tirsdag den 18. marts 2014

Date: 14/03 -2014
Duration of activity: 8 Hrs
Group members participating: Alexander Rasmussen and Søren Ditlev

Vehicle 1

Goal:

Make a system according to Tom Dean's notes[1][2]. Attach a sound sensor and try different mapping between the sound and the system motors.

Plan:

Use the Car.java and SoundDriver.java classes to create a system that uses the sound sensor values to send power to the motors. Try Different mapping between the sound sensor and the motors:
  • Percentage
  • Low sound values as negative motor power
  • Inhibitory

The to make the system drive backwards on low sounds we used the the percentage to determine when the system should drive forward or backwards. Sound percentage under 50% would make the system drive backwards. We mapped so that Sound values lower than 50 would be subtracted from a max motor power of 100. This means that the lower the sound the faster the system will drive backwards   

Results:


Picture of Sound Sensor System
*
We modified it with bigger wheel to look cooler, and get rid of the cog-wheels in the back  



Video of fLow sound values as negative motor power system[3]

Algorithm which uses the sound level to go either forwards or backwards:
int goVar = 10;
while (go) {
        soundlevel = sound.readValue();
        motorPower = soundlevel;
       
        LCD.drawString("Soundlevel " + soundlevel, 0, 0);
        if(soundlevel > 50){
        motorPower = soundlevel + goVar;
        Car.forward(motorPower, motorPower);
        }else{
        motorPower = (100 - soundlevel) + goVar;
        Car.backward(motorPower, motorPower);
        }
       }

Conclusion:

Motors need a minimum value of 40 in order to turn on the motors and minimum value of 60 in order to move the system. Therefore it needs a high continuous sound to drive straight forwards.A goVar value was added to the system code which multiples sound sensor values and makes the system go faster at lower sound values. We observed that other groups had a problem where the system’s motors made  enough noise to make the system going once it was started, however we did not experience that problem.

Vehicle 2

Goal:

Make a system that uses values from two light sensors to power the motors.

Plan:

Use the Car.java and a modified version of the SoundDriver.java (which uses light instead of sound sensors) to program  the system. Place two light sensors in approximate 100 degree angle to each other in the front of the system, so that have the possibility to detect different light values from each sensor.Try different mappings between light sensor and motor power and observe how the system behaves.

Results:









Picture of Light Sensor System
*



Video of light sensor system[5]
The code works by setting the measured light value as the power to the motor. Because the motor needs a certain amount of power to drive the wheels, we have implemented a variable goVar that we multiply with the light value to make the robot move. This variable is adjusted accordingly to the ambient light of the environment.

Algorithm which uses light sensor to follow light:
float goVar = 1.9f;
       while (go) {
        rightLight = lightRight.getLightValue() * goVar;
        leftLight =  lightLeft.getLightValue() * goVar;
       
        Car.forward((int)leftLight, (int)rightLight);
        LCD.drawString("LightLeft " + leftLight, 0, 0);
        LCD.drawString("LightRight " + rightLight, 0, 1);
       }

Conclusion:

We tried to do a light following system that would follow another system with lamp mounted in the back, in a dark room. However we had a problem getting the first system moving, so the second system would bump into the first. If we tried to introduce an alternative light source into the environment both systems would follow the light source. A way to make the experiment work would be to have one system leading at steady pace and use Ultrasonic sensors to avoid driving into the wall. The second system should follow a light source on the  first and have inhibition to is motor power, so once the light value would get too high the system would slow down to avoid bumping into the system in front.        

Vehicle 3

Goal:

Combine light and ultrasonic sensors to make a party finder robot.

Plan:

we plan to use the ultrasonic and light sensor as we did in the first partyfinder in exercise 3[4]. We will make the system go towards light but avoid obstacles on its way by letting light values give positive motor power and Ultrasonic value give negative motor power.   

Results:

Light and ultrasonic system
*

Video of party finder[6]

The code is implemented by letting the light value work as an exitatory connection  and the sonars as an inhibitory connection. To tweak the values from the sensors according to the motor power, we have implemented variables that is added to the light value, and a variable which divides the distance.

