FIRST Robotics Competition Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple sequential code using PID in Auton

Is there a simple way to create a sequence of steps in Auton which, for example, use PID to drive a fixed distance and then perform the next task, then drive again etc using the Flat Structure    I know I can do this with a state machine, but I am looking for a simplier way to accomplish the task that more clearly shows the entire sequence than a state machine's case statements which hide the sequence.  Thanks

PGR

0 Kudos
Message 1 of 4
(3,930 Views)

Hi prandall,

I would generally not recommend using sequence structures because of dataflow, you're unable to exit them gracefully, etc.

If you're not wanting to use a state machine, you could make each task into a SubVI and then wire them together on the block diagram.  Check out this video on SubVIs and dataflow (http://decibel.ni.com/content/docs/DOC-1694).

0 Kudos
Message 2 of 4
(2,610 Views)

You would only be able to do that in the Auto Independent mode.

There you could make the VI long as you like with the code going from left to right.

I would still use some type of state machine. You will be able to stay in any one state as long as you needed (until something is done)

You will then be able to move from one state to another based on input.

With a state machine it will be easier to edit code to add condition branching once you start testing your code on the robot

If you insist on a flat design then break the code into subVIs based on function and call them one at a time. Creating a block diagram of our program flow.

NOTE: You will have to feed the watchdog every 20ms and you could do that in a continuous running parallel loop inside the Auto Independent VI.

Omar
0 Kudos
Message 3 of 4
(2,610 Views)

This is basically what we did last year. We broke everything up into subVIs that had a while loop that terminated when it's condition was done. They were sequenced using the error wire.

autonomous.PNG

0 Kudos
Message 4 of 4
(2,610 Views)