Go to Post Commence the year of the brown out! - Jared Russell [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 24-03-2012, 21:16
krisloz's Avatar
krisloz krisloz is offline
Registered User
AKA: Krissy
no team
Team Role: Programmer
 
Join Date: Mar 2012
Rookie Year: 2012
Location: California
Posts: 23
krisloz will become famous soon enough
Arcade Control

I would like to try an arcade control program on RobotC. Would it be possible to move forward, backward and turn left and right all on one analog stick?

I thought about it, coded it, and I can't really see how this is possible. Is there a special code just for arcade control?
  #2   Spotlight this post!  
Unread 24-03-2012, 21:20
Andrew Lawrence
 
Posts: n/a
Re: Arcade Control

Yeah. I'm no programmer, but I think some arcade-drive code is included in the default code, so you can probably look there.

From what I remember our programmers saying, the up/down of a joystick (Z), and the left/right of a joystick (X) control whether you turn left or right, or go forward or backwards. Or a mixmatch of any of the options (ie. forward and right).

Hope this helps!
  #3   Spotlight this post!  
Unread 24-03-2012, 21:30
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,125
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Arcade Control

Quote:
Originally Posted by krisloz View Post
I would like to try an arcade control program on RobotC. Would it be possible to move forward, backward and turn left and right all on one analog stick?
Yes.

http://www.chiefdelphi.com/forums/at...5&d=1330054122


  #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.
  #5   Spotlight this post!  
Unread 25-03-2012, 00:31
krisloz's Avatar
krisloz krisloz is offline
Registered User
AKA: Krissy
no team
Team Role: Programmer
 
Join Date: Mar 2012
Rookie Year: 2012
Location: California
Posts: 23
krisloz will become famous soon enough
Re: Arcade Control

Oh my goodness, you just made variables understandable. I never liked using variables and tried to steer away from them as much as possible, but this just made so much sense. Thank you.

This is my first time building, until I get people for a team (building is such a pain I'd rather stick to programming) so I'm not sure what holonomic wheel driving is. I am planning on using a mix of omni-wheels and idlers for this.

I assume I just need to adjust the coding if I use more than 2 motors?
  #6   Spotlight this post!  
Unread 25-03-2012, 00:43
krisloz's Avatar
krisloz krisloz is offline
Registered User
AKA: Krissy
no team
Team Role: Programmer
 
Join Date: Mar 2012
Rookie Year: 2012
Location: California
Posts: 23
krisloz will become famous soon enough
Re: Arcade Control

Quote:
Originally Posted by ianonavy View Post
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.
*My comment above &...

Also would I still need to include the "arcadeControl();" line in there ?
  #7   Spotlight this post!  
Unread 25-03-2012, 01:14
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

I added this comment after I had finished writing this entire post:

Waaaiiit wait wait. Are you using Natural Language? arcadeControl() is a Natural Language function, which is different from plain old RobotC. If you have no idea what Natural Language is, then please ignore the above comment and keep reading below. If you are using that, then all of my provided code is completely obsolete.

------------------------------------------------------------------------------------------

I'm glad that my post was able to better explain how variables work, as they are very important for programming outside of RobotC.

To answer your question, no. arcadeControl() is a pre-built function that basically does what I showed you earlier but with an added feature called a threshold. I don't like using it because I prefer to work with the motors more directly since it allows me to tweak exactly how the motors respond to the joysticks, and I like to understand how it works. It also helped me figure out how to program holonomic drive, which I will explain later. arcadeControl() is a part of what is called Natural Language. It's a simplified version of robotC that comes with commands like forward() and untilSensor(). You really don't need to use it for FTC programming as my code essentially re-implements what arcadeControl() would do. It is good programming practice to separate your code into functions (if you haven't learned what those are, I highly recommend reading the RobotC help documentation to learn more about them), but it usually isn't necessary for FTC programming.

Regarding the threshold, basically, sometimes the joysticks don't perfectly reset to 0. You can sometimes see it while you're running your tests; after releasing the joysticks, the motor still vibrates and tries to move. When you're not touching them, they might have a value of say, x=-3 and y=4. With my code, the motors would try to move with a speed of -3, but this isn't enough to overcome the internal friction of the motor. This could lead to seriously bad problems, so we overcome that by only running the motors if the joystick values are smaller than pre-determined threshold.

See this example code:
Code:
int x = joystick.joy1_x1;
int y = joystick.joy1_y1;
int THRESHOLD = 10;

if (abs(x) > THRESHOLD && abs(y) > THRESHOLD) {
  motor[driveLeft] = y + x;
  motor[driveRight] = y - x;
} else {
  motor[driveLeft] = 0;
  motor[driveRight] = 0;
}
In English, that translates to:

If the absolute value of the joystick's x-axis is greater than 10 (the threshold) AND the y-value is also greater than 10, run the motors according to the formulas I showed you earlier. Otherwise, don't power the motors. You can also think of it like this: if either joystick value (x or y) is less than 10, don't even bother running the motor because it's too small to even move the motor anyway.

Also, holonomic drive is basically four omni wheels in a diagonal configuration, which lets you strafe left and right without needing to turn, much unlike a car or shopping cart.
  #8   Spotlight this post!  
Unread 25-03-2012, 02:22
krisloz's Avatar
krisloz krisloz is offline
Registered User
AKA: Krissy
no team
Team Role: Programmer
 
Join Date: Mar 2012
Rookie Year: 2012
Location: California
Posts: 23
krisloz will become famous soon enough
Re: Arcade Control

Oh no, I'm not looking to strafe, I want to reverse power on motors. These codes makes sense, plus the thresh hold would then just stop the motors from running unless they're bigger than the thresh hold. I've seen thresh holds in my teammate's codes before, but never understood them, so thank you again. I think that's all.

But please explain the holonomic drive if you don't mind, it sounds like a possibility, I learned a lot already.
Closed Thread


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 01:35.

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