Go to Post It's just a game. - artdutra04 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 29-01-2014, 22:04
Mubtasim Mubtasim is offline
Registered User
FRC #4797
 
Join Date: Feb 2013
Location: NY
Posts: 10
Mubtasim is an unknown quantity at this point
How to grdually speed up the robot?

We are trying to make it so that when the joystick signals to seed up, there has to be several milliseconds delays in order to gradually increase the speed. Is there any simple way to do this? [ using simple robot template ]

Thanks
Reply With Quote
  #2   Spotlight this post!  
Unread 30-01-2014, 09:18
eddie12390's Avatar
eddie12390 eddie12390 is offline
Registered User
AKA: Eddie
FRC #3260 (SHARP)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Pittsburgh
Posts: 285
eddie12390 is a glorious beacon of lighteddie12390 is a glorious beacon of lighteddie12390 is a glorious beacon of lighteddie12390 is a glorious beacon of lighteddie12390 is a glorious beacon of light
Re: How to grdually speed up the robot?

Quote:
Originally Posted by Mubtasim View Post
We are trying to make it so that when the joystick signals to seed up, there has to be several milliseconds delays in order to gradually increase the speed. Is there any simple way to do this? [ using simple robot template ]

Thanks
You can keep track of an output variable and add a percentage of the error between it and the desired output each loop. Something like:

Code:
float output = 0.0;

while(true)
{
    float desired = joystick.getY();

    float error = desired - output;

    output += error * 0.1;

    motor.set(output);
}
Reply With Quote
  #3   Spotlight this post!  
Unread 30-01-2014, 09:39
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,728
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: How to grdually speed up the robot?

We use what's called a rolling average to accomplish this. You keep a list of the past X values and average them together to get the current value. Each iteration you add the new value at the end and drop the first value. The more numbers you store the slower the system will react to changes. We wrote a utility to do this, I can get one of our students to post the code for it if you'd like.
Reply With Quote
  #4   Spotlight this post!  
Unread 30-01-2014, 09:41
omalleyj omalleyj is offline
Registered User
AKA: Jim O'Malley
FRC #1279 (Cold Fusion)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: New Jersey
Posts: 132
omalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to behold
Re: How to grdually speed up the robot?

What problem are you trying to solve? Are you trying to prevent spinning your wheels on acceleration? Preventing stress on the drivetrain when reversing direction quickly? Or just generally going for more control and less 'twitchiness'?

Eddie12390 has the right idea, but you need to manage each situation of input. For instance what will happen if you are going full speed and get a joystick input of full forward (-1.0). If you exactly cut and paste that code without at least limiting it you will be out of range for the motor input.

But his concept is sound for the problem as stated: take some percentage between where you are now and where you want to be and apply it. Just make sure you account for all situations.

Last edited by omalleyj : 30-01-2014 at 09:45. Reason: lack of coffee
Reply With Quote
  #5   Spotlight this post!  
Unread 30-01-2014, 10:09
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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: How to grdually speed up the robot?

Quote:
Originally Posted by Mubtasim View Post
We are trying to make it so that when the joystick signals to seed up, there has to be several milliseconds delays in order to gradually increase the speed. Is there any simple way to do this?
Yes.

Code:
change = joystick - limitedJoystick;
if (change>limit) change = limit;
else (if change<-limit) change = -limit;
limitedJoystick += change;
limit is the amount of change you will allow every iteration (e.g. every 20 milliseconds for TeleOp)

limitedJoystick is the rate-limited joystick value you use to control your motors.



Here's an article which might be of interest:
http://thinktank.wpi.edu/article/140



Last edited by Ether : 30-01-2014 at 10:15.
Reply With Quote
  #6   Spotlight this post!  
Unread 04-02-2014, 20:33
James Lightfoot James Lightfoot is offline
Programming & Electrical Mentor
FRC #3737 (Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Wayne County, NC
Posts: 21
James Lightfoot is just really niceJames Lightfoot is just really niceJames Lightfoot is just really niceJames Lightfoot is just really niceJames Lightfoot is just really nice
Re: How to grdually speed up the robot?

Quote:
Originally Posted by Ether View Post
Yes.

Code:
change = joystick - limitedJoystick;
if (change>limit) change = limit;
else (if change<-limit) change = -limit;
limitedJoystick += change;
limit is the amount of change you will allow every iteration (e.g. every 20 milliseconds for TeleOp)

limitedJoystick is the rate-limited joystick value you use to control your motors.

Hello all. Rocky mentor here w/ a quick question. Wheter we use a Logitech joystick or an Xbox controller (on USB), does a stick give a value of -1 to 1 (analog) or -1, 0, +1 (digital)?

Thanks
Reply With Quote
  #7   Spotlight this post!  
Unread 04-02-2014, 21:16
slibert slibert is offline
Software Mentor
AKA: Scott Libert
FRC #2465 (Kauaibots)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2005
Location: Kauai, Hawaii
Posts: 356
slibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud of
Re: How to grdually speed up the robot?

