|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Acceleration Curve java help
Hey does anyone know how to program an acceleration curve for cim motors??
|
|
#2
|
|||||
|
|||||
|
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. |
|
#3
|
||||
|
||||
|
Re: Acceleration Curve java help
Quote:
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. |
|
#4
|
||||
|
||||
|
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()); 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. |
|
#5
|
||||
|
||||
|
Re: Acceleration Curve java help
Quote:
You might also caution that your suggestion maps the domain -1..+1 to the range 0.769..1.3 |
|
#6
|
||||
|
||||
|
Re: Acceleration Curve java help
Quote:
Code:
Joystick stick1, stick2; double stick1val,stick2val; stick1val = Math.pow(stick1.getX(),3); stick2val = Math.pow(stick2.getY(),3); chassis.tankDrive(stick1val, stick2val); Last edited by JacobD : 17-02-2015 at 19:16. |
|
#7
|
|||
|
|||
|
Re: Acceleration Curve java help
We are trying to fix the automatic jump the robot gets as soon as you move the joysticks.
|
|
#8
|
||||
|
||||
|
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); Code:
double magnitude = Math.pow(driveStick.getMagnitude(),3); chassis.mecanumDrive_Polar(magnitude, driveStick.getDirectionDegrees(), driveStick.getRotationDirection()); |
|
#9
|
|||||
|
|||||
|
Re: Acceleration Curve java help
Quote:
Quote:
|
|
#10
|
|||
|
|||
|
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 } } } |
|
#11
|
||||
|
||||
|
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
}
}
}
|
|
#12
|
|||||
|
|||||
|
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); |
|
#13
|
|||
|
|||
|
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. |
|
#14
|
||||
|
||||
|
Re: Acceleration Curve java help
Quote:
Quote:
Quote:
Code:
change = joystickAxis - limitedJoystickAxis; if (change>limit) change = limit; else if (change<-limit) change = -limit; limitedJoystickAxis += change; Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|