diff --git a/pps_wiki/faq.md b/pps_wiki/faq.md index f9157ed0a37a800c3433dcf5397a4338b626cf3f..f4dc27fd72dfe464c153195da21eab34f3d6905d 100644 --- a/pps_wiki/faq.md +++ b/pps_wiki/faq.md @@ -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> <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>