COMP329: 2017-2018
Robotics and Autonomous Systems - Labs
COMP329 Lab 2 - Pilots, Odometry and Behaviours
Todays Tasks:
Step 1: Playing with the MovePilot.
Download the class SimplePilot.java available from the course web site. Take a look at the code. It drives the robot forward, as well as allowing you to turn left and right, and drawing a square. Modify this to draw a triangle and a hexagon, but in the opposite direction to the square. Check to see if it returns to the correct position, and see if you can improve the calibration so that it does.
Step 2: Playing with the OdometryPoseProvider.
Download the class SimplePose.java available from the course web site. Take a look at the code, and try it out. Although it illustrates how the OdometryPoseProvider works, we can use it to correct our expected position if for some reason we don’t go where we expect!!!
Download the class RandomDriver.java and look at the code. It drives the robot randomly over a set of 10 moves. Compile and test in one of the bays. Modify the RandomDriver class to navigate the robot back to its starting place after the random driving, by adding to your project and making use of an OdometryPoseProvider.
Hints:
•If the odometry tells you that the random motion has moved the robot through D degrees, then turning −D degrees should have the robot facing back to its start point.
•To figure out how to use the odometry information you will have to look at the LeJOS API online.
Expect that even when your code is right (which you can tell by looking at the pose stored in the Pose in your OdometryPoseProvider data) there will likely be some error in the final position of the robot.
Step 3: Recording events using the OdometryPoseProvider.
Write a program that drives the robot around the robot arena, detecting when it bumps into objects, and logging the positions of the objects it bumps into. Replay the locations of the “bumps” on the LCD screen when the robot finishes driving round (you decide how to end the driving round.)
Step 4: Understanding Threads.
Download the following classes from the course web site: SimpleRobot.java, RobotMonitor.java, RunMonitor.java (listed under the Notes on Threading and Multitasking). Note the following:
•SimpleRobot: This constructs a simple robot that controls the motors directly, and thus is not as sophisticated as the earlier code using Pilots. Note how it sets up the sensors so that they can be checked in a simple way.
•RobotMonitor: This constructs a monitor for the robot as a thread, so that data about the robot is displayed on the LCD screen. The constructor is passed a reference to the SimpleRobot instance, so that it can interrogate the status of the sensors and motors
•RunMonitor: This is our main class that constructs an instance of a SimpleRobot, and a Robot Monitor. it starts the RobotMonitor thread, and then provides control over the motor using the keys on the EV3 brick.
Compile the code and try it out. Note how we are using the robot’s motors rather than a Pilot Provider. Try extending these classes to use a MovePilot instead of the motors directly.
Step 5: Familiarising yourself with Behaviours.
In the lecture notes, we looked at code to generate behaviours within the Subsumption Architecture. Whilst you could play with that code, its behaviour is limited because of the direct use of the motors. It would be better if we could use a MovePilot, using the non-blocking class to move. Using odometry also allows the robot to correct its heading if it has to navigate around an obstacle.
Download the following files, which allow the robot to move around like a bumper car:
•DriveForward.java: This behaviour simply moves the robot forward, and is the lowest priority behaviour.
•BackUp.java: This behaviour causes the robot to reverse slightly after encountering an obstacle, and then change its direction.
•BumperCar2.java: This class provides the main code for creating the Arbitrator using these two behaviours.
You will also need two variants of our SimpleRobot (which are similar to the code you wrote in the prevous step):
•PilotRobot.java: This robot provides access to the sensors, but constructs a MovePilot to control the robot. A getter is provided to access the pilot directly
•PilotMonitor.java: Similar to the RobotMonitor, it also access the pilot to get information about the types of moves the pilot is making.
Test out the code. Note how when it hits an obstacle, it avoids it. The aim of the next two steps are to explore how to use these classes.
Step 5.1: WallFollowing.
Modify the code from Step 5 to add two new behaviours that follow a wall that is on its left (i.e. that it navigates the arena in a clockwaise direction):
1.ReturnToWall: this should cause the robot to move in an arc a few degrees towards the wall if the robot is more than a set distance from the wall (e.g. 30cm). It doesn’t have to guarantee that it is by the wall, as the arbitrator will keep activating this behaviour until its goal is achieved.
2.MoveFromTheWall: if the robot is too close to the wall (e.g. within 15cm) then the robot should move in an arc away from the wall by a few degrees.
It shouldn’t matter in what order these are defined (in terms of priority, but both should be higher priority than DriveForward, and below BackUp. You may also want to modify the BackUp behaviour so that when it hits a wall ahead of it, it backs up and rotates 90 degrees. This code assumes that the IR Distance Sensor is pointing towards the left of the robot. Take care that none of your code is blocking, but can respond immediately if a suppress occurs.
Step 5.2: ObstacleAvoiding.
Modify the code from Step 5 so that the robot tries to travel from its starting point to an end point (e.g. 1.5m away). Change the DriveForward behavour to head in a straight line from the current position to its target position. Add an odometry pose provider to use odometry to change the robots orientation and move in the correct direction. You may also need to change BackUp to not only move back and rotate, but also to move a short distance perpendicular to the obstacle to avoid it.
The aim of this lab is for you to become familiar with using the MovePilot (as opposed to controlling the motors directly). You will use the Odometer Pose Provider class to understand how you can track where the robot thinks it is (the same approach is used by the robot to know when it has reached its destination). Then you will explore how to write Behaviours within the Subsumption Architecture. You also get to play with Threads.
These labs are designed to prepare you for working on your first Assignment of COMP329.