Tank Drive Pattern
Challenge
A simple and intuitive joystick mapping for maneuvering about the field.
*Don’t forget to include Joystick Drivers.
* Also remember to call the joystick settings with:
getJoystickSettings(joystick);Solution
Using the D-Pad to directly affect the speed and maneuverability of the robot.
Pattern Template
Left drive motor <-- Left Analog Stick Y Axis Right driver motor <-- Right Analog Stick X AxisUsing these variables, if you wanted a very simple program that looks at the Y-Value of the left analog stick, and the Y-Value of the right analog stick, and assigns it to the left and right motors respectively (like a tank drive):
Example(s)
This code disregards achieves the same as the code above, but disregards small values.
task main() { while(true) { getJoystickSettings(joystick); motor[motorD] = joystick.joy1_y1; motor[motorE] = joystick.joy1_y2; wait1Msec(10); } }
This code combines everything above, and should deliver the full shebang.
task main() { waitForStart(); int leftPower, rightPower; while(true) { getJoystickSettings(joystick); // Update Joystick variables // Save the joystick values to two local variables leftPower = joystick.joy1_y1; rightPower = joystick.joy1_y2; // Check to make sure the values aren't too negligible if (abs(leftPower) < 10) { leftPower = 0; } if (abs(rightPower) < 10) { rightPower = 0; } // Check some buttons to move an NXT motor if(joy1Btn(2)) { motor[motorA] = 50; }else if(joy1Btn(4)) { motor[motorA] = -50; }else { motor[motorA] = 0; } motor[motorD] = leftPower; //Assign modified joystick variables to motor power. motor[motorE] = rightPower; wait1Msec(10); } }Related Patterns
Deadzone Pattern
Submitted by: Mark Raymond Jr.
Print This Post








