Outlines Developing A. Overview of the Course Programming Lab B. Robot Programming with Player/Stage Projects C. Robot Programming with Tekkotsu D. Robot Programming Projects  P1. Waypoints Following Xuejun Liang  P2. Target Searching Department of Computer Science  P3. Path Planning Jackson State University  P4. Localization and Navigation Jackson, MS, USA  P5. Another Version of P4 E. Conclusion FECS 2012 FECS 2012

A. Course Overview Course Overview (Cont.) o CSC499/539 Introduction to Robotics. o Lectures (3 Hours)  Elective course for  Covering major topics on AI mobile robotics  Both senior undergraduate students and graduate students  Reviewing C++ and Introducing robot programming with o Prerequisites:  Player/Stage and Tekkotsu  CSC 325 Operating System o Homework Assignments  CSC 323 Algorithm Design and Analysis  Assignments on major robotics topics o Catalog Description o Robot Programming Projects  Introduction to robotics and the key artificial intelligence  Five major robotics programming projects issues involved in the development of intelligent mobile robotics, including software control architectures,  Real robot (iRobot Create) and simulation localization, navigation, sensing, planning, and uncertainty

FECS 2012 FECS 2012

Course Overview (Cont.) iRobot Create/ASUS Netbook Platform

o Differential Drive o Midterm and Final Examinations o Buttons o Required Textbook  Power, Play, Advance   Introduction to AI Robotics, by Robin R. Murphy Wheel Drops (Front, Left, Right) o Reference Book  Bumps (Left, Right)  The Robotics Primer, by Maja J Mataric o Sensors  Behavior-Based Robotics, by Ronald C. Arkin  Wall, IR o Course Website  Cliffs (Left, Front Left,  http://www.jsums.edu/robotics/ Right, Front Right)  Encoders (Distance, Angle) FECS 2012 FECSo 2012 Leds

1 B. Player Sever for Robot Control Stage Simulator o Player provides a network Robot Control o Stage simulates a population of mobile moving in interface to a variety of real or Program and sensing a two-dimensional bitmapped environment. simulated robots and sensor (Client) o Various sensor models are provided, including hardware. data TCP  Sonar, scanning laser command o Player's client/server model allows Connection rangefinder, pan-tilt-zoom robot control programs to be camera with color blob written in any programming Player detection and odometry language and to run on any (Server) o Stage devices present a standard computer with a network data Device Player interface. connection to the robot command Specific Connection  Few or no changes are o Player supports multiple required to move between concurrent client connections to Real or Simulated simulation and hardware devices Robot FECS 2012 FECS 2012

Two Important Files Creating C++ Client Program o World (.world) file o Server/Client Control Structure  Needed when doing simulation using Stage  Player is server, your program is client  Things are available in the world, including robots, items,  Your code controls hardware on robot through something and layout of the world called proxy. o Configuration (.cfg) file o Program structure  Robot information: Drivers  Include the Player header file  Real robot driver is build in Player already  Establish a Player client  Simulation driver is always Stage  Connect your code to the device proxies  Items in .world file if your code interacts with them.  Control Loop (Interacting with Proxies)

FECS 2012 FECS 2012

int main(int argc, char *argv[]) { int randcount = 0; C. Tekkotsu Framework double speed, turnrate; Vector random(0,0); o It provides lower level primitives for PlayerClient robot("localhost"); An Example of Position2dProxy pp(&robot, 0);  Sensory processing, Client Program: pp.SetMotorEnable (true);  Smooth control of effectors, and Random Walk while(true)  Event-based communication { o It provides higher level facilities, including // update the proxies robot.Read();  A hierarchical state machine formalism for managing control flow in the application, // generate a random vector wander(randcount, random);  A vision system,  // compute the speed and the turn rate An automatically maintained world map, and translate(random, speed, turnrate);  Newly added Tekkotsu crew, including localization and // command the motors path planning, etc. pp.SetSpeed(speed, turnrate); o It provides housekeeping and utility functions, such as } timers and profilers } FECS 2012 FECS 2012

2 Programming with Tekkotsu Tekkotsu State and Transition o Application programmer simply define subclasses that o State nodes are behaviors inherit from the Tekkotsu base classes, and override any  Enter (Activate), Leave (Deactivate), Listen Events, member functions requiring customization Process Events o Behaviors and Events o Transitions are also behaviors  Behaviors: Construct, Activate, Deactivate, Listen Events,  A transition starts to work whenever its source state node Process Events, becomes active.  Events: Generator, Source, Type  Transitions listen for sensor, timer, or other events, and o State Machine when their conditions are met, they fire.  Robot moves from state to state.  When a transition fires, it deactivates its source node(s) and  Each state has an associated action: speak, move, etc. then activates its destination node(s).  Transitions triggered by sensory events or timers.

FECS 2012 FECS 2012

An Example: Annoying Dog Shorthand Notation #include "Behaviors/StateMachine.h" $nodeclass AnnoyingDog : StateNode { o A shorthand notation is used instead of C++ code to build virtual void setup() { state machines. The shorthand is turned into C++ by a state $statemachine{ launch: StateNode machine compiler. bark: SoundNode($, "barkmed.wav") o Node definition: howl: SoundNode($, "howl.wav") label: ClassName`(args)[inits] wait: StateNode launch =N=> bark o Transition definition: bark =T(5000)=> howl =label:TransAbbrev`(args)[inits]=> bark =B(RobotInfo::GreenButOffset) o Node Class definition [setSound("ping.wav")]=> wait wait =T(15000)=> bark $nodeclass ClassName(parameters) : ParentName(args) : howl =C=> wait initializers : methodname { } body } } } FECS 2012 FECS 2012 REGISTER_BEHAVIOR(AnnoyingDog);

Advanced Knowledge of Tekkotsu D. Robot Programming Projects

Projects o Transit from one state to multiple states o P1. Waypoints Following simultaneously so as to support parallel actions or o P2. Target Searching behaviors, o P3. Path Planning o P4. Localization and Navigation o Transit from one state to one of multiple states based on different conditions so as to make a conditional o P5. Another Version of P4 transition, and Discussing Aspects 1. Task and steps to accomplish the task, o Pass and/or share data among states so as to provide approaches of the data flow and the memory 2. Programming model (structure) and skills, 3. Concepts, algorithms, and mathematical formulas, 4. Issues regarding to failures, uncertainty, and real-time constraints FECS 2012 FECS 2012

3 P1. Waypoint Following Waypoint Following (Cont.)

o Read waypoints from file 1. Following waypoints  File I/O and queue data structure Read with simulation o Go to waypoint Waypoints From a File  Get the current pose of the robot 2. Following a square path  Compute how far the robot to the waypoint Set of Waypoints with iRobot Create and  Compute the angle of the robot to the waypoint measure its odometry error Pilot  Return true if the robot has reached the waypoint, Next Waypoint Waypoint is reached otherwise, return false o Translate Distance, Speed, Angle Turn rate  Use servo-loop control approach to determine an updated Go to Translate Waypoint speed and turn rate to drive the robot based on the distance and angle between robot and waypoint. FECS 2012 FECS 2012

Waypoint Following (Cont.) P2. Target Searching o Uncertainty  Odometry error Laser Avoid Vector  Obstacles

Wheel slippage and discretization of the continuous wheel rotations Sequencer Vector Combine Steering, o Mathematical formulas and Concepts Vector Velocity Vector Translate  Compute distance between two points Wander Vector  Compute slope of a line  Compute angle between two lines Fiducial Vector  detector Go to Angle range: [-π, π] Beacons  Degree V.S. Radian o Programming skills Detect beacon  File I/O operations and queue operations  Pass-by-value V.S. Pass-by-reference Note: Vector is a pair of distance and direction

FECS 2012 FECS 2012

Target Searching (Cont.) Target Searching (Cont.) o Avoid obstacles o Go to beacon  Check to see if there is an obstacle in front using laser  Check to see if there is a beacon using Fiducial detector scanner.  If a beacon is found  If an obstacle is found, set up a distance and an direction to go for about 2 seconds to avoid the obstacle.  Compute how far the robot to the beacon  Otherwise, set distance=0 and direction=0.  Compute the angle of the robot to the beacon o Wander  Computer the world coordinates of the beacon  Generate a random distance and a random direction every 3  If a beacon is not too close (and has not been visited seconds yet), return true, Otherwise, return false o Combine  Otherwise, return false  Compute weighted sum of the two input vectors o Sequencer o Translate  If a beacon is detect, use avoid obstacle and go to beacons  Same as in P1 FECS 2012  Otherwise, use avoid obstacleFECS 2012 and wander

4 Target Searching (Cont.) P3. Path Planning o Mathematical formulas and Concepts Goal  Generate a random number in a given range Wavefront Path Planer The path planner accepts as  Compute distance and angle input a user's goal point and  Coordinate Transformation (Rotation and Shift) Set of Waypoints generate the waypoints of a path to the user's goal point  Vector addition Pilot o Real-time constraints Next Waypoint Waypoint is reached  Set up a distance and an direction to go for about 2 seconds

 Generate a random distance and a random direction every 3 Go to Vector seconds Waypoint Steering, Vector Velocity o Programming skills Combine Translate  List operations Laser Avoid Vector Obstacles  Vector class

 Pass-by-value V.S. Pass-byFECS-reference 2012 FECS 2012

Wavefront Path Planer Wavefront Path Planer (Cont.) o Read the input map into the grid map o The occupancy grid (Study the functions inputMap and o Convert starting and goal points from the world coordinate into the image coordinate outputMap) o Check if the goal point is in the wall  The inputMap function reads in the map into a two- o Label the goal point on the grid map dimensional binary occupancy grid array in which 0’s o Grow the grid map a few times represent free space and 1’s represent obstacles (walls). o Propagate the wavefront until reaching to starting point or until the wavefront can not be propagated  The outputMap function writes out the occupancy grid o Compute waypoints information into a scaled map, which can be used to o Relax waypoints visualize your planner’ results o Store waypoints in the grid map o The conversion between the World Coordinates and the o Print the grid map into the output map Image Coordinates (Study the functions computeHW and o Convert waypoints from the image coordinate into the world coordinate and then return them computeXY) FECS 2012 FECS 2012

Wavefront Path Planer (Cont.) Wavefront Path Planer (Cont.) o The function grow( ) o The function propagate(…)  This function grows the obstacles in the grid map for a  This function propagates the wavefront one grid cell single step, i.e. one grid cell farther farther. It starts from the grid cells with value i and the o The function nextWaypoint(…) propagated cells get the value i+1.  This function computes the next waypoint.  If the cell of robot’s starting point has the same value of the start parameter, then the wavefront propagation should be  The next waypoint is a neighboring cell of the current over (done = 1). waypoint and its value is 1 less than the value of the current waypoint cell.  Otherwise, propagate the wavefront to its neighbors.  This function is called first with the current waypoint equal  if there is no room to propagate the wavefront, then the to the robot’s starting point. robot’s goal point is unreachable (done = 2);  It is called continuously until the new waypoint is the goal  otherwise, the wavefront can be propagated continuously (done = 0) point. FECS 2012 FECS 2012

5 Wavefront Path Planer (Cont.) P4. Localization and Navigation

N o Mathematical formulas and Concepts o This is the task for the WN EN 2010 Robotics Competition  Grid map representations held along with the 2nd W E  Conversion between the World Coordinates and the Image Annual ARTSI Student Coordinates Research Conference WS ES  The wavefront path planning algorithm o The task is to get a robot to S o Programming skills localize itself within a maze, navigate efficiently  Queue between locations, observe  Two-dimensional array objects in the maze, and report on what it has  Pass-by-value V.S. Pass-by-reference observed.

FECS 2012 FECS 2012

P4 (Cont.): Milestones P4 (Cont.): Skills and Challenges o What students need to know first o Basic Programming Skills  Following wall  Instantiate a class  Recognizing color balls (objects in the maze)  Derive a subclass  Detecting and visiting bi-color navigation marks o Tekkotsu Programming Challenges  Memorizing what objects have been seen already o Milestones  New state machine programming language  Travel though the maze by using “following wall”.  New semantics of state machine  Able to start “follow wall behavior” and able to stop  Setup computer camera setting for a specific light condition  Travel though the maze and report detected color balls o Uncertainty and Failure  Report only once per ball, so need memory  Bi-color markers are difficult to detect  Travel though the maze and report detected color balls and  Dealing with false color balls their locations FECS 2012 FECS 2012

P4 (Cont.): Follow Wall P4 (Cont.): Memorize Color Balls

o Color ball encoding: Speech =N=> Forwards  Orange(Red): 1 “Tiger Starts …” 50 mm/s  Blue: 2 Delay =B( )=>  Green: 4 Halt o The color ball combinations can be encoded as follows =C=> =T(60000)=>  {Red, Blue} = 3, =S=>  {Red, Green} = 5, Check IR Hold Result Send Stop  {Blue, Green} = 6, =S=> =S=>  {Red, Blue, Green} = 7 o The color ball sequences can be encoded as follows The robot can be placed in anywhere and can be stopped  (Red, Blue, Green)= 124, after a given period of time  (Blue, Green, Red) = 241, and etc. FECS 2012 FECS 2012

6 P4 (Cont.): Find Balls and Report P4 (Cont.): Detect and Visit Marker

Turn to Speech =N=> Search pi/6 Forwards C “Tiger Starts …” 50 mm/s S Speech C Turn to Delay =B( )=> =N=> Look Again “Looking for …” Marker Halt T(3000) S =C=> =T(60000)=> =S=> Look Ball Again Take Speech C =S=> Snapshot “Arrived at..” Check IR Hold Result Forward =T(3000)=> =C=> N S Speech C =S=> Check for Check Ball Marker F “Not find …” Report In case of failure in finding any marker,

FECS 2012 the robot just goesFECS 2012 straight to hit the wall

P5. Another Version of P4 P5 (Cont.): Task and Differences

North (1981.2, 457.2) x (1981.2, -1524.0) o This is the task for the 2011 4 5 6 o This task is the same as the one in P4 except Robotics Competition held rd 3 7  The bicolor makers are replaced by the AprilTags, and along with the 3 Annual E F ARTSI Student Research 9 8  The three color balls are replaced by three cubes with each covered by different AprilTags Conference 10 11 o The major differences between P4 and P5 2 12 C D  In P4, each bicolor marker is treated as a topological 14 13 navigation marker and the metric measurements of the 15 16 y maze are not used at all. 1 (0.0, 0.0) 17  In P5, a metric map of the maze is used in the robot A B 0 19 18 localization and path planning and execution.

(-457.2, 457.2) (-457.2, -1524.0) FECS 2012 South FECS 2012

P5 (Cont.): Milestones P5 (Cont.): Uncertainty and Failure o What students need to know first o Due to the uncertainty, the robot may not be able to be close enough to the target location. In this case, the goto  Drive the robot forward or make a turn, function should redo itself again until the robot is close to  Check the robot location inside the maze, the target within a threshold distance (for example, 200  Localize the robot within the maze, and mm). If the robot is still not able to reach the target after redoing 3 times, the goto function should be stopped and  Look AprilTags that are facing to the robot. return a failure. o Milestones o Due to the same reason as above, the robot may hit walls before reaching to the target. In this case, the robot should  Memorize object the robot has observed in each alcove. backup a little bit and then the goto function should redo  Look for the object in each alcove itself again. If the robot is still not able to reach to the  Drive robot to a waypoint in the maze. (goto function) target after redoing 3 times, the goto function should be stopped and return a failure  Put it together

FECS 2012 FECS 2012

7 P5 (Cont.): Put It Together Conclusion

o The robotics course is for both undergraduate students

drive and graduate students

Completion Walk End Look o It covers major topics on intelligent mobile robots, including robot control architectures, localization, wait4walk result wait4look navigation, sensing, planning, and uncertainty o Robot programming is a key component of this course randomize localize backup looktags turn4look o Five major robot programming projects have been again done Failure adopted, developed, and taught record decide gotowaypoint o More teaching resources are needed such as textbook, robot programming materials, etc.

FECS 2012 FECS 2012

Moore Projects Using Tekkotsu

Shoot balls Move canisters into a “pen”

FECS 2012

8