Coding/Debugging C++ using VS Code?

Is there any way to determine what type C++ expects, or what “type” Python is providing?

Or maybe some way to “typecast” in Python?

I will have to check on that.

2 Likes

yes, yes, yes. And there are “programming formalists” that always give “type hints” to Python, but for us “love Python because we don’t have to follow programming best practices” I don’t get involved in types unless working with numpy and OpenCV where the array representation of images have to be “type cast”.

There are some places in the GoPiGo3 API where DI uses Python type hints when interfacing with hardware.

2 Likes

OK. . .

Let me restate my overall goals so that we’re all on the same page.

Notes:

  1. I am using ChatGPT, both as an experiment in itself and as an “assistant”.

  2. I am maintaining this in an open forum, (as opposed to the Lounge), so that it is visible and, (perhaps, if we’re lucky), we can attract someone more experienced in C++ to provide guidance.
     

Project:  Coding and debugging C++ in VS Code:

Project goals:

  1. Immediate goals:

    • Configure VS Code to support C++
      Note that I am moving the project from my flight-simulator system to my “main” system where I do robot development.

    • Figure out how to both code and debug C++ code in a manner similar to debugging Python code.  (i.e. Single-step, set breakpoints, see what happens, etc.)
       

  2. Near-term goals:

    • Use my Checklist.cpp code as a target for step #1.

    • Find out why it is not working.

    • Successfully debug in VS Code.
       

  3. Longer term goals:

    • Continue @cyclicalobsessive’s work on porting the GoPiGo API/Libraries to C++ as noted below.
       

Project:  GoPiGo porting to C++:

Project goals:

  1. Eliminate, (to the greatest extent possible), the problems with Python dependencies.

  2. Make the GoPiGo functionality operating system agnostic:

    • The GoPiGo functionality should smoothly migrate from Buster to any later version of the Raspberry Pi O/S with no, or very few, modifications.

    • The GoPiGo functionality should smoothly migrate to any other operating system compatible with the Raspberry Pi with an absolute minimum of modifications.
       

  3. Make the GoPiGo functionality platform agnostic:

    • To the greatest extent possible, make the GoPiGo functionality available to any other controller platform that is electrically and pin compatible with the Raspberry Pi’s GPIO interface.[1]  This would include platforms like the Jetson Nano/Xavier, Orange Pi, etc.[2]

      • The goal of this is to reduce/eliminate the current hard dependence on the Raspberry Pi itself, if it becomes unavailable or inordinately expensive again.

      • This would also include the use-case where capabilities beyond the abilities of the Raspberry Pi are needed.
         

==================== Footnotes ====================

  1. Note that in theory it is technically possible to migrate to platforms that are not pin compatible with the Raspberry Pi’s GPIO interface, but that would be a more extensive technical effort that is outside the scope of this project.

  2. This requirement does not include the ability to be an absolute drop-in replacement in a foreign platform, (though it would be nice).

    • It is understood that, (at the very least), the software may need to be re-compiled to run on the target system.  It might also require modification to use the target system’s architecture and GPIO.

    • It is also understood that the surrounding code may require modifications to use the GoPiGo’s functionality.

    • Later projects, (for example:  Porting to the Jetson Nano and/or other NVIDIA systems), could provide additional drop-in code for those platforms though it is outside the immediate scope of this project.

1 Like

Very good - I did a long session with ChatGPT on porting EasyGoPiGo3.py to C++. I discovered it really cheats wherever it can, leaving out parameters, leaving out major logic blocks, does not use embedded pseudocode, does not even use given C++ header files, and discovered I was wasting my time telling ChatGPT what it ignored so it would make changes to its generated code.

I decided to see if just the ChatGPT version of target_reached(left_target_degrees,right_target_degrees) would even compile. No.

So when and if you ever want to work on EasyGoPiGo3 in C++ here is where I left off last year (no ChatGPT hogwash included)

C++ EasyGoPiGo3 for GoPiGo3

The Dexter/ModularRobotics GoPiGo3 robot includes a C++ API in GoPiGo3.h/cpp and libgopigo3.so
but does not include an “Easy API” that is available in Python.

This project is a rough implementation of an EasyGoPiGo3 class which includes:

Implemented Methods:

     set_speed(speed_in_DPS)
     set_speed()  // DEFAULT_SPEED
     int get_speed()
     get_speed(&out)
     float volt()
     forward(): drive forward - use set_speed() or default: 150 DPS
     backward(): drive backward
     stop(): 

TODO Methods:

     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()

LIMITATIONS and DIFFERENCES:

  • i2c mutex not implemented
  • does not perform sensor discovery / sensor init
  • DEFAULT_SPEED is set to 150 DPS rather than 300 DPS for additional safety from tipping over
  • Compiler enforces speed value type

========= ATTEMPT AT ChatGPT for target_reached ========

code is here

An Attempt to Use ChatGPT to translate Python to C++ for the EasyGoPiGo3 GoPiGo3 API

The Dexter/ModularRobotics GoPiGo3 robot includes a C++ API in GoPiGo3.h/cpp and libgopigo3.so
but does not include an “Easy API” that is available in Python.

This project is a rough implementation of an EasyGoPiGo3 class which includes:

Implemented Methods (by Alan):

     set_speed(speed_in_DPS)
     set_speed()  // DEFAULT_SPEED
     int get_speed()
     get_speed(&out)
     float volt()
     forward(): drive forward - use set_speed() or default: 150 DPS
     backward(): drive backward
     stop(): 

Attempted implementation by ChatGPT (Does not compile):

     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()
1 Like