Asked
Resolved by DJ Sures!
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 EZ-B v4
Related Controls
Custom Movement Panel
WebSocket Client
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
@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.
But, you can also parse the JSON in javascript right in arc..
Here's an example parsing JSON from a string...
And here's an example of getting JSON from an HTTP get request...
One last thing - you can view all of the built-in javascript classes here: https://synthiam.com/Support/javascript-api/javascript-overview
You can click on the ECMA 5.1 classes to read their manual page from developer.mozilla.org.
Thanks DJ I will try and connect with javascript. The HTML file I posted calls a javascript app.js that communicates with the bot via JSON. https://github.com/mjbots/quad/blob/main/mech/web_control_assets/js/app.js As far as I can tell this then talks to this file on the bot. https://github.com/mjbots/quad/blob/main/mech/quadruped_state.h#L32
I noticed your app.js is actually a WebSocket, so an HTTP get wouldn't work. Use this: https://synthiam.com/Support/Skills/Communication/WebSocket-Client?id=20442
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.
*Moved into own thread because it is out of scope for the original thread
Their json websocket end point is...
The JSON data is actually displayed in the mjmech control web interface at the bottom...
For example...
stop is: {"command":{"mode":"zero_velocity","log":"disable","v_R":[0,0,0],"w_R":[0,0,0]}}
idle is: {"command":{"mode":"rest","log":"disable","v_R":[0,0,0],"w_R":[0,0,0]}}
And when i press W & S for walking forward backward, i assume? the v_R first parameter value grows the longer i hold W - so maybe that's the speed? It's: {"command":{"mode":"walk","log":"disable","v_R":[0.19850326650786185,0,0],"w_R":[0,0,0],"walk":{"step_height":1,"maximize_flight":false}}}
And Q & E is turning left right? The w_R last parameter value is positive with E and negative with Q: {"command":{"mode":"walk","log":"disable","v_R":[8.30430736384064e-9,0,0],"w_R":[0,0,0.34211217332152727],"walk":{"step_height":1,"maximize_flight":false}}}
And A & D is straffe, which is disabled in the UI but can be activated in the advance menu. It seems to grow the second parameter of v_R {"command":{"mode":"walk","log":"disable","v_R":[-0.0000013168969403094258,0.038964137912889336,0],"w_R":[0,0,9.238252698349165e-20],"walk":{"step_height":1,"maximize_flight":false}}}
So taking those json queries, you can use the Custom Movement Panel and send json commands based on movements. Use the Javascript's Utility.Map() function to map the ARC speed to what the json query parameters need. Read about Utility.Map here: https://synthiam.com/Support/javascript-api/Utility/map
The ARC speed is a value between 0-255 and it appears the json speed is a floating-point between max -3 and +3.
This bit of code is an example of what you'd have in the custom Movement Panel for moving forward with speed control.
And this is what you'd have in the custom Movement Panel for moving backward with speed control (notice the - on the return of the Utility.Map() function)
And something like this for stop i guess....
Thanks for the help DJ, PTP was giving me a hand this morning but then we had a minor issue with a servo burn out so project is on hold until I get a new motor :-(
FYI I managed to get some of the JSON queries out via inspection in browser as I tried different things. There is a lot of chatter going on it sends this to me about 10 times a second (deleted 90% of this as I didn't realize it went for about 10 pages)
{ "timestamp" : "2021-Mar-06 08:00:49.321910", "mode" : "stopped", "mode_start" : "2021-Mar-06 07:58:15.324045", "fault" : "", "state" : { "joints" : [ { "id" : 1, "angle_deg" : 82.152000000000001, "velocity_dps" : 2.79, "torque_Nm" : 0, "temperature_C" : 27, "voltage" : 21, "mode" : 0, "fault" : 0, "kp_Nm" : 0, "ki_Nm" : 0, "kd_Nm" : 0, "feedforward_Nm" : 0, "command_Nm" : 0 },
Nink, I responded to your question about disabling the speaking response in the thread you asked it in, here: https://synthiam.com/Support/Skills/Communication/WebSocket-Client?id=20442
Also, while it could use the suggestion I had of a custom Movement Panel - if PTP is involved then it would make more sense to make a robot skill. You'll have newtonsoft JSON to work with and it's pretty easy from there.
@PTP to create a custom movement panel, check the source code for the recent DJI Tello drone, which is helpful: https://github.com/synthiam/Control-DJI-Tello-Movement-Panel
Assign to the OnMovement event from the movement manager. And that way you simply send the data to the robot and handle the movement.
Have you tried sending any of the commands that I outlined above?
i.e.
Robot just stood up WOOT! So happy.
Noice!!!!
Once you figure out the movement commands and speed, then you can use the Custom Movement Panel to rock it
Something like this for Forward. I dunno if that's the correct json or not. But the idea is use the Map function to convert the ARC speed (0-255) into a float of (0-1) for that robot.
Thanks for all your help on this DJ. I have it obeying a bunch of commands. Still a while to go but he can stand laydown and we are learning to walk. Lots of fun.