Tuesday, March 11, 2014

SciBorg Day 3-4

Fixed Distance with Proportional Control
In the previous fixed distance mechanism (Day 2), the SciBorg was allowed to go straight at a constant speed for 10ft until it came to a sudden stop. For this assignment, we implemented proportional control that could vary the power of the motors according to the distance that the SciBorg has to travel. 

  First, we determined the number of count a it takes for the SciBorg to go ten feet. With some measurements and calculations, we determined that count a must be 3100. 
We started out with a forever loop and set up a variable n that is equal to the total number of count a the car needs to go (3100) minus count a. This is our error value, and we set the power to equal the error value because if we multiplied it by a number greater than 1, the power was set at maximum for most of the 10 ft. 
Then, we set up an if-then statement that gives greater power to motor b is count a is greater than count b and greater power to motor a if count a is not greater than count b. This was an attempt to make our car go straighter. 
With this code, we were able to make our SciBorg go faster at the beginning and gradually slow down and stop at exactly 10 ft. 



Compared to the previous fixed distance control, the proportional fixed distance control allowed the car to gradually slow down, giving it a longer time to stop. Even though it is less noticeable in SciBorgs, if we consider a real car, this would cause less damage to the wheels and safer for the person inside the car. 



Conga Line Bang-Bang Control
The mechanism behind the Conga line bang-bang control is pretty simple. We let the SciBorg go forward when the ultrasonic sensor reads a number greater than 20, and stop when it is less than 20 (when there is a piece of delrin close to the front of the car). 


We were successful at implementing this control and the SciBorg moved straight at constant speed until it recognized a piece of delrin in front of it. Just like other bang-bang controls, it does not have any subtle controls on speed, which could possibly make the motions a little jerky. However, the code is very simple and it incorporates the feedback mechanism (ultrasonic sensor).


Conga Line Proportional Control
We decided to implement proportional control in both forward and backward directions. 
When the SciBorg senses an object very close to the ultrasonic sensor (with a reading less than 15), we wanted to make it go backwards and vice versa. However, instead of simply going forwards and backwards, we wanted the SciBorg to vary its speed according to how near or far the object is. For example, if there is an object extremely close to the sensor (say sensor reading=2), it would move backwards faster than when the object is not as close (sensor reading=10). Similarly, the SciBorg would move forward faster if the object is very far away compared to when it is somewhat far away.

First, we set the 'turning point' sensor reading to be 15. If the reading is less than 15, the car would back up and if the reading is greater than 15, the car would go forward. 
     
 When sensor reading is less than 15:
We wanted the SciBorg to go backwards faster is the reading is smaller. Therefore, we set a variable n that is equal to 14-(sensor reading) (This is not shown in the picture above because it is hidden behind the arrows). Then we set the power to nx10 (the multiplier value was determined through trial and error). This way, when the sensor reading is very low, the n value would be high and the power would be higher. Then we used the 'that way-motor on' commands to turn on the motor in the reverse direction. 

When the sensor reading is greater than 15:
In this case, we want the car to go forward faster when the sensor reading is greater (when the object is further away). Therefore, we simply set the power so that it is equal to the sensor reading times 4 (again, the multiplier value was determined through experimentation). Then we turned on the motor so that the car goes forward. 
This worked out very well, and it allowed the SciBorg to smoothly speed up or slow down depending on the location of the object (or a piece of wood in this case).
Our SciBorg was also successful at following other SciBorgs, although it became a little chaotic when there were multiple SciBorgs going in different directions.

Compared to the bang-bang conga line, the proportional conga line control gave us more control over the movement/speed of our SciBorg and I feel like it made use of the feedback mechanism more efficiently.


Proportional Control Line Following

Our initial idea for the proportional line following was to have our SciBorg follow the edge of the tape and when it senses that it is off the edge, have it turn in the correct direction with the amount of turn being proportional to the difference in the sensor readings. In other words, if the SciBorg is only slightly off from the edge reading, it would only turn slowly until it finds the edge again and vice versa.  

 The NXT sensor reading for the edge of the tape was 460 and we wanted the SciBorg to follow the right edge so we made a code that allowed the SciBorg to turn right when the sensor reading was less than 460 (meaning that the sensor is on the tape) and turn left when the sensor was reading a value that is greater than 460 (meaning that the sensor is on the melamine).

However, when the sensor is only slightly off the edge (making the difference small), the power was so low that the SciBorg refused to move. 

As a solution to this problem, we utilized if-then-else statements (as shown below).  


 At the start of the code, we made an if-then-else statement that separates the two cases: sensor is on the tape, sensor is on the melamine. 

When the sensor reads a value greater than equal to 460:
Since the sensor is on the melamine, we need to make the car rotate counterclockwise. We first set a variable n that is simply the error value (sensor reading-460). Then, we made another if-then-else statement that accounts for the situations when the error value is low. When the error value is lower than 15, we simply set the power of motor a to 75 so that it would rotate left. When the error value is greater than 15, we set the power of motor a so that it equals the error value times 5. These values might seem arbitrary, but it was determined after multiple trials. 

When the sensor reads a value less than 460:
Since the sensor is on the tape, we need the car to rotate clockwise. The mechanism is pretty much the same as the previous one, with the exception of setting power on motor b instead of a. 

To our surprise, the proportional line following worked very well, and it was much less agonizing than getting the bang-bang line following to work.



 In general, using the proportional control required more programming but worked a whole lot better than bang-bang control. Although the benefits of proportional control might be less obvious when working with SciBorgs, there are many cases in real life where proportional control provides more efficiency and greater control. (If we imagine our biological systems to be bang-bang, it would actually be very difficult to maintain homeostasis). 



 


 

 






 
 

1 comment:

  1. Good job on all your codes! I especially liked your program for proportional fixed distance. It was very smart to include a part that alters the power of the motors to keep the car straight. My partner and I kept having issues with our car turning and not reaching the ten feet mark because even though it went ten feet it didn't go straight. We just ended up playing with the power values relative to each other to get the motors to have roughly the same actual power (not set power). This worked a little, but your idea is much better!

    ReplyDelete