7: Wander Bot slides |

Simulating behavior in simulation
NOTE! All the book instructions make reference to turtlebot_xxx. We will be using turtlebot3_xxx

Intro

  • We will modify the instructions from the book so follow along here!
  • Code will be part of cosi119_src package which we have been using: cosi119_src

Red Light! Green Light!


$ cw
$ cd src/cosi119_src/samples/src
$ roslaunch turtlebot3_gazebo turtlebot3_world.launch
$ ./red_light_green_light.py

Reading Sensor Data

  • TB3 has a lidar
  • Lidar returns and array of 360 doubles (and some other stuff)
  • 0 degrees is straight ahead
  • Each element has distance to nearest obstacle (in M)
  • To compute the distance to the obstacle immediately ahead (0 degrees)
    • msg.ranges[0]
  • To compute the nearest obstacle:
    • nearest_obstacle = min(msg.ranges)
  • But of course those won’t be very useful (why?)

  • Experiment by running laser_scan.py program and understanding it
  • Experiment by seeing how the scan data changes based on where the simulated robot is

$ roslaunch turtlebot3_gazebo turtlebot3_world.launch
$ rostopic echo scan

Sensing and Actuation: Wander-bot!

  • Program will perform a pretty stupid trick
  • It will drive in a straight line for some seconds
  • Then it will spin in place for some more seconds
  • If it is too near an obstacle then it will spin in place
  • It turns out this is a pretty terrible algorithm
  • It gets stuck all the time
  • Take a look at the annotated code: Wander Bot Code

  • rospy.Time.now()
    • returns a time structure with
    • fields secs and nsecs
    • Comparison operator is defined
    • rospy.Duration(x) is an interval, in seconds
  • Now run the program

$ roslaunch turtlebot3_gazebo turtlebot3_stage_3.launch
$ chmod +x  wander.py
$ ./wander.py

Summary

  • Logic in a .py program can establish behaviors
  • It’s possible to modify an existing python program to be a ROS node
  • Nodes can publish and subscribe, and do both at the same Time
  • Need to know the exact names of the topics
  • Simulator is used for an idealized context for testing