Log in

View Full Version : Encoder in Autonomous


Dolphin07
30-01-2015, 18:55
We are trying to code a motor in autonomous using an encoder. We aren't getting any feedback from the encoder in autonomous, but we are in teleop. Any suggestions?

Mark McLeod
30-01-2015, 19:04
Is this the code you dropped into Autonomous?
Did you add a loop (with a Wait please)? Otherwise it gets called a single time, then never again in Autonomous.
Without an Autonomous loop your Arm will just keep running forever.

Teleop itself gets called every 20ms (optimally), so this code in Teleop gets called over and over again.
Autonomous is called only once, and you have to supply your own loops to keep it going and checking.


I'd also call Config Timer once in Begin, rather than every time you get an encoder value.

Dolphin07
11-02-2015, 19:37
Thank you! We ended up putting a while loop in and it works! Another problem that we are now having is that autonomous mode only runs when timed tasks is disabled. Do you have any ideas of why this is happening or a way to fix it?

aeastet
12-02-2015, 12:41
You are probably talking to two things at the same time. Look for motor control or other things that require in input to go or react. If you post both we can take a look and help.

aeastet
12-02-2015, 12:45
If you do not want everyone to see your code you can email me and I can look through it and give some help. Just message me if you want so help.

Dolphin07
12-02-2015, 14:21
Here are pictures of the timed tasks code and the beginning of autonomous. In auto, we're reading buttons from the dashboard to select which version of the code to run, and positions from the driver station as well.
Thank you.

Mark McLeod
12-02-2015, 14:36
By setting the Arm motor in two places at the same time the latest set wins.
That would be Periodic (Timed) Tasks because it reSets the motor every 10ms.

You have to set it in only one place.
Generally, I'd say have Autonomous set a Global variable that Timed Tasks reads and acts on.

Dolphin07
12-02-2015, 14:41
How would you suggest doing that?

aeastet
12-02-2015, 15:16
You are starting things in multiple places. If you start the encoder in the periodic tasks then you do not need to do it in the auto loop too. You just need to get the value from the to the Autonomous code. That can be done with a global variable.

18308

Dolphin07
12-02-2015, 22:01
We put the code in teleop like you suggested and it worked wonderfully! Thanks for the help!