|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#4
|
|||
|
|||
|
Re: Arcade Control
This code assumes that your robot has two powered wheels mounted opposite to each other and the left motor is reversed. Positive power to both motors would drive the robot forward.
Code:
#include "JoystickDriver.c" // Include the RobotC joystick driver file.
task main() {
while (true) { // infinitely loop
getJoystickSettings(joystick); // Update buttons and joysticks.
int turn = joystick.joy1_x1; // Get joystick 1's left x-axis value.
int power = joystick.joy1_y1; // Get joystick 1's left y-axis value.
motor[leftMotor] = power + turn;
motor[rightMotor] = power - turn;
}
}
To drive forward, we push the joystick forward (positive y). This makes the value of the power variable +100. The turn variable is 0 because the joystick hasn't moved left or right. This effectively translate in the code to Code:
motor[leftMotor] = 100 + 0; motor[rightMotor] = 100 + 0; Likewise, to turn right in place, we can push the joystick to the right. This will cause the turn variable to be +100, but the power variable will be 0. Code:
motor[leftMotor] = 0 + 100; motor[rightMotor] = 0 - 100; Now, say we wanted to go forward and turn right at the same time. If we push the joystick to a positive value of 100 in both directions (x and y), we ge this: Code:
motor[leftMotor] = 100 + 100; motor[rightMotor] = 100 - 100; Backing up and turning left work similarly. I hope this helps. If you are doing something like holonomic omni wheel driving, let me know because that is quite different and requires a lot more explanation. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|