ROBOTC.net forumshttp://www.robotc.net/forums/ 90 degree precise turnhttp://www.robotc.net/forums/viewtopic.php?f=11&t=3172 Page 1 of 1

 Author: TomH [ Thu Mar 31, 2011 7:22 am ] Post subject: 90 degree precise turn I am using encoders on my robot and am trying to get the robot to make two 90 degree precision turns so I can turn and go back to the exact same spot over and over again. So far I am close but not prefect. To be close My encoder reads <4, which I think is wrong, and to fine tune I've changed power to the wheels. The encoders are working fine in a straight line and I can see them on debug.As you can tell I am new to this.

 Author: magicode [ Thu Mar 31, 2011 10:19 am ] Post subject: Re: 90 degree precise turn If you want help, you could post your code and see if someone can help you make it better. But using encoders, you will never be able to turn exactly 90 degrees. If one motor is running a bit faster then the other, or a wheel slips slightly, your center of turning will be off, and your encoder values won't be as useful. Think about it this way: If your center of turning is exactly between the encoders, then you have to keep turning until both encoder values have turned through the same absolute value. So if your encoder values are zero at the start, you have to keep turning until the left encoder is at, say 50, and your right encoder is at -50. But if your center of turning changes, the robot will not turn 90 degrees even if you reach the same encoder values. I hope this helped. I'm sorry if I didn't explain very clearly, I'm sick and my brain is slightly malfunctioning.

 Author: TomH [ Thu Mar 31, 2011 5:50 pm ] Post subject: Re: 90 degree precise turn thanks here id the part of the code I am working on. The robot is to move straight, then pick up a can, then back up, then turn 90 degrees to the left, go forward set the can down, back up, turn right, and go get another can.As I say it works except the trouble with the turns. Which does no place me in the correct unloading or loading spot each time. Which is greatly needed. Any help suggestions etc. are warmly welcomedCode follows SensorValue[RightEncoder] = 0; SensorValue[LeftEncoder] = 0; while(SensorValue[LeftEncoder] < 900) { movestraight(); } motor[port3] = 0; //motor stop motor[port2] = 0; //motor stop wait1Msec(1000); //pause 2 second after moving forward motor[port4] = closegripper; //close gripper around can wait1Msec(200); motor[port4] = 0; // motor stop wait1Msec(1000); // pause 2 seconds after closing gripper motor[port1] = raisearm; // raise arm and pick up can wait1Msec(1000); motor[port1] = 0; // arm stop wait1Msec(1500); // stop arm SensorValue[RightEncoder] = 0; SensorValue[LeftEncoder] = 0; while(SensorValue[LeftEncoder] >-900) { backup(); } motor[port3] = 0; //motor stop motor[port2] = 0; //motor stop wait1Msec(3000); SensorValue[RightEncoder] = 0; SensorValue[LeftEncoder] = 0; // while(SensorValue[LeftEncoder] >-4) while(SensorValue[RightEncoder]<4) { motor[port3] = -60; //motor stop motor[port2] = 45; } wait1Msec(1500); motor[port3] = 0; //motor stop motor[port2] = 0; //motor stop SensorValue[RightEncoder] = 0; SensorValue[LeftEncoder] = 0; while(SensorValue[LeftEncoder] < 900) { movestraight(); } motor[port3] = 0; //motor stop motor[port2] = 0; //motor stop wait1Msec(1000); //pause 2 second after moving forward motor[port1] = lowerarm; // raise arm and pick up can wait1Msec(500); motor[port1] = 0; // arm stop wait1Msec(500); // stop arm motor[port4] = opengripper; //close gripper around can wait1Msec(1000); motor[port4] = 0; // motor stop SensorValue[RightEncoder] = 0; SensorValue[LeftEncoder] = 0; while(SensorValue[LeftEncoder] >-600) { backup(); } wait1Msec(1000); wait1Msec(500); // pause reverse SensorValue[RightEncoder] = 0; SensorValue[LeftEncoder] = 0; while(SensorValue[LeftEncoder] <4) { motor[port3] = 60; //turn motor[port2] = -45; //turn } wait1Msec(1500); motor[port3] = 0; //motor stop motor[port2] = 0; //motor stop}}

 Author: jbflot [ Thu Mar 31, 2011 6:01 pm ] Post subject: Re: 90 degree precise turn Like Magicode said, it's very difficult to achieve perfect 90-degree turns every time, even using the encoders. The rubber wheels in the VEX system lend themselves to the occasional jumps or slips while turning on a point. Have you considered incorporating other sensors to help achieve your goal? For example, you could use two ultrasonic range finders (one on the front, and one on the right) to see if you were the correct distance from two walls.

 Author: Aswin [ Thu Mar 31, 2011 6:27 pm ] Post subject: Re: 90 degree precise turn Like the others said, you will never get a precise turn of 90 degress all the time. However there is still room for improvement. Two things can be improved, the first is easy. The second more difficult. Implement in order.1. After the while loops that make sure the robot travels or turns there is often a wait statement. The motors will still run when exiting the while loop and executing the wait command. Only after the wait you halt the motors. This will make the motors overshoot the target. So you should halt your motors right after the while loop.2. Even if you stop the motors right after the while loop they still need to halt. While coming to stand still the motors are overshooting. If you want precise turns you should make sure that the motors don't overshoot at all. For this the motors should start slowing down when reaching he target position, so that they can stop right on spot. The easy way to do this is to use the nMotorTarget statement. (i'm not sure if they are available for the VEx, but you can check the manual). The more complex way to do it is to use a feedback controller. A feedback controler is something that uses the distance to the target to adjust the motor speed. Most commonly feed back used is a PID controller. Search for it here and in wikipedia to get an idea how it works and how it can be programmed.

 Author: TomH [ Thu Mar 31, 2011 8:36 pm ] Post subject: Re: 90 degree precise turn I like the range finder idea to follow the wall. How would I set it up to stay a certain distance from the wall? I can fix the motor stops easy enough and I spent more time and right now I am soooo close to having it routine turn a 90 degree. But yes its not perfectly doing it. My project is to feed a can crusher that we made. So it is to go forward until it see the can. pick up the can then back up , turn the 90 degrees and go forward until it gets to the can crusher. Load the crusher and then return for another can. While the can crusher does it thing. But if I cannot get it to make the turn and end up in the same place repeatedly I have to come up with a new routine.Another problem I seem to have is the robot will jump a little at times or just stop in the middle of a move. I am thinking this maybe a problem with how I have the waits set up so maybe by cleaning those up that will be eliminated.Thanks for your suggestions

 Author: magicode [ Thu Mar 31, 2011 10:37 pm ] Post subject: Re: 90 degree precise turn if you are parallel or perpendicular to a wall when you are at the can crusher, you can use two ultrasonic rangefinders to align yourself with the wall. if you have one rangefinder on the back-left of your robot, and one on the back-right, you can use the difference between them to align yourself parallel to the wall. I can provide sample code if you need it. I don't think that this is what jbflot was saying, but I may have misinterpreted his comment.

 Author: TomH [ Sat Apr 02, 2011 9:00 pm ] Post subject: Re: 90 degree precise turn I am going to try installing a three line followers. So far I am not impressed with this Vex controller. It jumps around at times and I do not know why. I get it running fine then all of a sudden it just stops like it gets stuck. Then it will start again. Other times it just jumps. I took it to show some one and it ran fine, but then it starting screwing up again. I do not understand why that is. Now I got home and am trying to down line the code to try the line follower and It will not send it. So I am charging the battery. I hope that is it. Sorry for the negative attitude but I just spend well over \$600 on all this stuff and it runs like junk. I will surly not recommend VEX to any one at this point!

 Author: mightor [ Sun Apr 03, 2011 6:18 am ] Post subject: Re: 90 degree precise turn The trouble with microcontrollers is that they do exactly what you tell them to not what you want them to.- Xander

 Author: TomH [ Sun Apr 03, 2011 9:19 am ] Post subject: Re: 90 degree precise turn Trouble with this one is I can't tell it any thing because its locked up and I cannot send any program to it. Plus when it was working it would run the program perfectly on thre or four cycles and then start acting up. That is not programmed as far as I can see. But I've been wrong before. I just need advise on how to get this unlocked and why did this happen1Thanks for any help

 Author: mightor [ Sun Apr 03, 2011 9:29 am ] Post subject: Re: 90 degree precise turn Please attach the file so we can see.- Xander

 Author: TomH [ Sun Apr 03, 2011 11:08 am ] Post subject: Re: 90 degree precise turn Here is what is in it right now. I cannot run it, nor reload a different program. All I get is "cannot communicate with Vex". I have recharged the battery, rebooted the computer, reloaded the USB drive. The Robot was working fine, except for its occassinally jump or stopping in the middle of a While loop for no reason I can figure out. After I loaded the below program,which I have run many times before it locked up. It shows the battery light on and the program status light is on. but it will not do any thing. once in a while it will move a motor for a second. But that like 30 minutes apart.task main(){ bMotorFlippedMode[port2] = true; //Port 2 Motor Direction Flipped bIfiAutonomousMode = false; //Activates Remote Control Mode while (1 == 1) //Creates and infinite loop { motor[port2] = vexRT(Ch2)/2; //The right motor is set to equal half the value transmitted by Ch2 (y-axis of the right joystick) motor[port3] = vexRT(Ch3)/2; //The left motor is set to equal half the value transmitted by Ch3 (y-axis of the left joystick) if(vexRT[Ch5] == 127) { motor[port1] = 31; // The arm is set up with ch5 push button } if (vexRT[Ch5] == -127) { motor[port1] = -31; } if(vexRT[Ch5] == 0) { motor[port1] = 0; } if(vexRT[Ch6] == 127) { motor[port4] =31; // The gripper is set up with ch6 push button } if(vexRT[Ch6] == -127) { motor[port4] = -31; } if(vexRT[Ch6] == 0) { motor[port4] = 0; }{} }}

 Author: mightor [ Sun Apr 03, 2011 11:15 am ] Post subject: Re: 90 degree precise turn Where are your pragmas? I asked you to -attach- the file to the post so I can see the whole thing.- Xander

Author:  TomH [ Sun Apr 03, 2011 7:53 pm ]
Post subject:  Re: 90 degree precise turn

the first one is the one that is in the controller right now. The other two are the ones I am working on