Go to Post Of course 254 owns Battlebots too - dodar [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Spotlight this post!  
Unread 24-03-2012, 22:10
ianonavy ianonavy is offline
Programming Mentor/Alumnus
AKA: Ian Adam Naval
FRC #3120 (RoboKnights)
Team Role: Mentor
 
Join Date: Dec 2010
Rookie Year: 2008
Location: Sherman Oaks
Posts: 32
ianonavy is an unknown quantity at this point
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 explain this, we can look at some of the different possible ways to push the joystick. For simplicity's sake, I'm going to make all of the joysticks be pushed to a value of 100.

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;
which as we know, will drive the robot forward.

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;
As you can see, this would make the right wheel spin backward and the left wheel spin forward, effectively turning the robot in place to the right.

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;
The left motor will go forward at 100% power even though technically the code is trying to set it to 200. This is due to a physical limitation. However, the right motor will stay at 0, which will allow for what is sometimes called a swing turn.

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
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 20:10.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi