Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
README.md

README.md

Experiment with ROS, Raspberry PI and Python

Raspberry PI setup.

Put simple push switches on pins 18 and 24 on a breadboard.

image

Raspberry PI ROS installation

Follow the instructions over here.

If something fails, it'll most likely to be an environment variable issue, e.g. for me this solved packages not being found.

export ROS_PACKAGE_PATH=/home/pi/catkin_ws/src:$ROS_PACKAGE_PATH

Also, I only installed the shell version, not the full desktop version.

The Python code

See my code in GitHub. Everything other than the scripts directory was autogenerated by a ROS.

I created a new ROS package first as explained here, my two python scripts live in the scripts directory. The code is based on this tutorial code.

To Run

You can configure a launch file #, but the simplest way to test this is to run the following in three separate shells:

All from within catkin workspace directory:

/home/pi/catkin_ws/

Run the ROS OS.

roscore

Run the talker

rosrun test talker.py

Run the listener

rosrun test listener.py

Test it

Press one one of the buttons and the output might look like:

pi@raspberrypi:~/catkin_ws/src/test/scripts $ rosrun test listener.py 
[INFO] [1556918461.361843]: heading 360
[INFO] [1556918461.964700]: heading 15
[INFO] [1556918462.867729]: heading 30
[INFO] [1556918463.667803]: heading 15
[INFO] [1556918464.167762]: heading 0
[INFO] [1556918464.372864]: heading 345
[INFO] [1556918464.778167]: heading 330

'heading' is just a variable name but in my code corresponds to a compass heading where the buttons turn left or right deducting or subtracting 15 degrees from the previous value.

What's next?

In this example, we see ROS decoupling sensor reading code from the action code. It would be possible to add more hardware to the PI and wire it together with more publisher/subscriber code and custom logic. See more on publishers and subscribers.

e.g. instead of just outputting data in the listener like this:

[INFO] [1556918464.372864]: heading 345
[INFO] [1556918464.778167]: heading 330

logic could be triggered to drive a motor, move a servo or trigger a solenoid. With a more complicated robot, ROS is ideal to keep the application simple and all parts decoupled.

Resources

You can’t perform that action at this time.