Skip to content

Commit

Permalink
Fix topic names
Browse files Browse the repository at this point in the history
  • Loading branch information
botamochi6277 committed Aug 19, 2024
1 parent 9f0a78f commit 15bad4e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
20 changes: 15 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,39 @@ This package is tested with Raspberry Pi 4 Model B with Ubuntu 20.04 LTS and fox

## Install

1. Install pigpio following official instruction
1. Install pigpio following [official instruction](https://abyz.me.uk/rpi/pigpio/download.html)
1. Download this repository in `<your ros2 workspace>/src`
1. build this package
1. build this package with `colcon build --packages-select ros2_pigpio`


## Preparing

```bash
sudo pigpiod # run pigpio daemon
cd <ros2_ws> # go to your ros2 workspace
source install/local_setup.bash # install local setup
```

## Read Input Pin

To read inputted signal on GPIO-21 (PULL_UP), run a following command.
To read inputted signal on GPIO-21 (PULL_UP), run the following command.
A publisher will send read value of the pin.
```
ros2 run ros2_pigpio gpio_reader --ros-args --param pin:=21
```

You can set a input pin as pull-down as below,
You can set a input pin in pull-down with the below,
```
ros2 run ros2_pigpio gpio_reader --ros-args --param pin:=21 --param is_pull_up:=false
```

## Write Output Pin
To write signal with GPIO-21, run a following command.
To write signal with GPIO-21, run a following command. A subscriber will wait for your inputs.
```
ros2 run ros2_pigpio gpio_writer --ros-args --param pin:=21
```

When you submit a value to the subscriber, it write the signal on the pin.
Write high signal:
```
ros2 topic pub --once gpio_output_21 std_msgs/msg/Bool '{data: true}'
Expand Down
2 changes: 1 addition & 1 deletion src/gpio_pwm_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PWMWriter : public rclcpp::Node
{
set_mode(pi_, pin_, PI_OUTPUT);
std::stringstream ss;
ss << "gpio_pwm_" << std::setw(2) << pin_;
ss << "gpio_pwm_" << std::setfill('0') << std::right << std::setw(2) << pin_;
subscription_ = this->create_subscription<std_msgs::msg::Int16>(
ss.str(), 10, std::bind(&PWMWriter::topic_callback, this, _1));
}
Expand Down
2 changes: 1 addition & 1 deletion src/gpio_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class DigitalReader : public rclcpp::Node
set_pull_up_down(pi_, pin_, PI_PUD_OFF);
}
std::stringstream ss;
ss << "gpio_input_" << std::setw(2) << pin_;
ss << "gpio_input_" << std::setfill('0') << std::right << std::setw(2) << pin_;
publisher_ = this->create_publisher<std_msgs::msg::Bool>(ss.str(), 10);
timer_ = this->create_wall_timer(
500ms, std::bind(&DigitalReader::timer_callback, this));
Expand Down
2 changes: 1 addition & 1 deletion src/gpio_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DigitalWriter : public rclcpp::Node
{
set_mode(pi_, pin_, PI_OUTPUT);
std::stringstream ss;
ss << "gpio_output_" << std::setw(2) << pin_;
ss << "gpio_output_" << std::setfill('0') << std::right << std::setw(2) << pin_;
subscription_ = this->create_subscription<std_msgs::msg::Bool>(
ss.str(), 10, std::bind(&DigitalWriter::topic_callback, this, _1));
}
Expand Down

0 comments on commit 15bad4e

Please sign in to comment.