Robot Update
The robot has ben updated again and this time it is has been greatly approved.
The bot now has wide turns. This was a hard challenge to overcome because the common answer to wide turns as opposed to spinning is just to make one wheel spin faster than the other and the robot will gradually turn instead of spinning all at once. The problem with this solution is that the servos that we are working with only spin at one speed. This means that both wheels can only be in 3 modes: forwards, stopped, and backwards. The way we overcame this challenge was to spin on wheel at full speed and to alternate the other wheel between forwards and off. This makes it so that the robot will jerkily move forward and turn at the same time making a circle that is about 1 foot in diameter. But we didn't stop there. Like with the normal turns, where we made it able to turn a certain amount of degrees, we made a precision wide turn function. This function makes you input a degree for the turn and it will make a wide turn that many degrees. If I put in 180 then it would turn all the way around, but it wouldn't spin, it would slowly turn in a wide circle.
Wide turns were the main thing that we added but thats not where we ended. We also rebuilt the bot using cleaner wires so that it doesn't look like so much of a jumbled mess anymore. We also added support for a distance sensor on the front of the robot. What this does is when you ask it will return how far the robot is from whatever is directly in front of it. In the future we will be able to easily make a code where the robot will turn around once it gets too close to something or create an AI that can guide it around objects. Like I said we have already implemented most of the code for the distance sensor but haven't really "turned it on" yet.
Code Snippets
The function that returns a distance
//returns a distance
int distanceFunction(){
int distance = 0;
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
distance = pulseIn(echoPin,HIGH);
Serial.println(distance);
return(distance);
}
The part of the wide turn function that alternates the servo mode
if(counter<counterFinal){
if(evenCounter == 1){
left.write(180);
right.write(90);
}
else{
left.write(180);
right.write(0);
}
}
Future
In the future this robot will hopefully be a lot smarter and be able to navigate around objects or avoid certain things. We continue to use more and more different types of robotic parts that will broaden our knowledge about the subject. Implementing a distance sensor will teach me and the entire class more about how different parts work and is sure to help us in our futures of electronics.
No comments:
Post a Comment