|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Here is the code I have written for autonomous. I want the robot to stop and the piston to extend when the ultrasonic sensor reads 40 inches. But it doesnt happen. We have tested the ultrasonic sensor and tuned it. We are sure that the distance ultrasonic sensor reads is true.
Can anyone tell me if the code is correct or wrong? Thanks in advance. http://imageshack.us/photo/my-images...tonomous2.png/ http://imageshack.us/photo/my-images...utonomous.png/ |
|
#2
|
||||||
|
||||||
|
Re: Autonomous with Ultrasonic sensor doesnt work!!
Quote:
Remove the "while loop" around the motors, and place the while loop around all of your code. That should fix the problem. |
|
#3
|
||||
|
||||
|
Re: Autonomous with Ultrasonic sensor doesnt work!!
We do a very similar routine, but with the vision system instead of the ultrasonic sensor. See the attached vi for an example.
The Target info would be your value coming from the ultrasonic sensor. The idea is to look at current value and compare to some setpoint. If you are above a setpoint, move one way. If you are below setpoint, move the other way and lastly if you are within some acceptable window, do nothing because you are in place. In the attached vi, the setpoint is zero, and the acceptable window is between .25 and -.25. Reply back if more questions. |
|
#4
|
|||
|
|||
|
Re: Autonomous with Ultrasonic sensor doesnt work!!
[/quote]
Quote:
Thanks in advance. Last edited by cilginbilgin : 01-02-2012 at 14:48. |
|
#5
|
||||||
|
||||||
|
Re: Autonomous with Ultrasonic sensor doesnt work!!
Quote:
Please see the post from MotorHead above. You autonomous code should look similar to his when your finished. |
|
#6
|
|||
|
|||
|
Re: Autonomous with Ultrasonic sensor doesnt work!!
Quote:
http://www.mypicx.com/02012012/Autonomous/ and I think my autonomous code is pretty same with MotorHead's. |
|
#7
|
||||||
|
||||||
|
Re: Autonomous with Ultrasonic sensor doesnt work!!
Your logic seems correct. However, you may not be getting anything from the ultrasonic sensor. See the attached image of the ultrasound example (the example can be found in (LabviewInstallFolder)/examples\FRC\Analog\EZ1 MB1010 Sonar Analog).
The example sets the averaging, sets sample rate, and then gets the voltage within the while loop. We tried moving the "set averaging" and "set sample rate" to Begin.vi, but the "analog get voltage" stopped working when we did that. Perhaps you need to add the "set averaging" and "set sample rate" into your while loop. Can you describe the following: 1) How exactly is your robot behaving when you run autonomous? 2) When you run autonomous, what are you seeing from your "Distance" indicator? |
|
#8
|
||||
|
||||
|
Re: Autonomous with Ultrasonic sensor doesnt work!!
I haven't used the Ultrasonic yet, so I can't comment on its setup. I do have a problem with your logic. The way you currently are configured is: If distance >= to 40 then back up with y =-.4, If distance < 40, stop and activate solenoid.
The problem with this is you do not have a deadzone in which to stop. Your arrangement can cause the robot to excessively hunt about the setpoint of 40. Look again at the vi I posted. There is a nested case structure to test if you are above or below the setpoint or if you are within the acceptable deadzone, in which case, do nothing. |
|
#9
|
|||
|
|||
|
Re: Autonomous with Ultrasonic sensor doesnt work!!
Quote:
Quote:
Thank you guys for your helps!!!!! ![]() |
|
#10
|
|||||
|
|||||
|
Re: Autonomous with Ultrasonic sensor doesnt work!!
Quote:
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|