Multiple nodes in final quiz

I am working on the quiz for section 4. I am getting this error

not sure why I cant import Twist. Script below

The right import statement is from geometry_msgs.msg import Twist

1 Like

thank you for your help!! that fixed the problem

now I get this

is it because I tried to initate two nodes in one program? the updated script is below

You can not launch two nodes in one script, it is not necessary, but if you need/want another node, launch it in another script.

1 Like

thank you! dont I need two nodes: one for publisher and one for subscriber?

also, how do isolate a value in the LaserScan data set. I only want the float32 ranges but the course didnt specifiy how to isolate the individual value from the rest (or they did and I missed it :frowning: )

No, one node is enough, you can create as many publisher subscribers service… etc as you want in that script with one node (one node per script).
if you use rosmsg show sensor_msgs/LaserScan you get the following:

that is what you get as parameter to your callback function (line 27 of your script)
you get the full msg so you have to get what you need from it, in this case you need the ranges that is a vector of float32 you can check in the lidar documentation that those values correspond to every angle the lidar detect. you acces the ranges like this:
in your callback function that might be defined like: def callback(msg):,
my_variable = msg.ranges[x] being x the position you need or if you need the whole vector just: my_variable = msg.ranges

1 Like

I got it!

Thank you for your help!!

I only used one laser (just increased the angle velocity). The program directions says there are two lasers? how do I access the second?

What do you mean by two lasers?
try rostopic list | grep laser if you get two lasers topics perhaps is what they mean. i think is more likely that the notebook says that you need two values from the laser topic which means you need to get two positions of the ranges array.