Skip to content
Snippets Groups Projects
Commit 25165ddf authored by beuchatp's avatar beuchatp
Browse files

Added rostopic FAQ details

parent c4ac093c
No related branches found
No related tags found
No related merge requests found
...@@ -249,11 +249,39 @@ Now the ``.otherCrazyflies`` property of the ``request`` variable that is passed ...@@ -249,11 +249,39 @@ Now the ``.otherCrazyflies`` property of the ``request`` variable that is passed
### I added some advertise, publish, subscribe topics but not getting the desired behaviour, what debugging tools are avilable? ### I added some advertise, publish, subscribe topics but I am not getting the desired behaviour, what debugging tools are avilable?
<details> <details>
<summary>Click here to expand</summary> <summary>Click here to expand</summary>
If you code changes compile successfully and your node runs without crashing, then the command line tool ``rostopic`` is the most useful tool for debugging errors. If your code changes compile successfully and your node runs without crashing, then the command line tool ``rostopic`` is the most useful tool for debugging errors. Open a new terminal and type `rostopic` to read the desription and help files.
After launching your node, open a separate command window and type the command
```
rostopic list
```
this will list all the topics that are currently active, including both advertised and subscribe to topics.
Common pitfalls to watch out for are:
- If there are two topics with a very similar name, then double check the spelling of the topic is identical in both the ``.advertise`` and ``.subscribe`` lines of code.
- Even if the topic name is exactly matching, the name space may be different.
- If you advertise or subscribe to a topic from with a block of code enclosed by curly braces, for example:
```
if (true)
{
ros::NodeHandle nodeHandle("~");
ros::Subscriber my_subscriber = nodeHandle.subscribe("/fortytwo",1,fortytwoCallback);
}
```
then the subscriber only exists while the code between the ``{}`` is being exectute and removed after the ``if`` statement has completed it execution. To make the subscriber persist, then you need to declare the subscriber varaible outside of the ``if`` statement's context, i.e.,
```
ros::Subscriber my_subscriber;
if (true)
{
ros::NodeHandle nodeHandle("~");
my_subscriber = nodeHandle.subscribe("/fortytwo",1,fortytwoCallback);
}
```
This would work if it is in the ``main()`` function of a node, but if it is in other functions then you should declare the subscriber as a class variable.
</details> </details>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment