Encoder in Autonomous

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?

code pic.JPG


code pic.JPG

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.

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?

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.

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.

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.







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.

How would you suggest doing that?

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.







We put the code in teleop like you suggested and it worked wonderfully! Thanks for the help!