I am embarking on a new adventure that, (hopefully), will benefit the GoPiGo robot and everyone who uses it.
Becoming familiar with C++.
Becoming familiar with coding C++ using VS Code.
Being able to both code and debug C++ within VS Code.
First project:
I am currently working on a graphical “checklist” program for Windows that has a list of items that must be selected before the “continue” button becomes active and allows you to proceed.[1]
I have two versions:
One in Python
One in C++
The one in Python works as expected, however the one in C++ does nothing.
The C++ version doesn’t generate any errors, but produces no output - no window, no nothing. I suspect that whatever is supposed to create the window isn’t creating the window, perhaps because it’s not being called?
Ergo:
I need to learn how to debug C++ code in VS Code.
====================================
Second project:
(After I figure out what I am doing in VS Code.)
Continue the work @cyclicalobsessive started porting the GoPiGo3 API to C++ as a way of avoiding Python being a moving target with version “X” being obsolete fifteen minutes after release.
Disclosure:
Most of the actual code, (and much of the advice I received), was generated initially as an experiment to explore the feasabity of using chatGPT to write code from a requirements description. Ultimately it transformed into the main source of the development effort.
“the GoPiGo3 APIs” for C++ would mean the GoPiGo3 and EasyGoPiGo3 classes.
The good news - Dexter already did a complete C++ GoPiGo3 class.
The bad news: Nobody has created a C++ EasyGoPiGo3 class but you don’t need it!
There is everything needed to program the GoPiGo3 in C++ including accessing all the sensors on a Pi3 or Pi4. (It also all works on PiOS Bookworm and Pi5, but only with my GoPiGo3 Software Installer.)
#include <GoPiGo3.h> // for GoPiGo3
#include <unistd.h> // for usleep
GoPiGo3 GPG;
// forward
GPG.set_motor_dps(MOTOR_LEFT + MOTOR_RIGHT, NO_LIMIT_SPEED);
sleep(2); // GO GO GO FAST FOR 2 seconds
// stop
GPG.set_motor_dps(MOTOR_LEFT + MOTOR_RIGHT, 0);
sleep(1); // make sure stopped before going on
How to setup your C++ testing and run all the examples:
What remains to be done and what difficulties lie ahead?
Having EasyGoPiGo3.drive_cm() and EasyGoPiGo3.turn_degrees() would really make life easy - so:
/* FILE: EasyGoPiGo3.h
Instance Vars:
speed: default 150 DPS
left_eye_color
right_eye_color
left_encoder_target
right_encoder_target
Implemented Methods:
TODO Methods:
set_speed(speed_in_DPS=150)
get_speed()
forward(): drive forward - use set_speed() or default: 150 DPS
backward(): drive backward
stop():
drive_cm(dist_cm, blocking=true)
drive_inches(dist_inches, blocking=true)
right() : pivot cw around right wheel
left(): pivot ccw around left wheel
spin_right(): spin in place clockwise
spin_left(): spin in place counter-clockwise
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()
reset_encoders(): resets both encoders to 0
read_encoders(out:left, out:right, in:units=CM/INCH/DEGREE)
read_encoders_average(out:ave, in:units=CM/INCH/DEGREE)
turn_degrees(in:deg, blocking=true): left: negative degrees
blinker_on(id:{LEFT,RIGHT}
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()
*/
and
/* FILE: EasyGoPiGo3.cpp
*
* Simplified C++ API for GoPiGo3
*
* Patterned after the Python EasyGoPiGo3.py
*/
#include <EasyGoPiGo3.h>
EasyGoPiGo3::EasyGoPiGo3(){
set_speed(DEFAULT_SPEED);
}
void EasyGoPiGo3::set_speed(int speed_in){
speed = speed_in;
};
Should have moved set_speed() to “Done”…
Difficulties? Handling the unsigned math in C++ for the encoders.