View source
From STEMRobotics
for
RobotC Resources
Jump to:
navigation
,
search
We use RobotC to program the VEX robots. This page has a number of RobotC resources you might find useful. == RobotC Class == Albert Schueller, one of the professors from Whitman College, has written an excellent course called [http://carrot.whitman.edu/Robots/notes.pdf ''Programming with Robots''] based on RobotC. It covers all the bases, variables, conditionals, loops and arrays, you name it. Each new concept is accompanied by example code and every chapter ends with a series of exercises that you can use to test if you have grasped the new concepts covered thus far. The examples use the NXT computer, but are transportable to the VEX. == RobotC Tasks == You can run up to three different tasks at one time. <source lang="c"> task taskA() { while(true) { // your code here Wait1Ms(100); //important, this allows other tasks to run } } task taskB() { while(true) { // your code here Wait1Ms(100); //important, this allows other tasks to run } } task main() { StartTask(taskA); // Start the first task StartTask(taskB); // Start the second task while (true) { Wait1Ms(100); //important, this allows other tasks to run } } </source> When this code runs, the three tasks (taskA, taskB and main) will all run their code. It's very important that you put the Wait1Ms(time) statement in. Once a task ''waits'' it releases the CPU to work on other tasks. If you want to have more than 3 tasks you need to do a StopTask(task_name) to stop it from running and then do a StartTask(new_task_name) to start the new task. == Setting Task Priority == The default task priority is '7'. You can assign priorities between 0 and 255 by setting the nSchedulePriority value. <source lang="c"> task taskA() { nSchedulePriority = 15; //Raising the Priority int pri_taskA = nSchedulePriority; } task taskB() { nSchedulePriority = 5; //Lowing the Priority int pri_taskB = nSchedulePriority; } task main() { int pri_main = nSchedulePriority; //Defaults to Priority '7' StartTask(taskA); StartTask(taskB); //This task won't run because it has lower priority than "Main" } </source> The variable '''nSchedulePriority''' is the CPU scheduler priority for the current task. ROBOTC shares CPU execution time among various tasks by giving each task a “time slice” where it will execute a group of instructions. Each task can be assigned a priority from 0 to 255. The scheduler gives execution time to the highest priority task that is waiting to run. A round robin scheduling scheme is used when there are multiple tasks ready to run all with the highest priority. Lower priority tasks will not execute until there are no tasks of higher priority that are ready to run. Values higher than 15 are not recommended since there are system level tasks that run. == Not using the competition template== Key thing is to use ''bVexAutonomousMode = false;'' that allows the remote controls to work. Below is a sample from one of our protobots <source lang=c> task main() { bVexAutonomousMode = false; //Activates Remote Control Mode bMotorReflected[LeftFront] = true; //Port 2 Motor Direction Flipped bMotorReflected[LeftRear] = true; bMotorReflected[LeftArm] = true; bMotorReflected[RightArm] = false; while (1 == 1) { motor[RightFront] = vexRT(Ch3); motor[RightRear] = vexRT(Ch3); motor[LeftFront] = vexRT(Ch2); motor[LeftRear] = vexRT(Ch2); motor[LeftArm] = vexRT(Ch5); motor[RightArm] = vexRT(Ch5); motor[Claw] = vexRT(Ch6); } } </source> == Program a VEX Spike == The [[VEX Spike]] page has how to program a VEX Spike. You need to make a special cable to attach the Spike to the VEX.
Return to
RobotC Resources
.
Views
Page
Discussion
View source
History
Personal tools
Log in
Navigation
Main Page
News
Community portal
Current events
Recent changes
Random page
Vex Event Calendar
Help
Search
Toolbox
What links here
Related changes
Upload file
Special pages