Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   How to grdually speed up the robot? (http://www.chiefdelphi.com/forums/showthread.php?t=125467)

Mubtasim 29-01-2014 22:04

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

eddie12390 30-01-2014 09:18

Re: How to grdually speed up the robot?
 
Quote:

Originally Posted by Mubtasim (Post 1334563)
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);
}


notmattlythgoe 30-01-2014 09:39

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.

omalleyj 30-01-2014 09:41

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.

Ether 30-01-2014 10:09

Re: How to grdually speed up the robot?
 
Quote:

Originally Posted by Mubtasim (Post 1334563)
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



James Lightfoot 04-02-2014 20:33

Re: How to grdually speed up the robot?
 
Quote:

Originally Posted by Ether (Post 1334719)
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 ::ouch::

slibert 04-02-2014 21:16

Re: How to grdually speed up the robot?
 
Quote:

Originally Posted by James Lightfoot (Post 1337732)
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 ::ouch::

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....

Joe Ross 04-02-2014 22:47

Re: How to grdually speed up the robot?
 
Quote:

Originally Posted by slibert (Post 1337745)
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

DonRotolo 05-02-2014 18:42

Re: How to grdually speed up the robot?
 
Quote:

Originally Posted by Mubtasim (Post 1334563)
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.

Ether 05-02-2014 18:46

Re: How to grdually speed up the robot?
 
Quote:

Originally Posted by DonRotolo (Post 1338163)
We did this once. Our drivers hated it.

How slow was your ramp rate?



Jared Russell 05-02-2014 19:57

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".

notmattlythgoe 07-02-2014 08:04

Re: How to grdually speed up the robot?
 
Quote:

Originally Posted by Jared341 (Post 1338212)
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.

Ether 07-02-2014 09:20

Re: How to grdually speed up the robot?
 
Quote:

Originally Posted by notmattlythgoe (Post 1339020)
We're using a moving average this year...

What was the problem you were trying to solve by doing this?



notmattlythgoe 07-02-2014 09:21

Re: How to grdually speed up the robot?
 
Quote:

Originally Posted by Ether (Post 1339051)
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.


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

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