View Single Post
  #3   Spotlight this post!  
Unread 02-02-2012, 08:32
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Autonomous with Ultrasonic sensor doesnt work!!

Quote:
Originally Posted by cilginbilgin View Post
After we put set averagıng and set sample inside the while loop the code seems to be working however there is a small problem. Let x inches be the distance I want the robot to stop and to extend the piston. When I set robots position to some distance which is greater than x inches and run the code the robot stops and extends the piston at x-y inches. If I set robots position to x inches from the wall and run the code the robot doesnt move and extends the piston as I want. Is there anything I can do to avoid this problem or should I just tell the robot to stop at x+y inches to make it stop at x inches?
The robot is moving. Once you detect that you are at x and tell the drive motors to stop, the robot coasts to a halt y inches further on. You could set the motor speed controllers to "brake" mode so the robot stops immediately, though that can make driving it a little less easy.

Or you could control the motor speed based on how far away you are, slowing down as you approach the target distance so you don't overshoot. For example, set the motor output to a value proportional to the error between the desired location and the measured location. If your proportionality constant is too high, you will overshoot (and then perhaps back up to the target, depending on the details of the code). If the constant is too low, you will stop too soon, so you can use another term that increases motor speed based on how long the position error is present. You can also reduce power if you're approaching the target too quickly. Put it all together and you have PID control -- search the forums for more discussion and explanation.
Reply With Quote