I am a programmer for my school's FRC robotics team and have received the request from our hardware/driving department to limit the speed at which the robot's motors can accelerate given a joystick input telling it to increase the speed of the motor. For example, when the robot first starts up and the driver decides to move the joystick from the center to the fully up position (0 to full motor power), we don't want it to literally go from 0 to full motor power in an instant - it obviously creates some rather jerky, unstable behavior. How might I receive the target joystick position from the joystick, save it, and build up to it over time (and if any other inputs are sent in this process — like telling it to turn around — stop the current process and enact the new one)?

I am using Java with WPILib's 2016 robotics library: here's the API http://first.wpi.edu/FRC/roborio/release/docs/java/, and here's the tutorials http://wpilib.screenstepslive.com/s/4485/m/13809.

I am using the "IterativeRobot" template class, and teleop is being run in the method teleopPeriodic(), which is continuously called every few milliseconds in the program (it's where i'm receiving joystick input and calling the method RobotDrive.tankDrive() with the inputs).

I realize this is more of a programming question than a robotics question, but I figured it would be better to put it here than in stack overflow, etc. If someone could give me some simple pseudocode or just a conceptual idea of how this might be done (not necessarily as it pertains directly to the library or the language I'm using), that would be great.

  • $\begingroup$ Welcome to robotics Nick, but I'm afraid that it is not clear what you are asking. We prefer practical, answerable questions based on actual problems that you face, so it is a good idea to include details of what what you would like to achieve, what you have tried, what you expected to see and what you actually saw. Take a look at How to Ask and tour for more information on how stack exchange works. If you edit your question to make it more clear, flag it for moderator attention and we can reopen it for you. $\endgroup$ – Mark Booth Jan 31 '16 at 14:43

Well without knowing any of the libraries you are using I suggest using a low-pass filter on your input signal.
Let's assume you fill use a standard filter of first order with a time coefficient of 0.1seconds (meaning in 0.1 seconds 68% or your input change was send to the output and in 0.5 seconds the input is switched to 99.9% to you output) and your are reading those the joystick every 10ms, then your filter will look like this: $$G_z=\frac{0.09516}{(z-0.9048)}$$. or: $$y_k=0.09516 \cdot u_{k} + 0.9048 \cdot y_{k-1}$$ Transformed into code this is something like this:

double GetPositionFiltered(double RawValueReadFromHw){
  static double OutputOld=0;
  double FilteredPosition = 0.09516*RawValueReadFromHw-0.9048*OutputOld;
  return FilteredPosition;
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.