MotorEncoder:
Looking at a downloaded code, we realized although the motor is set to move forward a second and backwards a second at the same speed, the position of the motor never returns back to 0. Jennifer and I concluded that the motors are old and the power provided is different every time despite the constant speed integer. This also helps explain why our SciBorg does not move in a straight line.The first screenshot is what to include from the Arduino Library for this specific task.
The second screenshot includes a block of commented out code which is what we used to get the position of the motor to be read and have it printed out in the serial monitor.
We then proceeded to calculate the position, starting from 0, the motors would be at after 10 feet. We calculated the circumference of the wheels and multiplied that by 10 feet. We calculated the number of revolutions needed for our SciBorg in order to reach 10 feet, which was approximately 18 revolutions. Next we used the test code above to see what the position of the motors were at after 18 revolutions, which was approximately 12643. We used that number to keep our motors running in the loop - if (motor1<=12643)
Our Sciborg stopped less than an inch from the 10 feet mark.
Touch_Switch_Sciborg_Front:
In front of the SciBorg is a button that when pressed and coded correctly can stop the motors connected to the robot. Before coding the touch switch to control the motors, Jenny and I first made sure when the switch was pressed, the serial monitor would say "button is pressed" or "button is not pressed" when the switch was untouched.Then we coded the motors to stop when the switch was pressed and go if the switch was not pressed. We had some fun with it and even coded the SciBorg to move backwards and turn around when it hit something in its path. After turning around, the loop repeats.
LightSensorNXT:
Initially, we coded a light sensor to sense the amount of light in front of it and for that value to be printed in the serial monitor.In the serial monitor, two values were being read and printed - ls.value and ls.scaledValue. By holding the light sensor above a board with a darker color and a white color, we looked at the scaled values in the serial monitor and concluded that a value of 90-92 was when the light sensor was hovering above a white color. A value of 10-11 was for a darker color.
We then turned on the LED light for the light sensor but that only hurt the sensitivity of the readings which only produced an one number difference between a dark and light color.
Lastly, by placing the light sensor about two centimeters above the surface, we received the best results. We attached the light sensor to the side of our SciBorg and coded our Sciborg to move when sensing a dark color: if (ls.scaledValue() >= 70), and stop when sensing a white color. We used the value 70 in our code for leeway.
Ultrasonic_sensor:
Connected to the front of our SciBorg also has an ultrasonic sensor. An ultrasonic sensor senses how far or close something is in front of it. After connecting the ultrasonic sensor to our breadboard and Brickstonic Lego NXT, we tested the sensor by moving a Delrin sheet back and forth in front of the sensor. In the serial monitor, values of how far the Delrin sheet was relative to the sensor was read and printed out.
Using that knowledge, we coded the ultrasonic sensor to stop the motors once something a certain distance in front of it was sensed.
Straight-Bang-Bang:
Bang-bang control is a feedback controller with two options - off and on. The SciBorg and its motors are far from perfect. Although coded at the same speed, the motors do not run at the same speed with the same power. Using bang-bang control, Jenny and I coded our SciBorg to move in a straight line. By combining the MotorEncoder task, if the position of one wheel was less than another, the speed of both motors would be different. This allows the SciBorg to make slight left or right turns and adjust itself again to move in a straight line.
Line-Following-Bang-Bang:
Using partial bang-bang control learned in Straight-Bang-Bang, we adapted bang-bang control to have our SciBorg follow a white path. We coded the SciBorg to follow the edge of the tape rather than the center of the tape as it was easier for the SciBorg to readjust and because the tape was not clean white.
If the light sensor read values between 70 and 75, our Sciborg was centered on the edge of the line and he SciBorg would move forward. If the light sensor read values over 75 - sensor more over the white tape - it would readjust by slightly turning left. If the light sensor read values under 70 - sensor more over the dark surface - it would readjust by slightly turning right. Through that whole process, the SciBorg would readjust the position every 5 milliseconds for the most up-to-date reading to keep the SciBorg from wandering from the line.
Object-Following-Bang-Bang:
Continuing with bang-bang control, Jenny and I coded the SciBorg to follow an object - delrin sheet. We coded the Sciborg to move at a fast pace, medium pace, and stop depending on how far the SciBorg was from the delrin sheet.
Our SciBorg tends to veer off to the right so we included code so the right motor goes faster than the left motor. This way, our SciBorg would move in a straighter line.
Behind our SciBorg is a SciBorg of another team.
Reflections:
I had fun learning about the three different sensors and the MotorEncoder. Instead of coding the SciBorg to move a certain distance forward, move backwards for a certain amount of time, or turn right 90 degrees, different sensors with different functions could control motors for us.
Bang-bang control itself is not too difficult, but when using bang-bang to have our SciBorg follow a line, many challenges surfaced. Our first obstacle was figuring out that having our SciBorg follow the edge of the tape would be easier. Our next obstacles the actual coding.
Although coding can be frustrating, the end result is beneficial.
Nice reflection at the end there! Great working with you!
ReplyDelete