Code Of While Loop:
float leftVar = 2.0f;
       float rightVar = 2.0f;
       while (go) {
        int distanceRight = rightSonic.getDistance();
        int distanceLeft = leftSonic.getDistance();
        float rightLight = lightRight.getLightValue() * rightVar;
        float leftLight =  lightLeft.getLightValue() * leftVar;
       
       
        float motorRight = rightLight - ((255 - distanceLeft)/3);
        float motorLeft = leftLight - ((255 - distanceRight)/3);
       
        Car.forward((int)motorLeft, (int)motorRight);
        leftVar = 2.0f;
        rightVar = 2.0f;
}

In order to get the system to work correctly it is important to tweak the light and US to send the appropriate values to the motor. We found, by logic, trial and error, that by dividing the US by 3 and multiplying the light value by 2 the

Conclusion:

The Party finder worked very well. It was able to navigate towards the light and use the Ultrasonic sensors to avoid objects. However we noticed a few flaws. If the system drive into a corner it will detect negative values on both US sensors and stop. This problem can be solved by programming clause that detects when motor power of both motors is lower  then 50 and then make the system back and turn using tacho counters. Furthermore the system have a problem of detecting small object directly in front of it( ei. a leg of chair) because such objects are so small that they does not provide enough shade for the light sensor to detect and is slim enough to be placed between the US sensors field of Vision.       



References:


tirsdag den 11. marts 2014

Date: 11/03-14
Duration of activity: 8 hrs
Group members participating: Alexander Rasmussen 20103865 Søren Ditlev 20116323


Lesson 5

Goal:

To make a self balancing system using the color sensor and a PID controller.

Plan:

We plan to use the model suggested by Phillippe Hurbain[1] to construct the physical system and the java code presented by Brian Bagnall[2] as base software.
In order to make the system balance, it was advised to implement a way of being able to tweak the system while running. Therefore we plan to set up a bluetooth connection between a PC and the system. In order to do so we will install the PCcarController.java[3] on a PC and BTcontrolledCar.java[4] on the system.  We will thereby be able to tweak the PID controller using a GUI on the PC and adjust the values on the system to match the unique condition of each run.       
Last lesson[5] we found out that the colour sensor is a more precise sensor, therefore we have made the decision to use the color sensor instead of the light sensor, which means that in the example code we have replaced the light sensor readings with the colour sensors normalized light values.

Picture the of the system

Results:

To implement the bluetooth connection, we used the BTcontrolledCar.java and modified it to read the values from the PCcarController.java and change them in the Sejway.java class. The Sejway.java class was modified with get and setter methods for all the constants.

In the test we were able to get the robot standing still by correcting the offset to a point where it almost were able to keep its balance, after that we tweaked the pid values.
We ended up getting the robot to stand still with little oscillations, but remaining on the same spot. We tried to push it a little which resulted in the robot driving off, and not being able to correct itself to a stand still without help, but if it was forced back by pushing it the opposite direction, we were able to get it back to a standstill.  

Pid Values table

KP
35
KI
7
KD
40



A video of the robot in action can be seen here[7]:

Conclusion:


We found that by changing the wheels to a larger size we gave the system more time to react, and thereby made it more stabil. Furthermore it was evident that the color sensor was very sensible therefore very small changes in the environment, forintance light and surface, will affect the system. Therefore it is very important to keep the environment as steady as possible so that you do not disturb the system.   

References:

[1] http://www.philohome.com/nxtway/nxtway.htm
[2] http://variantpress.com/books/maximum-lego-nxt/
[3] http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson5.dir/PCcarController.java
[4] http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson5.dir/BTcontrolledCar.java
[5] http://surdejspianisterne.blogspot.dk/

[6] https://www.youtube.com/watch?v=tuuO2egOp1w&feature=youtu.be

tirsdag den 4. marts 2014

Date: 28/02-2014 
Duration of activity: 5 hrs and 30 min
Group members participating: Alexander Rasmussen and Søren Ditlev

Lesson 4

Black White Detection

Goal:

Make a system that is able to distinguish between black and white

Plan:

Write a program that uses the BlackWhiteSensor.java class and the light sensor to detect the reflection level of black and white surfaces  
      
White Surface
Black surface
**
                                                                                                                                                                                                         
Conclusion:
The system is able to detect the difference between black and white and is responding rapidly.

Line Follower with Calibration

Goal:
To make a system that can follow a line in a black and white environment

Plan:

