![]() |
Why isn't this working?
Code:
#include "WPILib.h"- I have a servo (which works properly, and is wired properly). - I want to flick a switch which is declared as a DigitalInput, constructed as DigitalInput 12. - When I flick this switch I want the servo to move to either full left or full right (depending on its current position. I want it to move opposite of its current position). - I want to account for objects obstructing the path of this servo. If the servo hasn't reached the position I told it to go to, and it hasn't moved more than 18 degrees in 500 milliseconds, then we can assume there is an object obstructing it, so I want to stop the servo from moving. I have multiple problems with this program. One problem is that in case 0, state++ never gets executed, and I can't figure out why. Assume that cout is working properly (because I have the cRIO properly connected to another laptop via serial cable). However, I am not sure whether cout messes with anything. Also, the code just straight up doesn't work. Before, I had managed to jump into case 1 (I kinda had to force it) and even so, my code wasn't working. I would be most grateful if someone could give me a few pointers on what I'm doing wrong, or even if I am attacking this from the right angle. |
Re: Why isn't this working?
Can you put more debug in there? Debug is your friend.
Also, does case 0 run once or never? From a quick examination of the code it looks like "last_switch_state = servoswitch.Get();" right before your while loop would result in "(servoswitch.Get() != last_switch_state)" returning true always, especially if no or very little time elapses between the two statements. |
| All times are GMT -5. The time now is 03:57. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi