Even GoPiGo3 can use a little advice from Claude

Even a GoPiGo3 can use a little advice and help from Claude.

Dexter Industries provides a GoPiGo3 C++ API, but stopped short of offering the EasyGoPiGo3 C++ API.

So I asked “my sometimes hallucinatory friend” Claude to review the C++ GoPiGo3 API and the Python EasyGoPiGo3 API, and create a prototype EasyGoPiGo3 C++ API (ignoring all sensor imports and non-intrinsic sensor methods).

Initial testing suggests about 75% of the EasyGoPiGo3 C++ APIs are conforming to the Python EasyGoPiGo3 API. There are some obvious issues to be investigated, and all the input parameter variations to test, but in two days effort I have more working code than the month of effort I put toward this goal “alone” back in 2022 just trying to port the Python drive_cm() to C++.

 *  C++ port of EasyGoPiGo3 Python library
 *  Sensor functions for distance sensor, IMU, etcetera are intentionally excluded.
 *
 *  Class EasyGoPiGo3(string config_file_path): public GoPiGo3
 *    config_file_path defaults to ~/.gpg3_config.json
 *    Inherits all GoPiGo3 instance vars and methods
 *
 *    Instance Vars:
 *      int speed: default 150 DPS
 *      tuple RGBColor left_eye_color:   (uint8 R, uint8 G, uint8 B)
 *      tuple RGBColor right_eye_color:  (uint8 R, uint8 G, uint8 B)
 *      left_encoder_target
 *      right_encoder_target
 *
 *    Implemented Methods:
 *      void  set_speed(int speed_in_DPS=150)
 *      void  reset_speed():  reset speed to DEFAULT_SPEED (300 DPS)
 *      int   get_speed()
 *      void  forward(): drive forward - use set_speed() or default: 150 DPS
 *      void  backward(): drive backward
 *      void  stop():   stop both motors, power off to let wheels float
 *      void  drive_cm(float dist, blocking=true): dist in cm
 *      void  drive_inches(float dist, blocking=true): dist in inches
 *      void  right() : pivot cw around right wheel
 *      left  left():  pivot ccw around left wheel
 *      void  spin_right(): spin in place clockwise
 *      void  spin_left(): spin in place counter-clockwise
 *      void  steer(int left_percent, int right_percent):  -100 to +100
 *      target_reached(left_tgt_degrees, right_tgt_degrees):  use to detect when to stop 
 *                                                            forward(), backward(), right(), left(), spin_right(), spin_left()
 *                                                            and for non-blocking drive_cm() or drive_inches()
 *      void reset_encoders(bool blocking = true): resets both encoders to 0, 
 *                                                 if blocking=true waits till both motors have stopped
 *      pair(int32_t, int32_t) read_encoders(string& units = "cm") returns (left,right) encoder in degrees or converted to a distance  
 *                                                   units: {"cm","in","inch","inches","raw") 
 *                                                   "raw" causes encoder degree average for both left and right
 *      float read_encoders_average(units = "cm") returns average of left and right encoders in degrees or optionall convert to distance
 *                                                   units: {"cm","in","inch","inches","raw") 
 *                                                   "raw" causes encoder degree average for both left and right
 *      void drive_degrees( float degrees, bool blocking=true): drive by turning each wheel degrees
 *      void turn_degrees(in:deg, blocking=true):  left: negative degrees
 *      void orbit(float degrees, float radius_cm = 0.0f, bool blocking = true)  Orbit with radius to inside wheel
 *      float volt();  return battery voltage as float
 *      void blinker_on(int id)   0=Left,1=Right
 *      void blinker_off(int id)  0=Left 1=Right
 *      void blinker_on(string&  id)   "left" or "right"
 *      void blinker_off(string& id)   "left" or "right"
 *      void led_on(int id)        alias for blinker_on
 *      void led_on(string& id)    alias for blinker_on
 *      void led_off(int id)       alias for blinker_off
 *      void led_ff(string& id)    alias for blinker_off
 *
 *      set_left_eye_color(R,G,B)
 *      set_right_eye_color(R,G,B)
 *      set_eye_color(R,G,B)
 *      open_left_eye()
 *      open_right_eye()
 *      open_eyes()
 *      close_left_eye()
 *      close_right_eye()
 *      close_eyes()
 

Not sure anyone but me will be testing or using the GoPiGo3 and EasyGoPiGo3 C++ APIs, but it feels rewarding to be expanding the GoPiGo3 usability.