Does anyone know how to programme ‘states’? This is when you press either the small E or F buttons on the controller and the brain will turn a motor a specific amount. Very useful if you want to raise or lower an arm to an exact position. Thanks
In what programming language?
We do this using RobotC. We set a task up at the top with a global variable, similar to this:
#pragma config(Motor, motor1, armMotor, tmotorVexIQ, PIDControl, encoder)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
int armState = 0;
task armMovement()
{
if(armState == 0)
{
setMotorSpeed(armMotor, 0);
wait1Msec(10);
}
if(armState == 1)
{
setMotorSpeed(armMotor, 25);
wait1Msec(10);
}
}
task main()
{
startTask(armMovement);
while(true)
if(getJoystickValue(BtnLUp) == 1)
{
armState = 0;
while(getJoystickValue(BtnLUp) == 1)
{
wait1Msec(10);
}
}
if(getJoystickValue(BtnLDown) == 1)
{
armState = 1;
while(getJoystickValue(BtnLDown) == 1)
{
wait1Msec(10);
}
}
}
We use robotC graphical. Thanks
If you are using the graphical version it would be difficult to do what you’re asking. However, this can be done fairly easily with regular RobotC, as shown by DaddyCrusader. He takes advantage of multitasking. See his code. The task armmovement() does what you want. It is called from task main() as shown.
If you like, you can write the non-task code in Graphical then convert the file to text. Under View|Convert Graphical File to Text. Once done a new file appears with a different extension (“.c*”). It can also be compiled and downloaded to the robot after you have added in the desire task code. You can’t go backwards to the Graphical version from here, but the original Graphical file is unchanged.
I can tell you that you need to check the rotation degrees and stop when it is equal to OR greater than your target. It’s very hard to catch it when it is exactly equal to the target degrees.
We did this using modkit. Use rotation degrees and a variable that toggles active/stop states (to reset for when you want to begin movement again).
If you like the ideas of motor limits be sure to see my post in the tech discussion area. we have a code example there.
His code can be copied just above “task main()”
See his code under task main() to find out how to call his armMovement task. Your other commands in the repeatForever loop should remain after the startTask(armMovement) command.