Go to Post Don’t choose to aim for the stars because they mark the peak of our abilities, don’t choose to aim for the stars because it is easy, choose to aim for the stars because it shows the depth of our potential; choose to aim for the stars because it is hard! - Ken Leung [more]
Home
Go Back   Chief Delphi > Other > FIRST Tech Challenge
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
  #10   Spotlight this post!  
Unread 10-11-2009, 09:36
l0jec l0jec is offline
Registered User
no team
 
Join Date: Oct 2009
Rookie Year: 2004
Location: St. Louis, MO
Posts: 52
l0jec has a spectacular aura aboutl0jec has a spectacular aura about
Re: [FTC]: Robot C

That is generally good advice, but I'm going to go ahead and share some extra insight. Remember that the joystick analog sticks have a range of -127 to 128, but your DC motors only have a range of -100 to 100. While you can directly pass the analog stick value to the motor & ROBOTC will not error, you are losing about 20% of the actual range of the analog stick which will not give you the good fine-grained control your robot is capable of.

The basic solution is to apply a linear scale such as: motor_output = joystick_input / max_joystick_value * max_motor_value.

However, we can do even better if we use a parabolic curve so that we have fine control at low speeds for a larger portion of the analog stick's range and then ramp up the scaling for the extremities of the analog stick's range. Below is a function which will do just that (as well as apply a deadzone):

Code:
//scaling function
int scaleForMotor(int joyVal) {

  //constants
  const int DEADZONE = 5;
  const int MAX_MOTOR_VAL = 100;
  const float MAX_JOY_VAL = 127.0;

  //check for deadzone
  if(abs(joyVal) < DEADZONE) {
    return 0;
  }

  //calculate scaled value
  int sign = joyVal / abs(joyVal); // 1 or -1
  float ratio = ((joyVal * joyVal) / (MAX_JOY_VAL * MAX_JOY_VAL));
  int scaledVal = (sign * MAX_MOTOR_VAL) * ratio;

  return scaledVal;
}
I have no issues sharing this to help other teams get going, but please attempt to understand what it is doing if you choose to copy it into your code. Feel free to adjust the constants to set your own deadzone or max motor output.
Just place the function in your code above the main task and call it like below:

Code:
//scales input from joystick 1 left analog stick's y-axis
motor[someMotor] = scaleForMotor(joystick.joy1_y1);  
//scales input from joystick 1 right analog stick's y-axis
motor[someOtherMotor] = scaleForMotor(joystick.joy1_y2);
Best of luck,
l0jec
Reply With Quote
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
[FTC]: Power Surge Robot Nitro-Guy FIRST Tech Challenge 7 21-05-2009 10:30
[FTC]: FTC Futures Forum at FTC World Championship gdo FIRST Tech Challenge 0 08-04-2009 18:46
[FTC]: FTC]: FTC Champ Tournament - Ontario (Scoring Breakdown) Mr. Lim FIRST Tech Challenge 2 03-03-2008 11:54
pic: FTC #3 robot design Techno-Turkey Extra Discussion 5 06-02-2008 08:07
[FTC]: [FTC]: Ontario Provincial FTC Start/End Times cbhl FIRST Tech Challenge 8 16-12-2007 13:37


All times are GMT -5. The time now is 18:43.

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