Go to Post I guess it's true, 'There is no replacement for displacement'. - Andy A. [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 17-02-2015, 13:43
choas500 choas500 is offline
Registered User
FRC #4640
 
Join Date: Jan 2013
Location: frc
Posts: 4
choas500 is an unknown quantity at this point
Acceleration Curve java help

Hey does anyone know how to program an acceleration curve for cim motors??
Reply With Quote
  #2   Spotlight this post!  
Unread 17-02-2015, 14:12
GeeTwo's Avatar
GeeTwo GeeTwo is online now
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,687
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Acceleration Curve java help

What are you trying to accomplish?
If you really want to control/limit acceleration, you can set up a PIDController using the motor speed(s) as the system input and the acceleration (from the RoboRIO's built-in accelerometer, for example) as the system output.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #3   Spotlight this post!  
Unread 17-02-2015, 15:32
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: Acceleration Curve java help

Quote:
Originally Posted by choas500 View Post
Hey does anyone know how to program an acceleration curve for cim motors??
As GeeTwo asked, what is the problem you are trying to solve?

If you are simply wanting to prevent driver "jackrabbit" starts and stops so the totes won't fall off the stack you are carrying, a simple solution would be to add a slew rate limiter to your joystick commands.


Reply With Quote
  #4   Spotlight this post!  
Unread 17-02-2015, 17:34
JacobD's Avatar
JacobD JacobD is offline
Registered User
AKA: Jacob
FRC #1672 (Mahwah Robo T-Birds)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2013
Location: New Jersey
Posts: 93
JacobD is an unknown quantity at this point
Re: Acceleration Curve java help

I'm assuming you want something like this.

Code:
double magnitude = Math.pow(2,(driveStick.getMagnitude())-1; 
chassis.mecanumDrive_Polar(magnitude, driveStick.getDirectionDegrees(), driveStick.getRotationDirection());
this should make a pretty decent magnitude:acceleration ratio.

It is an exponential function that increases the speed of the robot when reaching the upper bounds.

You can just edit this so that it works with your drive and controls. Or, if you post the code I will do it for you.

Last edited by JacobD : 17-02-2015 at 19:08.
Reply With Quote
  #5   Spotlight this post!  
Unread 17-02-2015, 17:45
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: Acceleration Curve java help

Quote:
Originally Posted by JacobD View Post
I'm assuming you want something like this.

Code:
double magnitude = Math.pow(1.3,driveStick.getMagnitude()); 
chassis.mecanumDrive_Polar(magnitude, driveStick.getDirectionDegrees(), rotationDirection);
this should make a pretty decent magnitude:acceleration ratio.

You can just edit this so that it works with your drive and controls. Or, if you post the code I will do it for you.
Since the OP has not responded to requests to clarify the nature of the problem he is interested in solving, you might want to qualify your suggestion with an explanation of what problem it is intended to solve... lest he take your suggestion and apply it to a problem different from what you inferred.

You might also caution that your suggestion maps the domain -1..+1 to the range 0.769..1.3


Reply With Quote
  #6   Spotlight this post!  
Unread 17-02-2015, 18:54
JacobD's Avatar
JacobD JacobD is offline
Registered User
AKA: Jacob
FRC #1672 (Mahwah Robo T-Birds)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2013
Location: New Jersey
Posts: 93
JacobD is an unknown quantity at this point
Re: Acceleration Curve java help

Quote:
Originally Posted by Ether View Post
You might also caution that your suggestion maps the domain -1..+1 to the range 0.769..1.3


Yeah, I wasn't thinking. I fixed that. Also, the domain is [0,1] because you cannot have a negative magnitude. But, that assumes that he is using mecanum drive. If not, another solution will be needed.

Code:
Joystick stick1, stick2;
double stick1val,stick2val;

stick1val = Math.pow(stick1.getX(),3);
stick2val = Math.pow(stick2.getY(),3);

chassis.tankDrive(stick1val, stick2val);
That would let you take input with a domain of [-1,1] and use it with tank drive.

Last edited by JacobD : 17-02-2015 at 19:16.
Reply With Quote
  #7   Spotlight this post!  
Unread 17-02-2015, 19:19
choas500 choas500 is offline
Registered User
FRC #4640
 
Join Date: Jan 2013
Location: frc
Posts: 4
choas500 is an unknown quantity at this point
Re: Acceleration Curve java help

We are trying to fix the automatic jump the robot gets as soon as you move the joysticks.
Reply With Quote
  #8   Spotlight this post!  
Unread 17-02-2015, 19:35
JacobD's Avatar
JacobD JacobD is offline
Registered User
AKA: Jacob
FRC #1672 (Mahwah Robo T-Birds)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2013
Location: New Jersey
Posts: 93
JacobD is an unknown quantity at this point
Re: Acceleration Curve java help

Can you show us your code right now? Otherwise, tell me the type of drive you are using.

Tank Drive:
Code:
Joystick stick1, stick2;
double stick1val,stick2val;

stick1val = Math.pow(stick1.getX(),3);
stick2val = Math.pow(stick2.getY(),3);

chassis.tankDrive(stick1val, stick2val);
Mecanum Drive:
Code:
double magnitude = Math.pow(driveStick.getMagnitude(),3); 
chassis.mecanumDrive_Polar(magnitude, driveStick.getDirectionDegrees(), driveStick.getRotationDirection());
Reply With Quote
  #9   Spotlight this post!  
Unread 17-02-2015, 20:08
GeeTwo's Avatar
GeeTwo GeeTwo is online now
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,687
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Acceleration Curve java help

Quote:
Originally Posted by choas500 View Post
We are trying to fix the automatic jump the robot gets as soon as you move the joysticks.
Then the slew limiter Ether suggested is probably your best solution:

Quote:
Originally Posted by Ether View Post
If you are simply wanting to prevent driver "jackrabbit" starts and stops so the totes won't fall off the stack you are carrying, a simple solution would be to add a slew rate limiter to your joystick commands.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #10   Spotlight this post!  
Unread 17-02-2015, 22:04
choas500 choas500 is offline
Registered User
FRC #4640
 
Join Date: Jan 2013
Location: frc
Posts: 4
choas500 is an unknown quantity at this point
Re: Acceleration Curve java help

This is our regular code

package org.usfirst.frc.team4640.robot;


import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;



public class Robot extends SampleRobot {
RobotDrive myRobot; // class that handles basic drive operations
Joystick leftStick; // set to ID 1 in DriverStation
Joystick rightStick; // set to ID 2 in DriverStation
CameraServer server;

public Robot() {
myRobot = new RobotDrive(0, 1);
myRobot.setExpiration(0.1);
leftStick = new Joystick(0);
rightStick = new Joystick(1);
server = CameraServer.getInstance();
server.setQuality(50);
//the camera name (ex "cam0") can be found through the roborio web interface
server.startAutomaticCapture("cam0");

}


/**
* Runs the motors with tank steering.
*/
public void operatorControl() {
myRobot.setSafetyEnabled(true);
while (isOperatorControl() && isEnabled()) {
myRobot.tankDrive(leftStick, rightStick);
Timer.delay(0.005); // wait for a motor update time


}

}
}
Reply With Quote
  #11   Spotlight this post!  
Unread 17-02-2015, 22:27
JacobD's Avatar
JacobD JacobD is offline
Registered User
AKA: Jacob
FRC #1672 (Mahwah Robo T-Birds)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2013
Location: New Jersey
Posts: 93
JacobD is an unknown quantity at this point
Re: Acceleration Curve java help

Code:
package org.usfirst.frc.team4640.robot;


import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;



public class Robot extends SampleRobot {
    RobotDrive myRobot;  // class that handles basic drive operations
    Joystick leftStick = new Joystick(0);  // set to ID 0 in DriverStation
    Joystick rightStick = new Joystick(1); // set to ID 1 in DriverStation
    CameraServer server;
    double leftStickVal,rightStickVal;
    
    public Robot() {
        myRobot = new RobotDrive(0, 1);
        myRobot.setExpiration(0.1);
        leftStick = new Joystick(0);
        rightStick = new Joystick(1);
        server = CameraServer.getInstance();
        server.setQuality(50);
        //the camera name (ex "cam0") can be found through the roborio web interface
        server.startAutomaticCapture("cam0");
            
    }

    
    /**
     * Runs the motors with tank steering.
     */
    public void operatorControl() {
        myRobot.setSafetyEnabled(true);
        while (isOperatorControl() && isEnabled()) {

                leftStickVal = Math.pow(leftStick.getY(),3);
                rightStickVal= Math.pow(rightStick.getY(),3);
 
        	myRobot.tankDrive(leftStickVal, rightStickVal);
            Timer.delay(0.005);		// wait for a motor update time
           
           
            }
        
        }
    }
Use this code exactly and your problem should be solved.
Reply With Quote
  #12   Spotlight this post!  
Unread 18-02-2015, 01:41
GeeTwo's Avatar
GeeTwo GeeTwo is online now
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,687
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Acceleration Curve java help

For those trying to learn from this thread, the non-whitespace differences between the intitial (21:04) and updated (21:27) code are:
Code:
# diff -w initial.txt updated.txt
14,15c14,15
< Joystick leftStick; // set to ID 1 in DriverStation
< Joystick rightStick; // set to ID 2 in DriverStation
---
>     Joystick leftStick = new Joystick(0);  // set to ID 0 in DriverStation
>     Joystick rightStick = new Joystick(1); // set to ID 1 in DriverStation
16a17
>     double leftStickVal,rightStickVal;
37c38,42
< myRobot.tankDrive(leftStick, rightStick);
---
>
>                 leftStickVal = Math.pow(leftStick.getY(),3);
>                 rightStickVal= Math.pow(rightStick.getY(),3);
>
>               myRobot.tankDrive(leftStickVal, rightStickVal);
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #13   Spotlight this post!  
Unread 18-02-2015, 23:27
Poseidon5817's Avatar
Poseidon5817 Poseidon5817 is offline
Founder and CEO, DeadMemes Studios
AKA: Mitchel Stokes
FRC #5817 (Uni-Rex)
Team Role: Mentor
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Clovis, CA
Posts: 403
Poseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud of
Re: Acceleration Curve java help

How about using Talon.setVoltageRampRate()? The only downside is it would also slow down deceleration, and I think it only works on CANTalons.
__________________
My FRC History:

2014 - Team 1671: Central Valley Regional Finalist and Chairman's Award Winner, Sacramento Regional Finalist, Archimedes Quarterfinalist
2015 - Team 1671: Central Valley Regional Semifinalist, Sacramento Regional Semifinalist and Chairman's Award Winner, Newton Winner, Einstein Winner
2016 - Team 5817: Central Valley Regional Finalist and Rookie All-Star, Orange County Regional Quarterfinalist and Rookie All-Star, Newton Division
2017 - Team 5817: Return of the bench grinder


Reply With Quote
  #14   Spotlight this post!  
Unread 18-02-2015, 23:48
vps vps is offline
Registered User
FRC #3021 (The Agency)
Team Role: Programmer
 
Join Date: Mar 2013
Rookie Year: 2011
Location: United States
Posts: 30
vps is an unknown quantity at this point
Re: Acceleration Curve java help

I wanted Can Motor controllers but we ended up using regular one. I was going to use the setVoltageRampRate function, because we are top heavy, but I had to create something else. The acceleration curve by Math.pow(val, x) wasn't good enough for us, where x is an int. Why? because if the joystick slips, we don't want the robot to rapidly accelerate. So, what I do is that I read the "ReachVal" from the joystick, then, read the "CurrentVal" from what I set to the CIMs (CurrentVal is initialized to 0). Then, I take the difference, divide that by 7500 (trial and error lead me to this constant), add that to "CurrentVal", in my drive thread. This results in a smooth drive and we don't topple over even though we are quite top heavy.

Hope that helps!

Last edited by vps : 18-02-2015 at 23:50.
Reply With Quote
  #15   Spotlight this post!  
Unread 19-02-2015, 00:51
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: Acceleration Curve java help

Quote:
Originally Posted by Poseidon1671 View Post
How about using Talon.setVoltageRampRate()? The only downside is it would also slow down deceleration, and I think it only works on CANTalons.
Quote:
Originally Posted by vps View Post
I wanted Can Motor controllers but we ended up using regular one. I was going to use the setVoltageRampRate function,
Quote:
Originally Posted by Ether View Post
If you are simply wanting to prevent driver "jackrabbit" starts and stops so the totes won't fall off the stack you are carrying, a simple solution would be to add a slew rate limiter to your joystick commands.
^^Here's the code for the above:

Code:

change = joystickAxis - limitedJoystickAxis;
if (change>limit) change = limit;
else if (change<-limit) change = -limit;
limitedJoystickAxis += change;

Quote:
Originally Posted by vps View Post
The acceleration curve by Math.pow(val, x) wasn't good enough for us, where x is an int. Why? because if the joystick slips, we don't want the robot to rapidly accelerate.
Exactly.


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

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