VEX V5 - Driver Control
VEX V5 - Driver Control
#include "robot-config.h"this includes the robot-config as part of the program.
a custom function called Drive is written:
void Drive(int lspeed, int rspeed, int wt) { LMotor.spin(forward,lspeed,pct); RMotor.spin(forward,rspeed,pct); wait(wt); }
We initialize some global variables:
int lspeed=0; int rspeed=0;
lspeed and rspeed will be the speed of the two drive motors.
lspeed=Controller.Axis3.position(pct); rspeed=Controller.Axis2.position(pct);
lspeed and rspeed are set by sensing the position of the joysticks on the controller. Here we read Axis3 and Axis2 as a percentage (pct). So pushed full forward is 100%, full backward is -100%. Calling the Drive function :
Drive(lspeed, rspeed, 10);Runs the motors and slows the process a little by waiting 10msec for the motors to turn.
here is the complete main code:
#include "robot-config.h" void Drive(int lspeed, int rspeed, int wt) { LMotor.spin(forward,lspeed,pct); RMotor.spin(forward,rspeed,pct); wait(wt); } int main() { int lspeed=0; int rspeed=0; while(true) { lspeed=Controller.Axis3.position(pct); rspeed=Controller.Axis2.position(pct); Drive(lspeed, rspeed, 10); } }
Back to the course
Lessons
Lesson 1: Competitive Robotics
60 Minutes
Lesson 2: Game Analysis and Rules
60 Minutes
Lesson 3: Strategy and Game Play
60 Minutes
Lesson 4: Fasteners and Tools
60 Minutes
Design Rules
60 Minutes
Lesson 8: Gears and Gear Ratios
60 Minutes
Lesson 9: Custom Build
60 Minutes
Lesson 12: Autonomouse Code and Functions
60 Minutes
Lesson 14: Sensors and Improved Auton
60 Minutes
Lesson 15: Tournament
60 Minutes