Tank Drive
Introduction
Example Code
#include "main.h"
// Motor Group Declarations for Left and Right
pros::Motor_Group motors_left(1);
pros::Motor_Group motors_right(2, true); // Be sure to reverse this!
void opcontrol() {
while(1) {
// Drive the left side of the robot forward at joystick left Y speed
motors_left.move(master.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y));
// Drive the right side of the robot forward at joystick right Y speed
motors_right.move(master.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y));
delay(20);
}
}#include "vex.h"
using namespace vex;
vex::motor left_motor(vex::PORT1);
vex::motor right_motor(vex::PORT2, true);
int main(void) {
while(1) {
// Retrieve the necessary joystick values
int leftY = Controller1.Axis3.position(percent);
int rightY = Controller1.Axis2.position(percent);
// Move the left side of the robot
motors_left.spin(vex::directionType::fwd, leftY);
// Move the right side of the robot
motors_right.spin(vex::directionType::fwd, rightY);
wait(20, msec);
}
}Summary
Pros
Cons
Contributing Teams to this Article:
Last updated
Was this helpful?
