Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sensors.md doc #495

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions ionic/sensors.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ The last command listens to the messages sent over the `/imu` topic. The IMU dat

![Imu_message](tutorials/sensors/imu_msgs.png)

Move your robot forward using the keyboard up key. You should see the sensor values changing.
Move your robot forward using the keyboard up key. To do so, don't forget to enable the Key Publisher Plugin. You should see the sensor values changing.

## Contact sensor

Expand Down Expand Up @@ -315,24 +315,25 @@ To do that, we'll write a short C++ program that listens to
the sensor data and sends velocity commands to the robot.
This program is called a node. We will build a node that subscribes
to the `/lidar` topic and reads its data.
Have a look at this [tutorial](https://gazebosim.org/api/transport/9.0/messages.html)
Have a look at this [tutorial](https://gazebosim.org/api/transport/14/messages.html)
to learn how to build a `publisher` and a `subscriber` node.
You can download the finished node for this demo from [here](https://github.com/gazebosim/docs/blob/master/ionic/tutorials/sensors/lidar_node.cc).

#### The lidar_node

```cpp
gz::transport::Node node;
std::string topic_pub = "/cmd_vel";
gz::msgs::Twist data;
gz::transport::Node node;
auto pub = node.Advertise<gz::msgs::Twist>(topic_pub);
```

We declare a `node` which will publish to `cmd_vel` topic and defined the message type `Twist`. Then advertise our node.
We declare a `node` which will publish to `cmd_vel` topic. Then advertise our node.

```cpp
void cb(const gz::msgs::LaserScan &_msg)
{
gz::msgs::Twist data;

bool allMore = true;
for (int i = 0; i < _msg.ranges_size(); i++)
{
Expand Down Expand Up @@ -362,11 +363,11 @@ If so we publish a message to our car to move forward. Otherwise we make the rob
```cpp
int main(int argc, char **argv)
{
std::string topic = "/lidar";
std::string topic_sub = "/lidar";
// Subscribe to a topic by registering a callback.
if (!node.Subscribe(topic, cb))
if (!node.Subscribe(topic_sub, cb))
{
std::cerr << "Error subscribing to topic [" << topic << "]" << std::endl;
std::cerr << "Error subscribing to topic [" << topic_sub << "]" << std::endl;
return -1;
}

Expand Down
Loading