Expand the Black and White detection system with LineFollowerCal.java and  Car.java  classes  

Conclusion:

The car was able to follow a black line in a white environment.


ThreeColorSensor with Calibration

Goal:

Make a system that can distinguish between three colors: black, green and white

Plan:

Modify the BlackWhiteSensor.java class to calibrate for black and green, green and white. Thus making three different intervals.

Results:

To calibrate the sensor to recognise green we modified the BlackWhiteSensor.java to instead of having 1 threshold value, to have 2. By doing this it was possible to distinguish the different colors with black being below black green Threshold white being over green white threshold and green being in between.


Code from modified sensor class:
public boolean black() {
      return (ls.readValue() < blackGreenThreshold);
  }
  
  public boolean white() {
  return (ls.readValue() > greenWhiteThreshold);
  }
  
  public boolean green() {
return (ls.readValue() > blackGreenThreshold && ls.readValue() < greenWhiteThreshold);
}


Green surface
*


Conclusion:

The system is able to distinguish between the three colors black, green and white. However if the sensor is placed directly over a black/white transition it might return green.

Line Follower that stops in a Goal Zone

Goal:

Make a system that can follow a line and in black/white environment and stop once the color green is detected  

Plan:

Combine the threeColorSensor with LineFollowerCal.java and  Car.java classes.  

Results:

To stop the car we added an if statement checking for green color and stopping if true. Because the sesnor relies on a light value the transition between the black and white can give a reading which reads green, we managed to prevent it from stopping in these cases by implementing a counter, so that it had to be green in 10 ms before it took action.


Code from modified linefollower:
while (! Button.ESCAPE.isDown())
    {
    LCD.drawInt(sensor.light(),4,10,2);
    LCD.refresh();
    
    if(sensor.green()){
    count++;
    if(count > 100){
    Car.stop();
    LCD.drawString("Green!", 0, 0);
    count = 0;
    }
    }
    else if ( sensor.black() ){
       LCD.drawString("Black!", 0, 0);
     Car.forward(power, 0);
     count = 0;
    }else{
    LCD.drawString("white!", 0, 0);
    Car.forward(0, power);
    count = 0;
    }
    Thread.sleep(1);
    }

Conclusion:

The system works, but sometimes it stops because it detects green in a black/white transition. To combat this we added a counter that register the same value 10 times. This solved that transition problem, but had the side effect that the system did not always follow the line correctly.  

PID Line Follower

Goal:

Make a linefollower system that follow a line smoothly and runs as fast a possible.

Plan:

Implement a PID controller to control the system and tune it using a PID guide[1]

Results:

Video: [3]
Values:


Parameters
Values
TP
90
KP
7
Ki
0.3f
KD
107



Conclusion:

By using the PID guide we were able to calculate the k values, once the k values were found we gradually turned up the TP value(motor power) in order to make the system drive as fast as possible without losing track of the line.
The system follows a line fast and smoothly, but if the system loses track of the line completely it just drive around in cycles. This is because the system adds the errors from the previous measurements in order to correct for futures reading, if multiple errors is measured in a row the collected sum of errors makes the algorithm skewed. The system is therefore unable to distinguish between balck and white.

Color Sensor

Goal:

Use the color sensor to make a lineFolllower system that functions in a black/white environment and stops in a green field.

Plan:

Results:

To implement the lineFollower using the color sensor, we used the same type of algorithm as in the lineFollower using the light sensor. Instead of using light values and distinguish the colors by calibrating threshold values, we used the color sensors function getColor.


while (! Button.ESCAPE.isDown())
    {
    Inner:
    switch (cs.getColorID()){
    case Color.BLACK:
LCD.drawString(""+cs.getColorID(), 0, 0);
Car.forward(power, 0);
break Inner;
case Color.WHITE:
LCD.drawString(""+cs.getColorID(), 0, 0);
Car.forward(0, power);
break Inner;
case Color.GREEN:
LCD.drawString(""+cs.getColorID(), 0, 0);
Car.stop();
break Inner;
    }
    }

Conclusion:

Unlike a light sensor, the color sensor does not make the mistake of detecting green when it is placed directly a black/white transitions. Therefor it was not necessary to make corrections like in the previous lineFfollowers, where multiple readings had to be detected as same color so that the system would not stop on back/white transitions.


References: