Friday, April 25, 2014

Lab Session 9

Date: 24 April 2014
Duration of activity: 3 hours
Group members participating: Lukas, Daniela, Helene

Goals:


  • Perform exercises from Lab Session 9

Plan:

  • Modify the standard car with a better support wheel.
  • Use the DifferentialPilot class to make the car drive in the pattern given in the exercise.
  • Perform experiments to se how precise the DifferentialPilot is.
  • Discuss how to navigate while avoiding objects.
  • Discuss how to improve navigation.

Results:

We started by modifying the standard car we build from the instructions at the last lab session. We replaced the supporting wheel with a round brick to make the car turn more smooth. 

After building the car we measured the wheel diameter and the distance between the wheels, we got the following result:



  • Wheel diameter: 56 mm
  • Wheel distance: 103 mm

We wrote a navigation program, which uses the DifferentialPilot and the above measurements to make the car drive in the following path:


To do this we wrote the following code:


where we start by initializing the differential pilot with our measurents and afterwards asks the pilot to make the care drive in the wanted pattern.

To test this program we attached whiteboard marker to the car and placed it on a whiteboard lying on a table. Our first attemts was not very accurate with respect to the rotation. We had some problem with rotating the right angle. Especially the last rotation was far to big. When we started to investigate these problemes our first observation was that we had not calculated the last angle correctly. Just observing the figure we thought that the cars should rotate an angle of -135 degrees, but when using the cosinus relation to get a more accurate result we got that the car should rotate an angle of 90+27,5 = 117,5, which is much smaller than our original angle. 
The rotations was still not very precise, so we decided to invesigate whether our measurements were correct. Since the car drives the exact value specified when driving a straight line we concluded that the problem must be in the distance between the wheels and not the diameter of the wheels, since the diameter has effect on both straight lines an rotations, while the distance only effects the rotation. 
This conclusion lead us to try to vary the value for distance between the wheels in the code. To check whether the value is good or bad we changed the program to make the car drive straight for 20 cm and then turn 180 degrees and keep repeating this. Our goal is for the car to keep driving on the same line. The code for this experiment can be seen in the following figure:



The complete program can be found here: Navigator.java

The following video shows the car drive according to the above code for the original wheel distance of 103 mm:



In this video it is clear that the car turns to little, which gives us a very nice pattern, but not the one we desired. In the following you can see the test drives for different values of the distance between the wheels:

Wheel distance: 106 mm


Wheel distance: 109 mm


Wheel distance: 108 mm


This experiment show us, that the best distance was 108 mm.

After these exeriments we tried to measure the distance between the wheels agian using a measuringtape. We found that the actual distance between the center of the two wheels was very close to 108 mm. 
The reason why this measurment is so different from our first one could be that while handling the car we have moved the wheels a little, and the first measurement might not have been very accurate.

After this adjustment we tried to run the penny pattern program again, and this time we got a very good result. See the following video and figure:







Based on these experiments we started to discuss the following two questions stated in the exercise:


  • Navigation while avoiding objects
We could use the differential pilot to remember the robots position. When we remember the way the robot drives and how much it turnes at any point, we can calculate the current position and orientation by using vector operations. From this, we can always find the direction and distance to the goal we wanted to drive to. 

To detect obstacles we could use ultrasonic sensors, which give a distance to some object that may be in the way. Using this distance and the sensor orientation and position relative to the robot, we can compute a point in 2d space, where there is an obstacle. To check if the robot can drive through some part of the field, we remember all the points where there might be an obstacle, and simply avoid points with some distance or check if the robot might fit in between two obstacles/points.


  • Improved navigation
Method 1 (source [2]):
Use a thread to constantly check what we would call tacho count ( which they call shaft encoders ), and loop in small time intervals. For every time interval, assume that the robot drove in a straight line, and update the position we are at accordingly. This is called "Dead Reckoning"

Method 2 (source [5]):
Forward kinematics.

This method does not assume that the robot drove in a straigh line, but approximates the curve the robot drove around a center point with some angular velocity.


We see that the big difference between the two method is that method 1 is a more rough approximation, while method 2 tries to approximate the cars movements based on the laws of kinematics and angular movement.

We did not succeed in determining the method used by leJOS. We think that it looks more like method 1, by tries to do something smart when the car drive in a arc.

If we should choose between the two method we think that method 2 seems to be somewhat more accurate, because the timesteps used in method 1 could easily be a little to large, and the robot could have turned to much to make the approximation with a straight line to erronous.


Conclusion:

We got our car to drive very precisely along the path, when we found the correct values for the wheels diameter and distance from each other. This means that the DifferentialPilot implementation is reasonable accurate. Further testing could be done by letting the DifferentialPilot drive the robot for much longer distances and more complex paths, to see how well the implementation holds up or how good our measurements are for the long run.


