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

Pololu Forum

Romi Raspberry Pi motor control


#1

Hello, I’m very new to all this. I’m trying to control the speed of the motors on the romi using a raspberry pi.

Here is my code:

#!/usr/bin/env python
import sys
sys.path.insert(0, ‘/home/pi/pololu-rpi-slave-arduino-library-2.0.0/pi’)
import rospy
from a_star import AStar
from controltest.msg import RoverDirections

def callback(directions):
    a_star = AStar()
    if directions.forward:
        a_star.motors(int(200),int(200))
    elif directions.back:
        a_star.motors(int(-200),int(-200))
    elif directions.left:
        a_star.motors(int(200),int(-200))
    elif directions.right:
        a_star.motors(int(-200),int(200))

def main():
    rospy.init_node(‘Receiver’)
    rospy.Subscriber(’/directions_rover’, RoverDirections, callback)
    rospy.spin()


if name == ‘main’:
    main()

It’s just an if else statement that checks if a message is true and sets the motor value if it is but I keep getting:

TypeError: Third argument must be a list of at least one, but not more than 32 integers

Any help would be much appreciated, I’m also new to this forum so if this question is in the wrong place please let me know


#2

Hi, GregoryGregg.

It would be helpful if you include the output that describes where that error is occurring (which line of the program). In addition, it seems like using rospy in your program is unnecessarily complicating things at this point and making it harder to debug.

Have you tried running the example Python programs included with our Raspberry Pi slave library for Arduino? If they work for you, could you trim your program down to something very minimal (for example, only call a_star.motors() without using rospy) and then gradually try adding your other code back in until you encounter a problem?

By the way, you don’t need int() around your arguments to a_star.motors().

Kevin


#3

Ok, after sometime I was able to diagnose the issue. The framework I was using, ROS, was running the script I wrote as python 2 script. I was able to get it to run it as a python 3 script but it doesn’t seem very stable.

Is there a a_star.py script that will work with python 2?


#4

The scripts were originally written for Python 2 and later converted to Python 3 in version 2.0.0, so you might be able to use an older a_star.py from version 1.0.1 of the library. That version does not have the read_encoders() function, so you would have to add it back in if you use it.


#5

Cool, I was able to get it to work with the old version of the a_star.py script. I noticed however that it doesn’t include a function for reading the IMU data from the arduino. How could I fix this?


#6

Hello,

In the your setup, the Raspberry Pi is the I²C master, so it needs to communicate directly with the sensor chip; the AVR will not be involved. To be clear, you are using a Romi 32U4 Control Board, right? Unfortunately we do not have any complete example code for controlling the LSM6DS33 on that board with a Raspberry Pi. However, there are various example projects online that you could look at. For example, here is a blog post I found in a series about connecting a Raspberry Pi to a MinIMU-9 v5, which includes an LSM6DS33.

We also have this example code for the Balboa robot, which is a work in progress but contains code for communicating with the LSM6DS33.

You could also look at the LSM6DS33-related code in this MinIMU-9 AHRS example (by @DavidEGrayson), which is in C++ but shows how to write to more of the configuration registers, or our Arduino library for this chip.

-Paul


PololuRPiSlave + LSM6