It was suggested that I explain the last couple of lines of code in this example.
task main()
{
// Init smart motor control
SmartMotorsInit();
SmartMotorRun();
// Init drive system with standard controls
DriveSystemInit( Mecanum4Motor, MotorLF, MotorLB, MotorRF, MotorRB );
DriveSystemRun();
while(1)
wait1Msec(10);
}
This part
while(1)
wait1Msec(10);
The short answer is that this code spins in an infinite loop, whilst doing nothing. Well, it’s not quite that simple, the purpose is to keep the task running while constantly yielding time to other tasks. What is not apparent from this example (because it’s just to give a taste of how little code is need to use the driveLib) is that DriveSystemRun() function starts another task that checks the joystick and sends appropriate commands to the drive motors. If the main task exits then all the other tasks will stop as well. I should have commented the code as follows.
task main()
{
// Init smart motor control
SmartMotorsInit();
SmartMotorRun();
// Init drive system with standard controls
DriveSystemInit( Mecanum4Motor, MotorLF, MotorLB, MotorRF, MotorRB );
DriveSystemRun();
// Keep this task alive, all work happens in the drive library
while(1)
{
// Nothing to do so yield by calling wait1Msec
wait1Msec(10);
}
}
For the whole story on ROBOTC multi-tasking, see the series of posts in the ROBOTC programming tips thread, specifically posts 23 through 30