References:



Tuesday, April 22, 2014

Lab Session 8

Date: 10.04.2014
Duration of activity : 3 Hours
Group members participating: Lukas, Helene, Daniela

Goals
  • Build a robot car that can drive on the competition track (modified Alishan train track) according to the specified rules. 
Plan
  • Decide which sensors to use and formulate and overall strategy on how the car should work
  • Build a car
  • Write the software, make experiments and make changes to the software until we get the car to work
Results
We strated building a car and tried to place the motors under it in order to make the car as "thin" as possible. We thought that having a small footprint will make the car less prone to falling from the edges of the track and at the same time it will be possible for the car to turn faster. We used quite a lot of time building our own car but decided at the end to use some of the lego standard instruction, since our own car was not very stable while driving. 
The final car is equipped with two light sensors, used for PID control. The main idea was to use the light sensors to make the car follow the track and use tacho counts, where the PID controller failed.


First strategy

Our first idea was to make a line-follower. We wrote a program where we used data from the light sensor in order to make a PID controller following the Zigler-Nichols method. We calculated all the errors in the program as the difference from a  "gray" target value that we empirically determined at the beginning of our experiments.

Following the Zigler-Nichols method, the first step was to determine the p-gain at which the car begins oscillating. We wrote a program (see link below) in order to be able to change the p-gain parameter without compiling each time. We then found the right p-gain by making small incremental changes to the parameters and observing the car follow the line. 


We found the oscillating p-gain to be 0.6. We then logged the errors from the gray target value as recorded by the light sensor while the car was oscillating and found the oscillating period to be ca. 700 msec.


Afterwards we wrote a method that calculated the i-gain and d-gain from the two parameters above following the Zigler-Nichols method. 


Here ku is the p-gain and pu is the oscillation period.




We got quite good results when the car was following a straight line or driving along smooth curves, but the car was not able to follow the line on the track, because the car pivots when driving from the slope onto the platform and the light sensors got lifted off from the surface.


Second strategy
Our second strategy was to make a combination of the first strategy and some "hard-coding" of the behavior of the car in order to improve the car's performance at the curves of the Alishan train track.

We defined a state variable describing at which segment of the track the car is, and programmed the behavior of the car for each state as follows:


  • State 0 (first slope): We use the PID controller to let the car follow the straight line but we calculate the distance the car has to drive and measure it with the tachocounter. When the tachocounter has reached a certain value the car stops. This happens at the end of the first slope of the track.
  • State 1 (first platform): We use the tachocounter to drive and turn right for a while in order to let the car make a curve. The car slows down before the end of the turn and keeps driving until it sees the black line of the second slope. At this point it stops, turns a little to the left in order to be inlined with the straight line of the second slope.
  • State 2 (second slope): PID controller starts again and the car follows the line until the end of the second slope as in state 0.
  • State 3 (second platform): The car does the same as in state 1 but this time it turns to the left. Here we need to take into account that the motors behave differently, so we can not reuse the values for steering the motors to turn left.
  • State 4 (third slope): The car drives up the last slope as in state 0 and 2 but it travels slightly longer and ends up in the middle of the top platform.
  • State 5 (top platform): When on the top platform, the car turns slightly to the left, then keep turning until the left sensor sees black (the black line) then only turn very slightly and starts using the PID controller to follow the line to drive downward.

After some experiments we changed the way state 1 and 3 work: the car does no longer stop before turning, but it just drives forward while turning in the opposite direction, to end up on the black line and start the next state, which uses PID to follow the line. This process is more smooth and works more reliable, especially for the second turn. 

For example, the code for turning and searching for the black line in state 1 looks like this:
Here, distance is the average distance value of both tacho counts. rightValue is the reading fro the right light sensor and black is the measured light value for the black color of the marks on the track.
  We didn't finish programming the dowhill drive of the car. We tried to use some of the same principles as in the uphill drive, but we had some problem stabilizing the car, since it was often "sliding" down the track. It seemed like the car was mostly accelerated by gravity instead of the motors, but we only tried slowing the car down and driving more carefully, instead of trying to drive fast down the slope.

For now, the car manages to drive to the top of the track quite reliably, but does not at all manage to drive down again.

The code for the program can be seen in the following link: https://www.dropbox.com/sh/w9410uhkc680xii/YaQH64H9hz and https://www.dropbox.com/s/r0b5lu3sdj5dznh/RacerMain.java

The final video documenting the drive can be seen here:


Time: infinity.


















Monday, April 7, 2014

Lab Session 7

Date: 04.04.2014
Duration of activity : 3 Hours
Group members participating: Lukas, Helene

