Auto Position (Gait) icon Auto Position (Gait) — Create servo frames and actions to animate gaits and gestures with automatic motion planning, software ramping, movement panel, import/export Try it →
Canada
Twitter
Asked
Resolved Resolved by DJ Sures!
1 Participant
JSON to mjbots quad robot series

JSON To Mjbots Quad Robot Series

My robot wants to communicate via JSON commands (it is controlled via JSON from a browser) but I need to use ARC to talk to it. It also sends a lot of data back over JSON to provide current servo status that would need to be fed back into ARC.  Any thoughts if this can be adapted to communicate with the robot? https://github.com/mjbots/quad/blob/main/mech/web_control_assets/index.html



Related Hardware (view all EZB hardware)
EZ-B V4 by EZ-Robot
EZ-B v4 with Synthiam ARCx controls servos, sensors, camera and audio over Wi-Fi or USB serial, no firmware needed.
Wi-Fi / USB
Servos 24
Camera
Audio
UART 3
I2C
ADC 8
Digital 24

Related Robot Skills (view all robot skills)
Custom Movement Panel maps directional commands to scripts, adjusts per-wheel speed (0-255), and integrates with joysticks for unsupported motors
Websocket Client by Synthiam
WebSocket client for ARC: open/send messages, store server responses in a variable, run a response script, and track connection status.

ARC Pro

Upgrade to ARC Pro

Become a Synthiam ARC Pro subscriber to unleash the power of easy and powerful robot programming

Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#2  

@Nink - you sent a link to an HTML file. A JSON file looks similar to XML in that it has labelled parameter tags containing values. 

i.e.

{
    "glossary": {
        "title": "example glossary",
      "GlossDiv": {
            "title": "S",
         "GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
               "SortAs": "SGML",
               "GlossTerm": "Standard Generalized Markup Language",
               "Acronym": "SGML",
               "Abbrev": "ISO 8879:1986",
               "GlossDef": {
                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
                  "GlossSeeAlso": ["GML", "XML"]
                    },
               "GlossSee": "markup"
                }
            }
        }
    }
}
Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#3   — Edited

But, you can also parse the JSON in javascript right in arc..

Here's an example parsing JSON from a string...


var resp = '{ "glossary": { "title": "example glossary" } }';

var myObj = JSON.parse(resp);

print (myObj.glossary.title);

And here's an example of getting JSON from an HTTP get request...


var resp = Net.hTTPGet("https://ip.jsontest.com/";); 

var myObj = JSON.parse(resp);

print (myObj.ip);
Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#7  

The json that you would need to send is defined as a class struct in the app.js. You could edit the app.js and print the json to the console. But this is essentially the part that is creating the json - it is stored in a "command" variable and built throughout those lines by extracting data from the webpage objects and joystick.


let command = {
      "command" : {
        "mode" : (() => {
          if (this._mode == "off") { return "stopped"; }
          if (this._mode == "stop") { return "zero_velocity" ;}
          if (this._mode == "idle") { return "rest"; }

          if (!movement_commanded && !force_step &&
              (this._mode == "walk" ||
               this._mode == "pronk")) {
            return "rest";
          }
          if (this._mode == "walk") { return "walk"; }
          if (this._mode == "pronk") { return "jump"; }
          return "zero_velocity";
        })(),
      },
    };

    const record_data = getElement("record_data").checked;
    // Unset leaves the current value alone, but we can just send it
    // every time.
    command["command"]["log"] = record_data ? "enable" : "disable";

    command["command"]["v_R"] = v_R;
    command["command"]["w_R"] = w_R;

    if (pose_RB) {
      command["command"]["rest"] = {
        offset_RB : pose_RB,
      };
    }

    if (command["command"]["mode"] == "jump") {
      command["command"]["jump"] = {
        "acceleration" : this.getJumpAcceleration(),
        "repeat" : getElement("jump_repeat").checked,
      };
    } else if (command["command"]["mode"] == "walk") {
      const height_engaged = (
        this._joystick.down(Joystick.BUTTON_SHOULDER_RB) ||
          this._keys['h']);
      const maximize_flight = getElement("maximize_flight").checked;

      command["command"]["walk"] = {
        "step_height" : height_engaged ?
          Number(getElement("height_scale").value) : 1.0,
        "maximize_flight" : maximize_flight,
      };
    }

    const command_string = JSON.stringify(command);
    getElement('current_json_command').innerHTML = command_string;

    if (this._websocket.readyState == WebSocket.OPEN) {
      this._websocket.send(command_string)   <--------------- SENDS THE JSON
    }
  }
Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#8  

*Moved into own thread because it is out of scope for the original thread