FIRST Robotics Competition Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

make an autonomous action with a button

how can I make the robot move with a button to back one meter and activate engines in the teleop

0 Kudos
Message 1 of 5
(3,172 Views)

Davidrj28,

 

It seems you're asking this question related to the FIRST Robotics Competition. I recommend you post your questions in that forum in the future: FIRST Robotics Competition Discussion 

 

Regarding your question: it will depend on if you are using the Command and Control Framework or not. For the former, your subsystem should be able to handle that request from a call. If you are not using Command and Control, then you can program a state machine. You can learn more about these here: 

 

Good luck to your team!

All the best,

0 Kudos
Message 2 of 5
(3,151 Views)

Adding on to Oscar, I'd suggest taking a look at using Periodic tasks if you aren't using Command and Control.  You're less likely to lockup your Teleop this way (Most programmers lock teleop until the autonomous tasks completes)

0 Kudos
Message 3 of 5
(3,035 Views)

I'd suggest the following (There are lots of different ways):

-  Put the code that writes the actions to the motors in periodic tasks.  In other words, read the a "speed demand" global variable, and turn this into a motor output.  This way teleop and auto don't have to have duplicate code.

- Create a generic "position control" vi.  See chap 7 (I think) of the secret book that was referenced above.

- When the button is pressed (edge detection) initialize what is needed for position control (get the current left and right drive distances, and calculate the final desired distance).

- While the button is pressed -- call the position control vi.  This will calculate a drive speed demand.  Write this to the global variables for periodic tasks to drive the drive motors.

- (The same thing can be done with the gyro instead of the encoders, to spin the robot 90 or 180 degrees or whatever...)

Jim

0 Kudos
Message 4 of 5
(3,030 Views)

Can you post back or mark an accepted answer if you got this working?

 

If you're still struggling, take a look at

https://www.frclabviewtutorials.com/tutorials/producer-consumer/ for sending the "command"

 

(if a flat sequence is not sufficient, like if you need the ability to hit cancel, or repeat certain steps, replace that part with a state machine)

0 Kudos
Message 5 of 5
(2,940 Views)