A ROS2 package to use pigpio. This package is tested with Raspberry Pi 4 Model B with Ubuntu 20.04 LTS and foxy.
- Install pigpio following official instruction
- Download this repository in
<your ros2 workspace>/src
- build this package
To read inputted signal on GPIO-21 (PULL_UP), run a following command.
ros2 run ros2_pigpio gpio_reader --ros-args --param pin:=21
You can set a input pin as pull-down as below,
ros2 run ros2_pigpio gpio_reader --ros-args --param pin:=21 --param is_pull_up:=false
To write signal with GPIO-21, run a following command.
ros2 run ros2_pigpio gpio_writer --ros-args --param pin:=21
Write high signal:
ros2 topic pub --once gpio_output_21 std_msgs/msg/Bool '{data: true}'
Write low signal:
ros2 topic pub --once gpio_output_21 std_msgs/msg/Bool '{data: false}'
To write pwm signal with GPIO-18, run a following command.
ros2 run ros2_pigpio gpio_pwm_writer --ros-args --param pin:=18
A duty cycle is 0--255 which corresponded with 0%--100% Write 128 (50%) pwm signal:
ros2 topic pub --once gpio_pwm_18 std_msgs/msg/Int16 '{data: 128}'
You can control DC motors with H-Bridge motor drivers.
To control the driver, run wheels
.
ros2 run ros2_pigpio wheels
wheels
uses Maker Drive and GPIO-17, 18 and GPIO-27, 22 for Motor1 and 2, respectively in default settings.
You can drive wheels with publishing /wheels
(topic).
Move Forward:
ros2 topic pub --once /wheels geometry_msgs/msg/Twist "{linear: {x: 1.0, y: 0.0, z: 0.0}, angular: {x: 1.0, y: 0.0, z: 0}}"
Move Backward
ros2 topic pub --once /wheels geometry_msgs/msg/Twist "{linear: {x: 1.0, y: 0.0, z: 0.0}, angular: {x: 1.0, y: 0.0, z: 0}}"
Turn Left
ros2 topic pub --once /wheels geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.0}}"
Turn Right
ros2 topic pub --once /wheels geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: -1.0}}"
Stop
ros2 topic pub --once /wheels geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"