Coder Social home page Coder Social logo

rpigpio_ros's Introduction

RPIGPIO_ROS

This is a simple ROS package to help you expose some of the Raspberry Pi GPIO's functionalities to as standard ROS interfaces.

Install

  1. Clone this repository to your workspace.
  2. Build the package using catkin_make, catkin build or colcon.
  3. Source the workspace

Running the service server

This package provides a node that acts as a server that can dynamicaly create new ROS Services to manipulate with the GPIOs.

Running the command

$ rosrun rpigpio_ros gpio_control.py

will start the server and expose the generate_rpi_services service of type Trigger.

Upon calling this service, the server will read the desired configuration stored on the parameter server at the address new_gpio_configuration.

Let's put some configuration parameters to the parameter server manually with the following commands

$ rosparam set new_gpio_configuration/door_lock/name/ 'set_lock'
$ rosparam set new_gpio_configuration/door_lock/address/ 3
$ rosparam set new_gpio_configuration/brake/name/ 'set_brake'
$ rosparam set new_gpio_configuration/brake/address/ 4

Let's display the content of the parameter new_gpio_configuration

$ rosparam get new_gpio_configuration
brake: {address: 4, name: set_brake}
door_lock: {name: set_lock, set_lock: 3}

This read as: if you want to activate the brake you should call the set_brake service (type SetBool) that will change the state of the GPIO nr. 4.

Now that the configuration is on the parameter server, you can call the service

rosservice call /generate_rpi_services

The services set_brake and set_lock should be visible:

$ rosservice list
...
/set_brake
/set_lock
...

Command line arguments

You can start the server with a set of arguments.

Reading configuration from file

Starting the server with the -c followed by the location of the configuration file (YAML) will expose the services listed there. An example of the configuraiton file is provided with this package in conf/example.yml

$ rosrun rpigpio_ros gpio_control.py -c $(rospack find rpigpio_ros)/con f/example.yml

Providing mappings directly as arguments

You can start the server specify which services you want to have linked to which GPIOs with the -n and -a flag.

Running

$ rosrun rpigpio_ros gpio_control.py -n set_lock set_brake -a 4 3

will have the same result as (in terms of exposing the services) as setting the parameters as descibed above.

Starting the server at boot

To manage this server in the background, we will be using supervisor. If you already have it installed, you can skip the next step

Install supervisor

If you haven't done it yet, run:

$ sudo apt-get update

Then install supervisor:

$ sudo apt-get install supervisor

Configure the supervisor configuration file

Note: The following instructions are to be used as a template. Don't simply copy-paste stuff in the configuration file and expect it to work. Read carefuly and adjust according to your environment

To simplify your life, we included a script (util/supervisor.sh) that can be run from supervisor. This script takes care to set up the environment variables so that the running of the commands is smoother. Pay extra attention to the line that specifies the ROS_MASTER_URI environment variable and adjust it to your needs.

Open supervisor's configuration file (/etc/supervisor/supervisord.conf) with your favorite editor (don't forget to sudo) and add the following lines at the bottom:

[program:rpigpio_srv]
command=/bin/bash /home/<USER>/<ROS_WORKSPACE>/src/rpigpio_ros/util/supervisor.sh
user=<USER>
autorestart=true
startretries=100
stdout_logfile=</path/to/log/file.log>
stderr_logfile=</path/to/errorlog/file.log>

Replace <USER> with the name of your user.

Run supervisor:

$ supervisor

rpigpio_ros's People

Contributors

tgaspar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.