Quote:
Originally Posted by James Lightfoot View Post
Hello all. Rocky mentor here w/ a quick question. Wheter we use a Logitech joystick or an Xbox controller (on USB), does a stick give a value of -1 to 1 (analog) or -1, 0, +1 (digital)?

Thanks
Values from the joystick are continuous, so a value of 0.3 when pushing an axis forward slightly is reasonable.

We typically output the values so they can be viewed in NetConsole, like this:


System.out.println("X: " + joystick.getX() + ", Y: " + joystick.getY() + ", Rot: " + joystick.getTwist() );

However, we found out (we switched to java this year, it used to work in C++) that the getRotate() didn't work as we expected, so instead we use

double rotate = joystick.getRawAxis(4);

In fact, joystick.getTwist() for us was returning 0 until we moved it a bit, then it'd be stuck at 1. Not sure what's going on there....
Reply With Quote
  #8   Spotlight this post!  
Unread 04-02-2014, 22:47
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: How to grdually speed up the robot?

Quote:
Originally Posted by slibert View Post
However, we found out (we switched to java this year, it used to work in C++) that the getRotate() didn't work as we expected, so instead we use

double rotate = joystick.getRawAxis(4);

In fact, joystick.getTwist() for us was returning 0 until we moved it a bit, then it'd be stuck at 1. Not sure what's going on there....
It looks like C++ defines the twist axis as Axis 4 and Java defines it on Axis 3. This is probably due to different joysticks behaving differently. I know the Logitech Axis 3 defines the throttle on Axis 3 and doesn't have a twist, but the Logitech Extreme 3d Pro defines the twist on Axis 3 and throttle on Axis 4.

I filed artf1718
Reply With Quote
  #9   Spotlight this post!  
Unread 05-02-2014, 18:42
DonRotolo's Avatar
DonRotolo DonRotolo is offline
Back to humble
FRC #0832
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Atlanta GA
Posts: 7,014
DonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond repute
Re: How to grdually speed up the robot?

Quote:
Originally Posted by Mubtasim View Post
We are trying to make it so that when the joystick signals to seed up, there has to be several milliseconds delays in order to gradually increase the speed.
We did this once. Our drivers hated it.
__________________

I am N2IRZ - What's your callsign?
Reply With Quote
  #10   Spotlight this post!  
Unread 05-02-2014, 18:46
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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: How to grdually speed up the robot?

Quote:
Originally Posted by DonRotolo View Post
We did this once. Our drivers hated it.
How slow was your ramp rate?


Reply With Quote
  #11   Spotlight this post!  
Unread 05-02-2014, 19:57
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,080
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: How to grdually speed up the robot?

Another way to do this is:

Code:
motor_value = k*joystick_reading + (1-k)*motor_value
k is between 0 and 1.

Large k values make the motor very responsive, and a value of 1 means no filtering is actually happening. Small values make the output move slowly from the old value to the joystick value.

This is an Infinite Impulse Response (IIR) low pass filter, whereas the moving average is a Finite Impulse Response (FIR) filter. Which of these to choose (or using a rate limiter like Ether suggested) depends on what exactly you are trying to accomplish.

My experience with using any sort of filtering in the drive train (other than traction control in 2009) is that drivers usually hate it because if the effect is significant it feels "sluggish".
Reply With Quote
  #12   Spotlight this post!  
Unread 07-02-2014, 08:04
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,728
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: How to grdually speed up the robot?

Quote:
Originally Posted by Jared341 View Post
Another way to do this is:

Code:
motor_value = k*joystick_reading + (1-k)*motor_value
k is between 0 and 1.

Large k values make the motor very responsive, and a value of 1 means no filtering is actually happening. Small values make the output move slowly from the old value to the joystick value.

This is an Infinite Impulse Response (IIR) low pass filter, whereas the moving average is a Finite Impulse Response (FIR) filter. Which of these to choose (or using a rate limiter like Ether suggested) depends on what exactly you are trying to accomplish.

My experience with using any sort of filtering in the drive train (other than traction control in 2009) is that drivers usually hate it because if the effect is significant it feels "sluggish".
We're using a moving average this year and chose our value based on if it felt laggy to the driver or not. We're only storing 10 values, but we figured something is better than nothing. We'll see how this season goes and decide if it is something that we'll continue to use.
Reply With Quote
  #13   Spotlight this post!  
Unread 07-02-2014, 09:20
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
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: How to grdually speed up the robot?

Quote:
Originally Posted by notmattlythgoe View Post
We're using a moving average this year...
What was the problem you were trying to solve by doing this?


Reply With Quote
  #14   Spotlight this post!  
Unread 07-02-2014, 09:21
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,728
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: How to grdually speed up the robot?

Quote:
Originally Posted by Ether View Post
What was the problem you were trying to solve by doing this?


Just trying to limit current draw when we can. We weren't really having a problem, just something we wanted to try.
Reply With Quote
Reply


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

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