A-team
December 14, 2019, 10:08pm
#1
I need help coding my macros for my robot. I have the code for the buttons regularly, but the brake type is on hold. Is this supposed to interfere?
this is the code for the macro
outside of usercontrol
void methodA() {
LIMotor.startRotateFor(directionType::rev, .2, rotationUnits::rev, 100, velocityUnits::pct);
RIMotor.rotateFor(directionType::rev, .2, rotationUnits::rev, 100, velocityUnits::pct);
}
in the user control
//set intakes down something rotations
(Controller1.ButtonA.pressed(methodA));
your void command is good. But I do macro a bit different. Not sure what this is what your looking for but this is what it would be
void methodA() {
LIMotor.startRotateFor(directionType::rev, .2, rotationUnits::rev, 100, velocityUnits::pct);
RIMotor.rotateFor(directionType::rev, .2, rotationUnits::rev, 100, velocityUnits::pct);
}
//in the user control
if (Controller1.ButtonA.pressing()) {
methodA()
};
1 Like
A-team
December 15, 2019, 1:45am
#4
Thanks!
Ill try it when I get a chance, but I want to just press a button, and then the intakes to move a certain distance.
weilin
December 15, 2019, 9:51am
#5
A-team, if you need to do only one action then it is best to do what @Micah_7157X said using rotateFor() function.
https://api.vexcode.cloud/v5/html/classvex_1_1motor.html#a9d60dc336810ea4d8aef35ee042f0d68
Or, if you need multiple steps, please, take a look at these macro programming examples:
@73335T , whenever you program a macro that executes during interactive user control period you need to define at least one state variable outside of the while(1) loop.
Please, see the following example:
int iMacroStateVar = 0; // 0 - macro is not running
uint32_t macroStepEndTime = 0;
while(1)
{
int userVal = 0;
int joyVal = Controller1.Axis1.position(pct);
if( fabs(joyVal) > 10 ) // if using joystick
{
userVal = joyVal;
}
// if using buttons
if( Controll…
Yes, you are correct that your user control code takes over your macro execution.
You need to give the macro some time to complete. Use this code as a sample for your user control loop:
bool bMacroIsRunning = false;
uint32_t macroStartTime = 0;
while(1)
{
int joyVal = Controller1.Axis1.position(pct);
if( abs(joyVal) > 10 )
{
motor1.spin(fwd,joyVal,pct);
bMacroIsRunning = false; // cancel macro run
}
else if( Controller1.ButtonL1.pressing() && bMacroIsRunnin…
A-team
January 14, 2020, 2:57pm
#6
Thanks, I figured I probably needed to do something like that, creating a state value. I’m good now