Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

PololuRPISlave data structure format changes



I have been using the pololu rpi slave arduino library with some success on a zumo 32u4-raspberry pi 3 robot.

In the AStarRPiSlaveDemo.ino, there is a comment above the “struct Data” line that mentions changing the data format.

So far I have been able to manipulate this and a_stary.py to allow the RPi to read the line sensors and line position as well as allow the Pi to set the mode (line following or “manual” motor control) and also set the motor speeds.

Which leads me to ask, are the any resources or documentation someone could point me to that would help me understand what’s going on better so that I can create my own custom data structure?

My goal is to be able to write a python script that reads in a config file and sends those parameters over i2c to the arduino side (motor speed, line following P-I values, mode set, etc). I also want the script to read data from the arduino side to the Pi to monitor it remotely via ssh.

I am a novice at best with this stuff but am I trying to learn.



Your project sounds interesting; we would love to hear more about it as it progresses.

There are plenty of resources online that can help you better understand C++ data structures, like this tutorial on the cplusplus website.

Based on your description, it sounds like you already figured out how to add variables to the data structure in the example. What kind of custom data structure are you trying to make, and why?

- Amanda



On the Raspberry Pi side, you may also find the Python struct module documentation quite useful (I did!). Section has a table of all the different format conversion codes, their corresponding data type in C and Python and standard size (in bytes).

For my project, I made a simple table in a spreadsheet to help me track the different bytes used for each function and the associated variable type (see example below). The corresponding Arduino and Python files can be found here and here respectively. These are based on the pololu/pololu-rpi-slave-arduino-library with only the encoder variables added.

Hoping this can be helpful!