On our robot, we have 2 separate mechanisms, a DR4B, and a tray. To make the dr4b move, we have to make the tray move first and then make the dr4b move. I wanted to program a macro that had the ability to perform this task in the sequence stated above when pressing only one button. If anyone can help me or provide any sample code I can use that would be great.
(sorry for all the trouble. I am new to vex. Thx for your help )
a means one. macros means many. How many do you want?
I want one macro that moves the tilter first and then moves the dr4b. Sorry for the misunderstanding.
Do you want one to move the Dr4b down and filter back?
Yes, one macro that moves it both up and one that moves it down. I only mentioned one because i believed that it would be easy to make the second one after learning how to make the first one.
Here is an example. you will need to change it to fit your robot.
change the button to what you want
note what is and is not in the while and what is and is not in the user control task
Code
/*---------------------------------------------------------------------------*/
/* */
/* User Control Task */
/* */
/* This task is used to control your robot during the user control phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
void up() {
//code you want to run when going up
}
void down() {
//code you want to run when going down
}
void usercontrol(void) {
// User control code here, inside the loop
while (1) {
// This is the main execution loop for the user control program.
// Each time through the loop your program should update motor + servo
// values based on feedback from the joysticks.
// ........................................................................
// Insert user code here. This is where you use the joystick values to
// update your motors, etc.
// ........................................................................
Controller1.ButtonA.pressed( up ); //change the button to what you want
Controller1.ButtonB.pressed( down ); // note what is and is not in the while loop
//and what is and is not in the user control task
wait(20, msec); // Sleep the task for a short amount of time to
// prevent wasted resources.
}
}
Do you want me to explain any of the lines?
One thing I had a question about was what you are supposed to put in the area inside the user control function but before the while loop. I am confused about what is supposed to go there.
Also just to clarify I just call the up function when I click a button on the code.
Ex.
bool buttonA = Controller1.ButtonA.pressing();
bool buttonB = Controller1.ButtonB.pressing();
if (buttonA){
up();
}
else if (buttonB){
down();
}
else {
tilter.spin(forward,0, voltageUnits::volt);
}
No dont do this.
you just need these 2 lines
nothing
any more questions?
No not really. I think i understand this now. Thx alot for the help!
Remember donβt put these in a if statement. Just straight into the while true loop.