Goals
  • Perform exercises from lab session 7
Plan
  • Add ultrasonic sensor, light sensor and bumper to the robot.
  • Observe the robot with a single behavior
  • Modify the observed behaviour
  • Observe the robot with multiple behaviors
  • Program the Escape behavior
  • Add third motor
  • Analyze Arbiter and Shared Car classes
Results

Single Behaviour: 

We added the light sensor, the ultrasonic sensor and the two pressure sensor for the bumper to the robot.

Then we uploaded the program RobotFigure9_3.java to the robot and ran it. With this program, the robot drove straigh ahead, until some big object was about 20 to 30 centimers in front of it. The robot then stopped, turned left and right and then drove further in to one of the two directions it just turned. Sometimes, the robot stopped again immediately, to turn left and right and change its direction again.This resulted in the robot avoiding some obstacles in front of it, like table legs and feet. When driving into a corner, the robot would just rotate left and right in the corner, without being able to escape.

To fix this behavior, we were tasked with changing the behavior to let the robot rotate 180 degrees, when something is in proximity, both when it turned left and right. We changed the program by adding a check, that if it turned left and right, and in both directions the ultrasonic sensor did detect something close by, we let the robot drive back a little and turn on the spot for about 2.25 seconds, which results in approximately a 180 degree turn. We also changed PrivateCar.java slightly, to make it possible to give negative values to the method forward(), to be able to turn on the spot, instead of turning with only one motor. Here and here are the files that were changed.


The changed section in RobotFigure9_3.java 

When using the modified program, the robot turned away, when it was stuck in a corner, or put very close to a wall or large objects and still avoided objects, when it detected that there was enough space in one direction.

The robot in action:
 

---------------------------------------------------------------------------------------------------------------------------
Multiple Behaviours:

In the next exercise, we were asked to observe the robots behavior, when running the program RobotFigure9_9.java. When letting the robot drive around in the lab, it behaved mostly liked it did at the very start of the lab session, it avoided objects and otherwise drove straight ahead, only this time, there were more pauses, where the robot would just sit and do nothing for a second or two.  Sometimes, it turned left and right and chose a new direction, without there being something in front of the robot. Other times, it would choose a new direction and drive much faster for a very short amount of time. This behaviour was the result of three different behaviors that could be triggered by different sensor inputs.
  • The Cruise behavior: Was always triggered and let the robot drive straight forward.
  • The Avoid behavior: Triggered when the ultrasonic sensor detects something being close. Turns the robot left and right and chooses a new direction.
  • The Follow behavior: Triggered when the lightsensor detects a value above a certain treshold. Turns the robot left and right and chooses the direction where the most intense light had been measured.
When we turned off the Avoid and Follow behaviors, the only behavior controlling the robot was the Cruise behavior, resulting in the robot only driving forwards and never turning.

When enabling the follow behaviour again, we used a mobile phone's LED as a lightsource and let the robot drive around in a darkened room. When pointing the light at the robots light sensor, it stopped and turned left and right, and then drove roughly in the direction of the lightsource, effectively following the mobile phone through the room. 

We were asked to implement a new behavior, the Escape behavoir, which uses the bumper on the pressure sensors to make the robot turn, when it drives into something the ultrasonic sensor could not detect. We implemented it slightly different to what was proposed in Mobile Robots on page 305. When both pressure sensors were pressed, our robot should back off and turn 180 degrees, instead of just making a 90 degree turn. When only sensor is pressed, the robot should back off and turn 90 degree away from where something pressed the sensor. The full behavior is implemented in Escape.java and the core part is shown here.
The Escape behavoir is then added to RobotFigure9_9.java by assigning a SharedCar which the behavoir can use, and starting it in its own thread. This is implemented in RobotFigure9_9-2.java. When running this program, the robot drives backwards and turns, when the bumber is pressed or the robot hits an object that the ultrasonic sensor did not sense. For now, the robot does turn by only using one wheel, and leaving the second wheel off, which requires more space than turning on the spot.

The behavior of the robot can be seen in this video:
 
We ran out of time at this point.

Conclusion

In this lab session we experimented with different behaviors that run in parrallel and successfully implemented the Escape behavior. The next thing we would like to do is to make the robot turn on the spot, which only requires small changes to the classes provided for the exercise. Building the robot with three motors, and the lightsensor on the third motor and changing the behaviors accordingly seems like an interesting task. Especially because this would make it possible to steer the robot more smoothly, instead of stopping and turning twice. The robot could just continue to drive, while the light sensor moves around and a behaviour changes the movement of the robot slightly based on the light sensors readings. An interesting challenge would also be to have the light sensor always point in the same direction and not "loose" a lightsource, while the robot turns beneath it.

References