Vcs c++

Hello. We were wondering if you are able to program macros in VCS C++. If so, how would you set them up in the program? Any help would be appreciated.

Macros as in predefined behaviors that you can invoke during the teleop (e.g. by pressing a dedicated button)? Sure, you can program that.
How to do that is a little more complicated and depends on the way you structure your teleop control loop and also on the breadth of the macro (how many susbystems does it affect, how do you expect the controls to behave while executing the macro and so on.

The tricky part is that you need to make sure only one master controls a subsystem (motor) at any given time. Let’s look at a simple example of an arm driven up and down by two buttons, but having a third button as a preset height. A typical control loop for that subsystem would be like:

if (buttonUp) {
    setSpeed(upSpeed);
} else if (buttonDOwn) {
    setSpeed(downSpeed);
} else {
    setSpeed(0);
}

A naive way of extending that by inserting something like:

... else if(macroButton) {
    setTarget(preserHeight);
} ...

is bound to fail, since as soon as you let go of the macroButton, the no-button else branch would kick in and stop your motor.
To deal with this problem, you need some kind of interlock mechanism that dictates what is controlling the subsystem at any given time - in this case macro vs. controller. So what you do is introducing a kind of state variable. When the driver presses the macro button, you set it to the macro-is-driving state. Up or down button and you reset it to joystick-is-driving. Then, you only stop the motor if the joystick is in charge.

The above is the proper and a very generic approach that could handle the most complex control problems. As long as you can express them in the form of states and state machine transitions, you can easily code the solution. There are simpler solutions, with drawbacks though. One such approach is to block the control loop for the duration of the macro - the macro would happen synchronously (using blocking calls) inside the macro button conditional brannch, for example. But then, you won’t be able to abort the macro, or even engage the other subsystems while it runs, with possibly catastrophic consequences. Imagine programmer quickly hacking together such a blocking robot unfold macro for use in the driver skills, then the driver, at the start signal, driving forward while pressing the macro button - well, the macro worked, but the robot was uncontrollably speeding across the field in the mean time, tipping over at the end…

2 Likes