Servo
RobotArm
This page documents the LX-16A servo robot arm:
Components:
RGB Color Sensor: TCS34725
Four servos: LX16A
Hiwonder TTL/USB Debugging Board
Jumper Wires
5v PSU for servos and Arduino
19v psu for magnet
Magnet from 20-30v relay.
Pins for wiring:
#define RELAYPIN 3
#define RXSERVO 9
#define TXSERVO 8
A5 to TCS34725 SDL
A4 to TCS34725 SDA
OBS: Magnet needs to have a DIODE - It need to be the right way in relation to pluys and minus!!
Possible commands
The commands are sent via serial 115200 baud as JSON on a single line, and "\ n" is used as the end of the command:
{"cmd":"getRelayValue"} // gets state of relay
{"cmd":"begin"} // starts a transaction
{"cmd":"end"} // starts a transaction
{"cmd":"init"} // init check
{"cmd":"hello"} // hello world check
{"cmd":"setRelay","value":true} // sets relay
{"cmd":"setServoPos","value":460,"time":500, "id":1} // sets servo with time
{"cmd":"setServoPos","value":460,"speed":5, "id":1} // sets servo with speed
{"cmd":"setServoPos","trans":true, "value":460, "time":500, "id":1} /trans mode
{"cmd":"getColor"}
{"cmd":"getServoPos","id":1}
Time is in ms and speed is in degrees pr second.
To create a transactional move
Often it is relevant to make sure that a whole transaction has happened before an new move is initiated:
{"cmd":"begin"}
{"cmd":"setServoPos","value":460, "speed":500, "id":1}
{"cmd":"setServoPos","value":460, "speed":500, "id":2}
{"cmd":"setServoPos","value":460, "speed":500, "id":3}
{"cmd":"end"}
If you only want to move one motor you can also do:
{"cmd":"setServoPos","trans":true, "value":460, "time":500, "id":1}
Installation
Download the latest folder in the Arduino folder
If using the yellow keyStudio board then you need to install the driver
Extract the folder.
Make sure that the folder name is miniRobotIno_X and inside there are all the ino files.
Install the libraries
Arduino_JSON
Adafruit_TCS34725
Double-click the miniRobotIno_X.ino to open the project.
Choose an Arduino Uno board and press compile/upload.
P5JS - Interface
A custom interface has been made to interact with the robot
Steps to get the p5 up and running:
Create a p5js account
Load this sketch: https://editor.p5js.org/servoRobot/sketches/1tQqZhA_e
duplicate the sketch so you have your own.
Run your own sketch.
Connect to the arduino button with the connect button.
First time on a new computer:
Press the load json button. => retrieves the different positions from from server from the positions.json file.
Press a position for the robot to go to (e.g. “START_1”). => moves the robot to a position.
Press the Save position for the same position (e..g “START_1”) => saves all the positions as cookies so it is preset on the next refresh/run.
Place each color on the color sensor and save the color according to the numbers below:
let GREEN = 0;
let BLUE = 1;
let RED = 2;
You can press “a” to toggle admin interface. When admin interface is hidden the robot autostarts on play.
solution.js contains a solution program to run.
code should be written in function robotProgram in sketch.js