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.


















No comments:

Post a Comment