Skip to content

ICE9-Robotics/rpi_gpiozero_ros

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rpi_gpiozero_ros

ROS 2 Jazzy Python package for Raspberry Pi GPIO control using gpiozero.

Dependencies

Supported gpiozero base classes

  • DigitalInputDevice
  • SmoothedInputDevice
  • DigitalOutputDevice
  • PWMOutputDevice
  • Servo

Interfaces

  • Publishes digital input state on ~/inputs/<name>/state (std_msgs/Bool)
  • Publishes smoothed input value on ~/smoothed_inputs/<name>/value (std_msgs/Float32)
  • Provides digital output service ~/outputs/<name>/set (std_srvs/SetBool)
  • Provides PWM output service ~/pwm_outputs/<name>/set (ros_common_srvs/SetFloat32)
  • Provides servo output service ~/servo_outputs/<name>/set (ros_common_srvs/SetFloat32)

Build

cd /path/to/workspace
colcon build --packages-select rpi_gpiozero_ros

Run

source install/setup.bash
ros2 launch rpi_gpiozero_ros gpiozero_node.launch.py

Parameter file

Parameters live under the node name (for example gpiozero_node) in ros__parameters:. See config/gpiozero_params.yaml.

Device parameters

Declare each device under gpio.<logical_name>.<field>. In YAML this is normally a nested map gpio: with one key per <logical_name>. ROS stores these as flat dotted parameters (for example gpio.button.pin).

There must be at least one configured device (type + pin per logical name).

Global parameters

Parameter Type Default Description
pin_factory string auto auto: use gpiozero’s default backend. mock: MockFactory with PWM-capable mock pins so pwm_output can run without a Pi.
pin_numbering string bcm How each integer pin is turned into a gpiozero pin specification. See next subsection.
publish_rate_hz float 20.0 Period for publishing all digital and smoothed input topics (1.0 / publish_rate_hz). Must be > 0.

If a device entry defines publish_rate_hz, it is validated (must be > 0) but publishing still uses the global publish_rate_hz timer only.

pin_numbering

Value Example YAML pin Passed to gpiozero
bcm 17 17 (integer BCM number)
gpio 17 "GPIO17"
board 11 "BOARD11" (header pin numbering)
wpi 0 "WPI0" (WiringPi style index; availability depends on backend)

gpio.<logical_name>.* — per-device fields

The map key <logical_name> becomes the device name in topics and services. Required for every entry: type and pin.

type Extra fields Notes
digital_input
  • pull_up (bool, optional)
  • bounce_time (float, optional)
  • active_state (bool, optional)
  • publish_rate_hz (float, optional)
If pull_up is omitted and active_state is omitted, behaviour matches gpiozero pull-up default (pull_up=true). If you set active_state, you must omit pull_up; gpiozero does not allow both pull_up=true/false and a custom active_state. See also.
smoothed_input
  • queue_len (int, default 5)
  • sample_wait (float, default 0.0)
  • threshold (float, default 0.5)
  • partial (bool, default false)
  • publish_rate_hz (float, optional)
queue_len must be > 0; threshold in [0.0, 1.0].
digital_output
  • active_high (bool, default true)
  • initial_value (bool, default false)
pwm_output
  • active_high (bool, default true)
  • initial_value (float, default 0.0)
  • frequency (float, default 100.0)
initial_value in [0.0, 1.0]; frequency must be > 0. On real Pi hardware, BCM PWM-capable pins restrictions still apply (same as gpiozero).
servo
  • initial_value (float, default 0.0)
  • min_pulse_width (float, default 0.001)
  • max_pulse_width (float, default 0.002)
  • frame_width (float, default 0.02)
initial_value and service setpoint in [0.0, 1.0]; min_pulse_width > 0; max_pulse_width > min_pulse_width; frame_width > max_pulse_width. See gpiozero Servo.

About

ROS 2 Jazzy Python package for Raspberry Pi GPIO control using `gpiozero`.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages