🖇️Serial Protocol

We have defined a set of serial communication protocols for robots:

All the tokens start with a single ASCII-encoded character to specify their parsing format. They are case-sensitive and usually in lowercase.

Some commands, like the c and m commands, can be combined.

For example:

Successive "m8 40", "m8 -35", "m 0 50" can be written as "m8 40 8 -35 0 50".

You can change the limit in the code, but there might be a systematic constraint for the serial buffer.

Try the following serial commands in the serial monitor:

  • ksit”

  • m0 30”

  • m0 -30”

  • kbalance”

  • kwkF”

  • ktrL”

  • d

You can refer to the macro definitions in OpenCat.h to utilize the most updated sets of tokens.

https://github.com/PetoiCamp/OpenCat/blob/3368dfd46d91cb453bb5fcca3ca4cf84712c922e/src/OpenCat.h#L204-L254
//token list
#define T_ABORT 'a'      //abort the calibration values
#define T_BEEP 'b'       //b note1 duration1 note2 duration2 ... e.g. b12 8 14 8 16 8 17 8 19 4 \
                         //a single 'b' will toggle the melody on/off
#define T_CALIBRATE 'c'  //send the robot to calibration posture for attaching legs and fine-tuning the joint offsets. \
                         //c jointIndex1 offset1 jointIndex2 offset2 ... e.g. c0 7 1 -4 2 3 8 5
#define T_REST 'd'
#define T_GYRO_FINENESS 'g'             //adjust the finess of gyroscope adjustment to accelerate motion
#define T_GYRO_BALANCE 'G'              //toggle on/off the gyro adjustment
#define T_INDEXED_SIMULTANEOUS_ASC 'i'  //i jointIndex1 jointAngle1 jointIndex2 jointAngle2 ... e.g. i0 70 8 -20 9 -20 \
                                        //a single 'i' will free the head joints if it were previously manually controlled.
#define T_JOINTS 'j'                    //A single "j" returns all angles. "j Index" prints the joint's angle. e.g. "j 8" or "j11".
#define T_SKILL 'k'
#define T_SKILL_DATA 'K'
#define T_INDEXED_SEQUENTIAL_ASC 'm'  //m jointIndex1 jointAngle1 jointIndex2 jointAngle2 ... e.g. m0 70 0 -70 8 -20 9 -20
// #define T_MELODY 'o'
#define T_PAUSE 'p'
// #define T_SLOPE 'l'
#define T_SAVE 's'  //save the calibration values
// #define T_TILT 't'
// #define T_MEOW 'u'
#define T_PRINT_GYRO 'v'            //print the Gyro data once
#define T_VERBOSELY_PRINT_GYRO 'V'  //toggle verbosely print Gyro data
// #define T_XLEG        'x'
// #define T_ACCELERATE  '.'
// #define T_DECELERATE  ','
#define T_RANDOM_MIND 'z'  //toggle random behaviors in the RANDOM_MIND mode
#define T_QUERY '?'

#ifdef GROVE_SERIAL_PASS_THROUGH
#define T_READ 'R'        //read pin     R
#define T_WRITE 'W'       //write pin                      W
#define TYPE_ANALOG 'a'   //            Ra(analog read)   Wa(analog write)
#define TYPE_DIGITAL 'd'  //            Rd(digital read)  Wd(digital write)
#endif
#define T_COLOR 'C'                     //change the eye colors of the RGB ultrasonic sensor
#define T_INDEXED_SIMULTANEOUS_BIN 'I'  //I jointIndex1 jointAngle1 jointIndex2 jointAngle2 ... e.g. I0 70 8 -20 9 -20
#define T_INDEXED_SEQUENTIAL_BIN 'M'    //M jointIndex1 jointAngle1 jointIndex2 jointAngle2 ... e.g. M0 70 0 -70 8 -20 9 -20

#define BINARY_COMMAND  //disable the binary commands to save space for the simple random demo

#ifdef BINARY_COMMAND
#define T_BEEP_BIN 'B'    //B note1 duration1 note2 duration2 ... e.g. B12 8 14 8 16 8 17 8 19 4
#define T_LISTED_BIN 'L'  //a list of the DOFx joint angles: angle0 angle1 angle2 ... angle15
// #define T_SERVO_MICROSECOND 'w'  //PWM width modulation
#define T_TEMP 'T'  //call the last 'K' skill data received from the serial port
#endif

#define EXTENSION 'X'
#define EXTENSION_VOICE 'A'
#define EXTENSION_ULTRASONIC 'U'

Some more available commands for skills:

The complete set of skills in effect is defined in InstinctBittle.h or InstinctNybble.h: For example:

const char* skillNameWithType[]={"bdFI","bkI","bkLI","crFI","crLI","hlwI","mhFI","mhLI","pcFI","phFI","phLI","trFI","trLI","vtFI","vtLI","wkFI","wkLI","balanceI","buttUpI","calibI","droppedI","liftedI","restI","sitI","strI","zeroN","bfI","ckI","climbCeilI","fdI","ffI","hiI","jyI","pdI","peeI","puI","pu1I","rcI","rlLI","rtI","stpI","tsI",};

All the skill names in the list can be called by adding a 'k' to the front and deleting the suffix. For example, there's "sitI" in the list. You can send "ksit" to call the sitting posture. If a skill has "F" or "L" as the second last character, it's a gait. It means walking forward or left. Walking right is a mirror of walking left. So you can send "kwkF", "kwkL", "kwkR" to make the robot walk. Similarly, there are other gaits like trot ("tr"), crawl ("cr"), and stepping ("vt").

Last updated

Was this helpful?