From 225ff541b15ba27d63abe0f0e95c4937514ce1d7 Mon Sep 17 00:00:00 2001 From: Jason Antwi-Appah Date: Wed, 25 Feb 2026 12:09:35 -0600 Subject: [PATCH 1/7] feat: init steering controller project --- .../drivetrain_steering_node/.gitignore | 5 + .../.vscode/extensions.json | 10 ++ .../drivetrain_steering_node/README.md | 5 + .../drivetrain_steering_node/include/README | 37 +++++++ .../drivetrain_steering_node/lib/README | 46 ++++++++ .../drivetrain_steering_node/platformio.ini | 100 ++++++++++++++++++ .../drivetrain_steering_node/src/main.cpp | 18 ++++ .../drivetrain_steering_node/test/README | 11 ++ obstacle_detection.code-workspace | 36 ++++--- 9 files changed, 253 insertions(+), 15 deletions(-) create mode 100644 microcontroller_code/drivetrain_steering_node/.gitignore create mode 100644 microcontroller_code/drivetrain_steering_node/.vscode/extensions.json create mode 100644 microcontroller_code/drivetrain_steering_node/README.md create mode 100644 microcontroller_code/drivetrain_steering_node/include/README create mode 100644 microcontroller_code/drivetrain_steering_node/lib/README create mode 100644 microcontroller_code/drivetrain_steering_node/platformio.ini create mode 100644 microcontroller_code/drivetrain_steering_node/src/main.cpp create mode 100644 microcontroller_code/drivetrain_steering_node/test/README diff --git a/microcontroller_code/drivetrain_steering_node/.gitignore b/microcontroller_code/drivetrain_steering_node/.gitignore new file mode 100644 index 00000000..89cc49cb --- /dev/null +++ b/microcontroller_code/drivetrain_steering_node/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/microcontroller_code/drivetrain_steering_node/.vscode/extensions.json b/microcontroller_code/drivetrain_steering_node/.vscode/extensions.json new file mode 100644 index 00000000..080e70d0 --- /dev/null +++ b/microcontroller_code/drivetrain_steering_node/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/microcontroller_code/drivetrain_steering_node/README.md b/microcontroller_code/drivetrain_steering_node/README.md new file mode 100644 index 00000000..dcd1f8e3 --- /dev/null +++ b/microcontroller_code/drivetrain_steering_node/README.md @@ -0,0 +1,5 @@ +# drivetrain_steering_node + +PlatformIO + Arduino framework project for controlling the steering stepper motors on _La Princesa_. Runs on a Pi Pico controlling 4 DRV8825 drivers (one driver for each wheel). + +Will eventually use micro ROS like the 'MotorTest' node does but for now has rough test code to verify that the steppers work. \ No newline at end of file diff --git a/microcontroller_code/drivetrain_steering_node/include/README b/microcontroller_code/drivetrain_steering_node/include/README new file mode 100644 index 00000000..49819c0d --- /dev/null +++ b/microcontroller_code/drivetrain_steering_node/include/README @@ -0,0 +1,37 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the convention is to give header files names that end with `.h'. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/microcontroller_code/drivetrain_steering_node/lib/README b/microcontroller_code/drivetrain_steering_node/lib/README new file mode 100644 index 00000000..93793971 --- /dev/null +++ b/microcontroller_code/drivetrain_steering_node/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/microcontroller_code/drivetrain_steering_node/platformio.ini b/microcontroller_code/drivetrain_steering_node/platformio.ini new file mode 100644 index 00000000..d49083e7 --- /dev/null +++ b/microcontroller_code/drivetrain_steering_node/platformio.ini @@ -0,0 +1,100 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + + +[platformio] +default_envs = rpipico + + + +[env] +framework = arduino +upload_port = /dev/ttyACM0 +platform = teensy +; Micro-ROS configuration +board_microros_transport = serial +board_microros_distro = ${sysenv.ROS_DISTRO} +monitor_speed = 921600 +monitor_port = /dev/ttyACM0 +lib_deps = + https://github.com/micro-ROS/micro_ros_platformio + PaulStoffregen/Time + https://github.com/RobTillaart/DRV8825 +build_flags = + '-D LOCAL_MAC={ 0xAA, 0xBB, 0xCC, 0xEE, 0xDD, 0xFF }' + '-D LOCAL_IP={ 192, 168, 1, 101 }' + '-D AGENT_IP={ 192, 168, 1, 100 }' + '-D AGENT_PORT=8888' + '-D WIFI_SSID="wifi_ssid"' + '-D WIFI_PASSWORD="wifi_password"' + +[env:rpipico] +framework = arduino +monitor_speed = 115200 +monitor_port = /dev/ttyACM0 +platform = https://github.com/maxgerhardt/platform-raspberrypi.git +board = rpipico +board_build.core = earlephilhower +lib_ldf_mode = chain+ +#enable serial.begin +build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC=1 + +[env:rpipico2w] +framework = arduino +monitor_speed = 115200 +monitor_port = /dev/ttyACM0 +platform = https://github.com/maxgerhardt/platform-raspberrypi.git +board = rpipico2 +board_build.core = earlephilhower +lib_ldf_mode = chain+ +#enable serial.begin +build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC=1 + + +[env:megaatmega2560] +platform = atmelavr +board = megaatmega2560 + +[env:teensy41] +board = teensy41 +framework = arduino +upload_protocol = teensy-cli +monitor_speed = 115200 +lib_deps = + https://github.com/micro-ROS/micro_ros_platformio + PaulStoffregen/Time + micro_ros_arduino + https://github.com/micro-ROS/micro_ros_arduino.git +build_flags = + -D ARDUINO_ARCH_TEENSY + +[env:teensy40] +board = teensy40 + +[env:teensy36] +board = teensy36 + +[env:teensy35] +board = teensy35 + +[env:teensy31] +board = teensy31 + +[env:dev] +board = teensy40 +build_flags = + -I ../config + -D USE_DEV_CONFIG + +[env:vattenkar] +board = teensy40 +build_flags = + -I ../config + -D USE_VATTENKAR_CONFIG diff --git a/microcontroller_code/drivetrain_steering_node/src/main.cpp b/microcontroller_code/drivetrain_steering_node/src/main.cpp new file mode 100644 index 00000000..e2d570d4 --- /dev/null +++ b/microcontroller_code/drivetrain_steering_node/src/main.cpp @@ -0,0 +1,18 @@ +#include +#include "encoder_driver.h" +#include "pwm_driver.h" + +#include +#include +#include +#include +#include +#include + +void setup() { + +} + +void loop() { + +} \ No newline at end of file diff --git a/microcontroller_code/drivetrain_steering_node/test/README b/microcontroller_code/drivetrain_steering_node/test/README new file mode 100644 index 00000000..9b1e87bc --- /dev/null +++ b/microcontroller_code/drivetrain_steering_node/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/obstacle_detection.code-workspace b/obstacle_detection.code-workspace index 5d87edaf..1288f338 100644 --- a/obstacle_detection.code-workspace +++ b/obstacle_detection.code-workspace @@ -5,27 +5,33 @@ }, { "path": "ws_urc/src" + }, + { + "path": "microcontroller_code/MotorTest" + }, + { + "path": "microcontroller_code/drivetrain_steering_node" } ], "settings": { - "ros.distro": "humble", + "ros.distro": "jazzy", "python.autoComplete.extraPaths": [ - "/home/therion/dev/school/URC/ws_urc/install/video_streamer/lib/python3.10/site-packages", - "/home/therion/dev/school/URC/ws_urc/install/obstacle_detection/lib/python3.10/site-packages", - "/home/therion/dev/school/URC/ws_urc/install/drivetrain/lib/python3.10/site-packages", - "/home/therion/dev/school/URC/ws_urc/install/depth_image_viewer/lib/python3.10/site-packages", - "/home/therion/dev/school/URC/ws_urc/install/action_drivetrain_interface/local/lib/python3.10/dist-packages", - "/opt/ros/humble/lib/python3.10/site-packages", - "/opt/ros/humble/local/lib/python3.10/dist-packages" + "${workspaceFolder}/ws_urc/install/video_streamer/lib/python3.10/site-packages", + "${workspaceFolder}/ws_urc/install/obstacle_detection/lib/python3.10/site-packages", + "${workspaceFolder}/ws_urc/install/drivetrain/lib/python3.10/site-packages", + "${workspaceFolder}/ws_urc/install/depth_image_viewer/lib/python3.10/site-packages", + "${workspaceFolder}/ws_urc/install/action_drivetrain_interface/local/lib/python3.10/dist-packages", + "/opt/ros/jazzy/lib/python3.10/site-packages", + "${workspaceFolder}/opt/ros/jazzy/local/lib/python3.10/dist-packages" ], "python.analysis.extraPaths": [ - "/home/therion/dev/school/URC/ws_urc/install/video_streamer/lib/python3.10/site-packages", - "/home/therion/dev/school/URC/ws_urc/install/obstacle_detection/lib/python3.10/site-packages", - "/home/therion/dev/school/URC/ws_urc/install/drivetrain/lib/python3.10/site-packages", - "/home/therion/dev/school/URC/ws_urc/install/depth_image_viewer/lib/python3.10/site-packages", - "/home/therion/dev/school/URC/ws_urc/install/action_drivetrain_interface/local/lib/python3.10/dist-packages", - "/opt/ros/humble/lib/python3.10/site-packages", - "/opt/ros/humble/local/lib/python3.10/dist-packages" + "${workspaceFolder}/ws_urc/install/video_streamer/lib/python3.10/site-packages", + "${workspaceFolder}/ws_urc/install/obstacle_detection/lib/python3.10/site-packages", + "${workspaceFolder}/ws_urc/install/drivetrain/lib/python3.10/site-packages", + "${workspaceFolder}/ws_urc/install/depth_image_viewer/lib/python3.10/site-packages", + "${workspaceFolder}/ws_urc/install/action_drivetrain_interface/local/lib/python3.10/dist-packages", + "/opt/ros/jazzy/lib/python3.10/site-packages", + "/opt/ros/jazzy/local/lib/python3.10/dist-packages" ] } } From efe92495c2488d7f5a32f670ceeb9d042330d796 Mon Sep 17 00:00:00 2001 From: Jason Antwi-Appah Date: Wed, 25 Feb 2026 14:36:09 -0600 Subject: [PATCH 2/7] feat: testing arduino code --- .../drivetrain_steering_node/platformio.ini | 3 +-- .../drivetrain_steering_node/src/main.cpp | 25 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/microcontroller_code/drivetrain_steering_node/platformio.ini b/microcontroller_code/drivetrain_steering_node/platformio.ini index d49083e7..ce656851 100644 --- a/microcontroller_code/drivetrain_steering_node/platformio.ini +++ b/microcontroller_code/drivetrain_steering_node/platformio.ini @@ -17,14 +17,13 @@ default_envs = rpipico [env] framework = arduino upload_port = /dev/ttyACM0 -platform = teensy +platform = https://github.com/maxgerhardt/platform-raspberrypi.git ; Micro-ROS configuration board_microros_transport = serial board_microros_distro = ${sysenv.ROS_DISTRO} monitor_speed = 921600 monitor_port = /dev/ttyACM0 lib_deps = - https://github.com/micro-ROS/micro_ros_platformio PaulStoffregen/Time https://github.com/RobTillaart/DRV8825 build_flags = diff --git a/microcontroller_code/drivetrain_steering_node/src/main.cpp b/microcontroller_code/drivetrain_steering_node/src/main.cpp index e2d570d4..d0821069 100644 --- a/microcontroller_code/drivetrain_steering_node/src/main.cpp +++ b/microcontroller_code/drivetrain_steering_node/src/main.cpp @@ -1,18 +1,23 @@ #include -#include "encoder_driver.h" -#include "pwm_driver.h" +#include "DRV8825.h" -#include -#include -#include -#include -#include -#include +DRV8825 frontLeftSteeringMotor; +DRV8825 frontRightSteeringMotor; +DRV8825 backLeftSteeringMotor; +DRV8825 backRightSteeringMotor; +// TODO: update pinouts +#define UNUSED_PIN 255 void setup() { - + frontLeftSteeringMotor.begin(1, 1, UNUSED_PIN, 1, 1); + frontRightSteeringMotor.begin(1, 1, UNUSED_PIN, 1, 1); + backLeftSteeringMotor.begin(1, 1, UNUSED_PIN, 1, 1); + backRightSteeringMotor.begin(1, 1, UNUSED_PIN, 1, 1); } void loop() { - + frontLeftSteeringMotor.step(); + frontRightSteeringMotor.step(); + backLeftSteeringMotor.step(); + backRightSteeringMotor.step(); } \ No newline at end of file From 4e17182b91dd4db13d74ab6733cfdbcc3fec92b5 Mon Sep 17 00:00:00 2001 From: Jason Antwi-Appah Date: Wed, 25 Feb 2026 23:39:23 -0600 Subject: [PATCH 3/7] feat: update pinout --- .../drivetrain_steering_node/src/main.cpp | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/microcontroller_code/drivetrain_steering_node/src/main.cpp b/microcontroller_code/drivetrain_steering_node/src/main.cpp index d0821069..e265b08d 100644 --- a/microcontroller_code/drivetrain_steering_node/src/main.cpp +++ b/microcontroller_code/drivetrain_steering_node/src/main.cpp @@ -6,13 +6,29 @@ DRV8825 frontRightSteeringMotor; DRV8825 backLeftSteeringMotor; DRV8825 backRightSteeringMotor; -// TODO: update pinouts +/* +Pins connected to the Pico on the protoboard as of 2/25/2026 according to Pablo. +NOTE: GP pins are NOT the same as the physical pin numbers on the Pico. +use https://pico.pinout.xyz as a reference for mapping GP pins to physical pins. + ------------------------------------------------------------- + - GP 2/3: direction + step for the first stepper driver + - GP 4/5: direction + step for the second stepper driver + - GP 6/7: direction + step for the third stepper driver + - GP 8/9: direction + step for the fourth stepper driver + + - GP 10/11: sleep + reset for the fourth stepper driver + - GP 12/13: sleep + reset for the third stepper driver + - GP 14/15: sleep + reset for the second stepper driver + - GP 18/17: sleep + reset for the first stepper driver +*/ + #define UNUSED_PIN 255 void setup() { - frontLeftSteeringMotor.begin(1, 1, UNUSED_PIN, 1, 1); - frontRightSteeringMotor.begin(1, 1, UNUSED_PIN, 1, 1); - backLeftSteeringMotor.begin(1, 1, UNUSED_PIN, 1, 1); - backRightSteeringMotor.begin(1, 1, UNUSED_PIN, 1, 1); + // The motor to stepper driver assigments are probably wrong but the sets of pins for each stepper driver should be mostly correct (needs testing). + frontLeftSteeringMotor.begin(4, 5, UNUSED_PIN, 24, 22); + frontRightSteeringMotor.begin(6, 7, UNUSED_PIN, 19,20); + backLeftSteeringMotor.begin(9, 10, UNUSED_PIN, 16,17); + backRightSteeringMotor.begin(11, 12, UNUSED_PIN, 14,15); } void loop() { From 782f81166c4e573756f0fdc00d3d8941c66d294f Mon Sep 17 00:00:00 2001 From: Jason Antwi-Appah Date: Thu, 26 Feb 2026 11:45:04 -0600 Subject: [PATCH 4/7] feat: step motor on loop --- .../drivetrain_steering_node/platformio.ini | 2 +- .../drivetrain_steering_node/src/main.cpp | 41 +++++++++++++++---- obstacle_detection.code-workspace | 17 +++++++- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/microcontroller_code/drivetrain_steering_node/platformio.ini b/microcontroller_code/drivetrain_steering_node/platformio.ini index ce656851..fb29b8f4 100644 --- a/microcontroller_code/drivetrain_steering_node/platformio.ini +++ b/microcontroller_code/drivetrain_steering_node/platformio.ini @@ -16,7 +16,7 @@ default_envs = rpipico [env] framework = arduino -upload_port = /dev/ttyACM0 +; upload_port = /dev/ttyACM0 platform = https://github.com/maxgerhardt/platform-raspberrypi.git ; Micro-ROS configuration board_microros_transport = serial diff --git a/microcontroller_code/drivetrain_steering_node/src/main.cpp b/microcontroller_code/drivetrain_steering_node/src/main.cpp index e265b08d..a6e8106f 100644 --- a/microcontroller_code/drivetrain_steering_node/src/main.cpp +++ b/microcontroller_code/drivetrain_steering_node/src/main.cpp @@ -1,4 +1,6 @@ #include +// currently using this library: https://github.com/RobTillaart/DRV8825/tree/master?tab=readme-ov-file +// I considered using this library: https://github.com/laurb9/StepperDriver but the current one is working fine so far #include "DRV8825.h" DRV8825 frontLeftSteeringMotor; @@ -24,16 +26,39 @@ use https://pico.pinout.xyz as a reference for mapping GP pins to physical pins. #define UNUSED_PIN 255 void setup() { - // The motor to stepper driver assigments are probably wrong but the sets of pins for each stepper driver should be mostly correct (needs testing). - frontLeftSteeringMotor.begin(4, 5, UNUSED_PIN, 24, 22); - frontRightSteeringMotor.begin(6, 7, UNUSED_PIN, 19,20); - backLeftSteeringMotor.begin(9, 10, UNUSED_PIN, 16,17); - backRightSteeringMotor.begin(11, 12, UNUSED_PIN, 14,15); + // The motor to stepper driver assigments are probably wrong but the sets of pins for each stepper driver should be mostly correct (needs further testing). + // So far we have only tested the back left steering motor, shich is connected to the first stepper driver. + backLeftSteeringMotor.begin(2, 3, UNUSED_PIN, 18, 17); + // frontRightSteeringMotor.begin(4, 5, UNUSED_PIN, 14,15); + // frontLeftSteeringMotor.begin(6, 7, UNUSED_PIN, 12,13); + // backRightSteeringMotor.begin(8, 9, UNUSED_PIN, 18,17); + + + pinMode(LED_BUILTIN, OUTPUT); } void loop() { frontLeftSteeringMotor.step(); - frontRightSteeringMotor.step(); - backLeftSteeringMotor.step(); - backRightSteeringMotor.step(); + + // the intention behind this was to make the LED blink but it doesn't work as expected yet and just stays on + bool ledStatus = frontLeftSteeringMotor.getSteps() % 10000; + digitalWrite(LED_BUILTIN, ledStatus < 100 ? HIGH : LOW); + + Serial.print(ledStatus); + Serial.print(","); + + Serial.print(frontLeftSteeringMotor.getPosition()); + Serial.print(","); + + Serial.print(frontLeftSteeringMotor.getSteps()); + Serial.print(","); + + Serial.print(frontLeftSteeringMotor.getStepPulseLength()); + Serial.print(","); + + Serial.print(frontLeftSteeringMotor.getStepsPerRotation()); + + Serial.println(); + + // one other interesting observation - stepper motor behavior changes based on whether I have the serial monitor open or not. } \ No newline at end of file diff --git a/obstacle_detection.code-workspace b/obstacle_detection.code-workspace index 1288f338..b8f5c603 100644 --- a/obstacle_detection.code-workspace +++ b/obstacle_detection.code-workspace @@ -32,6 +32,21 @@ "${workspaceFolder}/ws_urc/install/action_drivetrain_interface/local/lib/python3.10/dist-packages", "/opt/ros/jazzy/lib/python3.10/site-packages", "/opt/ros/jazzy/local/lib/python3.10/dist-packages" - ] + ], + "files.associations": { + "__bit_reference": "cpp", + "__hash_table": "cpp", + "__split_buffer": "cpp", + "__tree": "cpp", + "array": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "initializer_list": "cpp", + "map": "cpp", + "string": "cpp", + "string_view": "cpp", + "unordered_map": "cpp", + "vector": "cpp" + } } } From 7c435951b671ee425fece12355de1db150626a44 Mon Sep 17 00:00:00 2001 From: Jason Antwi-Appah Date: Thu, 26 Feb 2026 19:44:23 -0600 Subject: [PATCH 5/7] feat: re add all steppers --- .../drivetrain_steering_node/src/main.cpp | 53 +++++++++++++++---- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/microcontroller_code/drivetrain_steering_node/src/main.cpp b/microcontroller_code/drivetrain_steering_node/src/main.cpp index a6e8106f..09f81823 100644 --- a/microcontroller_code/drivetrain_steering_node/src/main.cpp +++ b/microcontroller_code/drivetrain_steering_node/src/main.cpp @@ -29,35 +29,66 @@ void setup() { // The motor to stepper driver assigments are probably wrong but the sets of pins for each stepper driver should be mostly correct (needs further testing). // So far we have only tested the back left steering motor, shich is connected to the first stepper driver. backLeftSteeringMotor.begin(2, 3, UNUSED_PIN, 18, 17); - // frontRightSteeringMotor.begin(4, 5, UNUSED_PIN, 14,15); - // frontLeftSteeringMotor.begin(6, 7, UNUSED_PIN, 12,13); - // backRightSteeringMotor.begin(8, 9, UNUSED_PIN, 18,17); + frontRightSteeringMotor.begin(4, 5, UNUSED_PIN, 14,15); + frontLeftSteeringMotor.begin(6, 7, UNUSED_PIN, 12,13); + backRightSteeringMotor.begin(8, 9, UNUSED_PIN, 18,17); pinMode(LED_BUILTIN, OUTPUT); } void loop() { - frontLeftSteeringMotor.step(); - // the intention behind this was to make the LED blink but it doesn't work as expected yet and just stays on bool ledStatus = frontLeftSteeringMotor.getSteps() % 10000; digitalWrite(LED_BUILTIN, ledStatus < 100 ? HIGH : LOW); + + frontLeftSteeringMotor.step(); + frontRightSteeringMotor.step(); + backLeftSteeringMotor.step(); + backRightSteeringMotor.step(); - Serial.print(ledStatus); - Serial.print(","); - + // Log front left steering motor + Serial.print("FL,"); Serial.print(frontLeftSteeringMotor.getPosition()); Serial.print(","); - Serial.print(frontLeftSteeringMotor.getSteps()); Serial.print(","); - Serial.print(frontLeftSteeringMotor.getStepPulseLength()); Serial.print(","); - Serial.print(frontLeftSteeringMotor.getStepsPerRotation()); + Serial.println(); + // Log front right steering motor + Serial.print("FR,"); + Serial.print(frontRightSteeringMotor.getPosition()); + Serial.print(","); + Serial.print(frontRightSteeringMotor.getSteps()); + Serial.print(","); + Serial.print(frontRightSteeringMotor.getStepPulseLength()); + Serial.print(","); + Serial.print(frontRightSteeringMotor.getStepsPerRotation()); + Serial.println(); + + // Log back left steering motor + Serial.print("BL,"); + Serial.print(backLeftSteeringMotor.getPosition()); + Serial.print(","); + Serial.print(backLeftSteeringMotor.getSteps()); + Serial.print(","); + Serial.print(backLeftSteeringMotor.getStepPulseLength()); + Serial.print(","); + Serial.print(backLeftSteeringMotor.getStepsPerRotation()); + Serial.println(); + + // Log back right steering motor + Serial.print("BR,"); + Serial.print(backRightSteeringMotor.getPosition()); + Serial.print(","); + Serial.print(backRightSteeringMotor.getSteps()); + Serial.print(","); + Serial.print(backRightSteeringMotor.getStepPulseLength()); + Serial.print(","); + Serial.print(backRightSteeringMotor.getStepsPerRotation()); Serial.println(); // one other interesting observation - stepper motor behavior changes based on whether I have the serial monitor open or not. From ff2a2ea980a343eb3cb10cfe84323747cf6c591f Mon Sep 17 00:00:00 2001 From: Jason Antwi-Appah Date: Fri, 27 Feb 2026 04:15:43 -0600 Subject: [PATCH 6/7] checkpoint --- .../drivetrain_steering_node/platformio.ini | 21 ++- .../drivetrain_steering_node/src/main.cpp | 129 +++++++----------- .../src/main.cpp_real | 84 ++++++++++++ 3 files changed, 147 insertions(+), 87 deletions(-) create mode 100644 microcontroller_code/drivetrain_steering_node/src/main.cpp_real diff --git a/microcontroller_code/drivetrain_steering_node/platformio.ini b/microcontroller_code/drivetrain_steering_node/platformio.ini index fb29b8f4..fe5a9209 100644 --- a/microcontroller_code/drivetrain_steering_node/platformio.ini +++ b/microcontroller_code/drivetrain_steering_node/platformio.ini @@ -10,7 +10,7 @@ [platformio] -default_envs = rpipico +default_envs = rpipicow @@ -22,10 +22,11 @@ platform = https://github.com/maxgerhardt/platform-raspberrypi.git board_microros_transport = serial board_microros_distro = ${sysenv.ROS_DISTRO} monitor_speed = 921600 -monitor_port = /dev/ttyACM0 +; monitor_port = /dev/ttyACM0 lib_deps = PaulStoffregen/Time https://github.com/RobTillaart/DRV8825 + adafruit/Adafruit Motor Shield V2 Library@^1.1.4 build_flags = '-D LOCAL_MAC={ 0xAA, 0xBB, 0xCC, 0xEE, 0xDD, 0xFF }' '-D LOCAL_IP={ 192, 168, 1, 101 }' @@ -37,7 +38,7 @@ build_flags = [env:rpipico] framework = arduino monitor_speed = 115200 -monitor_port = /dev/ttyACM0 +; monitor_port = /dev/ttyACM0 platform = https://github.com/maxgerhardt/platform-raspberrypi.git board = rpipico board_build.core = earlephilhower @@ -45,10 +46,21 @@ lib_ldf_mode = chain+ #enable serial.begin build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC=1 +[env:rpipicow] +framework = arduino +monitor_speed = 115200 +; monitor_port = /dev/ttyACM0 +platform = https://github.com/maxgerhardt/platform-raspberrypi.git +board = rpipicow +board_build.core = earlephilhower +lib_ldf_mode = chain+ +#enable serial.begin +build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC=1 + [env:rpipico2w] framework = arduino monitor_speed = 115200 -monitor_port = /dev/ttyACM0 +; monitor_port = /dev/ttyACM0 platform = https://github.com/maxgerhardt/platform-raspberrypi.git board = rpipico2 board_build.core = earlephilhower @@ -71,6 +83,7 @@ lib_deps = PaulStoffregen/Time micro_ros_arduino https://github.com/micro-ROS/micro_ros_arduino.git + adafruit/Adafruit Motor Shield V2 Library@^1.1.4 build_flags = -D ARDUINO_ARCH_TEENSY diff --git a/microcontroller_code/drivetrain_steering_node/src/main.cpp b/microcontroller_code/drivetrain_steering_node/src/main.cpp index 09f81823..633d5858 100644 --- a/microcontroller_code/drivetrain_steering_node/src/main.cpp +++ b/microcontroller_code/drivetrain_steering_node/src/main.cpp @@ -1,95 +1,58 @@ #include -// currently using this library: https://github.com/RobTillaart/DRV8825/tree/master?tab=readme-ov-file -// I considered using this library: https://github.com/laurb9/StepperDriver but the current one is working fine so far -#include "DRV8825.h" +#include +#include +// #include "Adafruit_MS_PWMServoDriver.h" -DRV8825 frontLeftSteeringMotor; -DRV8825 frontRightSteeringMotor; -DRV8825 backLeftSteeringMotor; -DRV8825 backRightSteeringMotor; +Adafruit_MotorShield AFMS; +Adafruit_StepperMotor *myMotor; +Adafruit_StepperMotor *myMotor2; -/* -Pins connected to the Pico on the protoboard as of 2/25/2026 according to Pablo. -NOTE: GP pins are NOT the same as the physical pin numbers on the Pico. -use https://pico.pinout.xyz as a reference for mapping GP pins to physical pins. - ------------------------------------------------------------- - - GP 2/3: direction + step for the first stepper driver - - GP 4/5: direction + step for the second stepper driver - - GP 6/7: direction + step for the third stepper driver - - GP 8/9: direction + step for the fourth stepper driver - - GP 10/11: sleep + reset for the fourth stepper driver - - GP 12/13: sleep + reset for the third stepper driver - - GP 14/15: sleep + reset for the second stepper driver - - GP 18/17: sleep + reset for the first stepper driver -*/ - -#define UNUSED_PIN 255 void setup() { - // The motor to stepper driver assigments are probably wrong but the sets of pins for each stepper driver should be mostly correct (needs further testing). - // So far we have only tested the back left steering motor, shich is connected to the first stepper driver. - backLeftSteeringMotor.begin(2, 3, UNUSED_PIN, 18, 17); - frontRightSteeringMotor.begin(4, 5, UNUSED_PIN, 14,15); - frontLeftSteeringMotor.begin(6, 7, UNUSED_PIN, 12,13); - backRightSteeringMotor.begin(8, 9, UNUSED_PIN, 18,17); + Serial.begin(9600); + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, HIGH); + delay(5000); - pinMode(LED_BUILTIN, OUTPUT); + Serial.println("Setting up Wire"); + + Wire.begin(); + Wire.setClock(100000); // 100 kHz instead of 400 kHz + + AFMS = Adafruit_MotorShield(); + bool success = AFMS.begin(1600, &Wire); + if (!success) { + Serial.println("Could not find Motor Shield. Check wiring."); + } + else { + Serial.println("Motor Shield found"); + } + + myMotor = AFMS.getStepper(200, 1); + myMotor2 = AFMS.getStepper(200, 2); + myMotor->setSpeed(100); + myMotor2->setSpeed(100); + Serial.println("Setup complete"); + } void loop() { - // the intention behind this was to make the LED blink but it doesn't work as expected yet and just stays on - bool ledStatus = frontLeftSteeringMotor.getSteps() % 10000; - digitalWrite(LED_BUILTIN, ledStatus < 100 ? HIGH : LOW); + myMotor->onestep(FORWARD, DOUBLE); + myMotor2->onestep(FORWARD, DOUBLE); - frontLeftSteeringMotor.step(); - frontRightSteeringMotor.step(); - backLeftSteeringMotor.step(); - backRightSteeringMotor.step(); - - // Log front left steering motor - Serial.print("FL,"); - Serial.print(frontLeftSteeringMotor.getPosition()); - Serial.print(","); - Serial.print(frontLeftSteeringMotor.getSteps()); - Serial.print(","); - Serial.print(frontLeftSteeringMotor.getStepPulseLength()); - Serial.print(","); - Serial.print(frontLeftSteeringMotor.getStepsPerRotation()); - Serial.println(); - - // Log front right steering motor - Serial.print("FR,"); - Serial.print(frontRightSteeringMotor.getPosition()); - Serial.print(","); - Serial.print(frontRightSteeringMotor.getSteps()); - Serial.print(","); - Serial.print(frontRightSteeringMotor.getStepPulseLength()); - Serial.print(","); - Serial.print(frontRightSteeringMotor.getStepsPerRotation()); - Serial.println(); - - // Log back left steering motor - Serial.print("BL,"); - Serial.print(backLeftSteeringMotor.getPosition()); - Serial.print(","); - Serial.print(backLeftSteeringMotor.getSteps()); - Serial.print(","); - Serial.print(backLeftSteeringMotor.getStepPulseLength()); - Serial.print(","); - Serial.print(backLeftSteeringMotor.getStepsPerRotation()); - Serial.println(); - - // Log back right steering motor - Serial.print("BR,"); - Serial.print(backRightSteeringMotor.getPosition()); - Serial.print(","); - Serial.print(backRightSteeringMotor.getSteps()); - Serial.print(","); - Serial.print(backRightSteeringMotor.getStepPulseLength()); - Serial.print(","); - Serial.print(backRightSteeringMotor.getStepsPerRotation()); - Serial.println(); + // Serial.println("Stepping forward"); + // digitalWrite(LED_BUILTIN, HIGH); + // myMotor->step(1000, FORWARD, DOUBLE); + // myMotor2->step(1000, FORWARD, DOUBLE); + // Serial.println("Stepping backward"); + // digitalWrite(LED_BUILTIN, LOW); + // myMotor->step(1000, BACKWARD, DOUBLE); + // myMotor2->step(1000, BACKWARD, DOUBLE); + + + // Serial.print("Step time: "); + // Serial.println(millis()); + delay(10); +} - // one other interesting observation - stepper motor behavior changes based on whether I have the serial monitor open or not. -} \ No newline at end of file diff --git a/microcontroller_code/drivetrain_steering_node/src/main.cpp_real b/microcontroller_code/drivetrain_steering_node/src/main.cpp_real new file mode 100644 index 00000000..cec1a73b --- /dev/null +++ b/microcontroller_code/drivetrain_steering_node/src/main.cpp_real @@ -0,0 +1,84 @@ +#include +// currently using this library: https://github.com/RobTillaart/DRV8825/tree/master?tab=readme-ov-file +// I considered using this library: https://github.com/laurb9/StepperDriver but the current one is working fine so far +#include "DRV8825.h" + +DRV8825 frontLeftSteeringMotor; +DRV8825 frontRightSteeringMotor; +DRV8825 backLeftSteeringMotor; +DRV8825 backRightSteeringMotor; + +/* +Pins connected to the Pico on the protoboard as of 2/25/2026 according to Pablo. +NOTE: GP pins are NOT the same as the physical pin numbers on the Pico. +use https://pico.pinout.xyz as a reference for mapping GP pins to physical pins. + ------------------------------------------------------------- + - GP 2/3: direction + step for the first stepper driver + - GP 4/5: direction + step for the second stepper driver + - GP 6/7: direction + step for the third stepper driver + - GP 8/9: direction + step for the fourth stepper driver + + - GP 10/11: sleep + reset for the fourth stepper driver + - GP 12/13: sleep + reset for the third stepper driver + - GP 14/15: sleep + reset for the second stepper driver + - GP 18/17: sleep + reset for the first stepper driver +*/ + +#define UNUSED_PIN 255 +void setup() { + // The motor to stepper driver assigments are probably wrong but the sets of pins for each stepper driver should be mostly correct (needs further testing). + // So far we have only tested the back left steering motor, shich is connected to the first stepper driver. + backLeftSteeringMotor.begin(2, 3, UNUSED_PIN, 18, 17); + frontRightSteeringMotor.begin(4, 5, UNUSED_PIN, 14,15); + frontLeftSteeringMotor.begin(6, 7, UNUSED_PIN, 12,13); + backRightSteeringMotor.begin(8, 9, UNUSED_PIN, 18,17); + + backLeftSteeringMotor.setStepPulseLength(50); + frontLeftSteeringMotor.setStepPulseLength(50); + backRightSteeringMotor.setStepPulseLength(50); + frontRightSteeringMotor.setStepPulseLength(50); + + + + pinMode(LED_BUILTIN, OUTPUT); +} + +bool moveCW = true; + +void loop() { + bool ledStatus = moveCW; + digitalWrite(LED_BUILTIN, ledStatus ? HIGH : LOW); + + if(moveCW) { + frontLeftSteeringMotor.setDirection(DRV8825_CLOCK_WISE); + frontRightSteeringMotor.setDirection(DRV8825_CLOCK_WISE); + backLeftSteeringMotor.setDirection(DRV8825_CLOCK_WISE); + backRightSteeringMotor.setDirection(DRV8825_CLOCK_WISE); + } else { + frontLeftSteeringMotor.setDirection(DRV8825_COUNTERCLOCK_WISE); + frontRightSteeringMotor.setDirection(DRV8825_COUNTERCLOCK_WISE); + backLeftSteeringMotor.setDirection(DRV8825_COUNTERCLOCK_WISE); + backRightSteeringMotor.setDirection(DRV8825_COUNTERCLOCK_WISE); + } + + if (frontLeftSteeringMotor.getSteps() > 1000) { + moveCW = !moveCW; + frontLeftSteeringMotor.resetSteps(); + } + + + frontLeftSteeringMotor.step(); + frontRightSteeringMotor.step(); + backLeftSteeringMotor.step(); + backRightSteeringMotor.step(); + + Serial.print("FL,"); Serial.print(frontLeftSteeringMotor.getPosition()); Serial.print(","); Serial.print(frontLeftSteeringMotor.getSteps()); Serial.print(","); Serial.print(frontLeftSteeringMotor.getStepPulseLength()); Serial.print(","); Serial.print(frontLeftSteeringMotor.getStepsPerRotation()); + Serial.print(" FR,"); Serial.print(frontRightSteeringMotor.getPosition()); Serial.print(","); Serial.print(frontRightSteeringMotor.getSteps()); Serial.print(","); Serial.print(frontRightSteeringMotor.getStepPulseLength()); Serial.print(","); Serial.print(frontRightSteeringMotor.getStepsPerRotation()); + Serial.print(" BL,"); Serial.print(backLeftSteeringMotor.getPosition()); Serial.print(","); Serial.print(backLeftSteeringMotor.getSteps()); Serial.print(","); Serial.print(backLeftSteeringMotor.getStepPulseLength()); Serial.print(","); Serial.print(backLeftSteeringMotor.getStepsPerRotation()); + Serial.print(" BR,"); Serial.print(backRightSteeringMotor.getPosition()); Serial.print(","); Serial.print(backRightSteeringMotor.getSteps()); Serial.print(","); Serial.print(backRightSteeringMotor.getStepPulseLength()); Serial.print(","); Serial.print(backRightSteeringMotor.getStepsPerRotation()); + Serial.println(); + + delay(1); + + // one other interesting observation - stepper motor behavior changes based on whether I have the serial monitor open or not. +} \ No newline at end of file From eb2c86530bdac2a9b55f8a52f7bd425106623c08 Mon Sep 17 00:00:00 2001 From: Jason Antwi-Appah Date: Fri, 27 Feb 2026 06:56:14 -0600 Subject: [PATCH 7/7] ckpt --- .../drivetrain_steering_node/platformio.ini | 5 ++++ .../drivetrain_steering_node/src/main.cpp | 25 +++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/microcontroller_code/drivetrain_steering_node/platformio.ini b/microcontroller_code/drivetrain_steering_node/platformio.ini index fe5a9209..0e2da0b6 100644 --- a/microcontroller_code/drivetrain_steering_node/platformio.ini +++ b/microcontroller_code/drivetrain_steering_node/platformio.ini @@ -69,6 +69,11 @@ lib_ldf_mode = chain+ build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC=1 +[env:uno] +platform = atmelavr +board = uno +monitor_speed = 115200 + [env:megaatmega2560] platform = atmelavr board = megaatmega2560 diff --git a/microcontroller_code/drivetrain_steering_node/src/main.cpp b/microcontroller_code/drivetrain_steering_node/src/main.cpp index 633d5858..a8a7d3e2 100644 --- a/microcontroller_code/drivetrain_steering_node/src/main.cpp +++ b/microcontroller_code/drivetrain_steering_node/src/main.cpp @@ -9,16 +9,19 @@ Adafruit_StepperMotor *myMotor2; void setup() { - Serial.begin(9600); + Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); - delay(5000); + delay(5000); // delay so i can see logs :p Serial.println("Setting up Wire"); + Wire.setSDA(0); + Wire.setSCL(1); Wire.begin(); - Wire.setClock(100000); // 100 kHz instead of 400 kHz + + Wire.setClock(100000); // 100 kHz instead of 400 kHz (default) AFMS = Adafruit_MotorShield(); bool success = AFMS.begin(1600, &Wire); @@ -31,24 +34,24 @@ void setup() { myMotor = AFMS.getStepper(200, 1); myMotor2 = AFMS.getStepper(200, 2); - myMotor->setSpeed(100); - myMotor2->setSpeed(100); + myMotor->setSpeed(15); + myMotor2->setSpeed(15); Serial.println("Setup complete"); } void loop() { - myMotor->onestep(FORWARD, DOUBLE); - myMotor2->onestep(FORWARD, DOUBLE); + myMotor->onestep(FORWARD, SINGLE); + // myMotor2->onestep(FORWARD, SINGLE); // Serial.println("Stepping forward"); // digitalWrite(LED_BUILTIN, HIGH); - // myMotor->step(1000, FORWARD, DOUBLE); - // myMotor2->step(1000, FORWARD, DOUBLE); + // myMotor->step(1000, FORWARD, SINGLE); + // myMotor2->step(1000, FORWARD, SINGLE); // Serial.println("Stepping backward"); // digitalWrite(LED_BUILTIN, LOW); - // myMotor->step(1000, BACKWARD, DOUBLE); - // myMotor2->step(1000, BACKWARD, DOUBLE); + // myMotor->step(1000, BACKWARD, SINGLE); + // myMotor2->step(1000, BACKWARD, SINGLE); // Serial.print("Step time: ");