Hi, we are a rookie team trying to limit the range of our robotic arm in java. We have a PG188 gear motor with an encoder moving the arm. We want to have a joystick control the arm between a certain range of values, letâs say from 15 to 200 according to the encoder. We want to prevent it from going outside that range though. Any simple ways to do this through java, or is this a more advanced problem?
We were starting with something like:
{
armMotor.set(armStick.gety());
If (armPosition.get() <15) {armMotor.stopMotor}
If (armPosition.get() >200){armMotor.stopMotor}
}
All we accomplished was temporary movement and then lockdown. We could really use some help as we have no programming mentors or experience.
Youâre 90% of the way there. What you want to do is not stop the motor entirely if the arm is outside a range, but instead stop it moving in that direction.
Let me know if you need help with the implementation of this.
One way to solve this problem is to think about your problem differently. Right now, your code reflects the thinking: âWhen do I stop the motion of my arm?â Instead, I encourage you to think about: âUnder what conditions should my arm be moving forward? Under what conditions should my arm be moving backwards?â
This reminds me of a silly book I read as a kid. I think it was Captain Underpants. It told of a school with two elevators. One elevator could only go up, and the other elevator could only go down. The elevators worked exactly once, and never worked again. Nobody could figure out why.
Wayside School. Also, when going up the stairs you must go up the right side, and when going down you must go down the left side in order to avoid collisions
Are you using a Talon SRX to control the arm? You can set up a soft limit so that the Talon wonât let the encoder get higher than a certain value.
Soft limits are going to follow a lot of the same characteristics as we are talking about over in your thread. I donât use them but you donât supply any values. The values and monitoring is all taken care of in the SRX just like the hardwired switches.
There is a forward soft limit and a reverse soft limit.
If the forward limit is triggered, it will stop the motor from moving forward
only, reverse will still be allowed.
If the reverse soft limit is triggered, it will stop the motor from moving in reverse only, forward will still be allowed.
For setting up the softlimit, it depends if you are using the encoder in the Quadrature mode or Pulse Width mode. You would set this when you tell the talon what feedback device.
Java:
/* Relative mode -- use quadrature value */
talon.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative, 0, 0);
/* Absolute mode -- use pulse width value */
talon.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Absolute, 0, 0);
C++:
/* Relative mode -- use quadrature value */
talon.ConfigSelectedFeedbackSensor(FeedbackDevice::CTRE_MagEncoder_Relative, 0, 0);
/* Absolute mode -- use pulse width value */
talon.ConfigSelectedFeedbackSensor(FeedbackDevice::CTRE_MagEncoder_Absolute, 0, 0);
The magnetic encoders can be used as relative (quadrature) OR absolute (pulse width). Most of the time youâll want to stick to one of the modes per encoder to avoid confusion. Maybe an arm would be better suited to absolute, but a drivetrain wheel would be better suited to relative.
While testing last night, we connected switches to the Talon SRX breakout board and it stoped the motor just like we wanted⌠no code just hard limit switch⌠planning on using on our elevatorâŚ
If i want to use roller arm limit switch, any recommendations on good one to use, specifc voltage and other specs to look for?
The difference between a soft limit and a regular limit is that a soft limit is in 'softâware. Thus, it uses an encoder value and not an actual hardware limit switch. What you used is a hard limit switch, as in, a 'hardâware limit switch. A soft limit does not refer to a limit switch that is plugged into a Talon SRX. It only refers to a âsimulatedâ limit switch that actually uses an encoder. Hope that makes sense.
That being said, any standard, momentary switch that changes from open to closed (or vice versa) when something gets pressed will work. I am not sure what voltage the Talons use, but generally the switch will not need any power. The Talon provides the voltage that it needs to be able to read the state of the switch.
Ok thanks for clearing that up for others reading along here. I too fall in the trap sometimes that I assume that when I say soft limits everyone knows it software limits and hard limits means hardware limits. Plus I tend to take short cuts when using my phone to reply and chat.
One thing I will caution you is that even with soft and hard limits, you want to take into account what will happen if your motor hits the limit at high speed (and possibly high torque, depending on your gearbox). You might still want to move your mechanism (such as your arm or lift) using closed-loop position control (PID) in order for it to apply a deceleration factor as it approaches the end stop.
Otherwise, this is what happens: your mechanism travels at high speed, carrying with it momentum from the weight of the mechanism (and possibly assisted by gravity, as in the case of a lift moving downwards). You reach the soft or hard limit. The limit switch gets clicked. At some point in the next few milliseconds, the software/firmware detects the limit switch, and turns the motor off. However, for that split second, the motor is still spinning, and the mechanism is still moving. The mechanism will slam into whatever physical barrier is behind the limit switch. If that is a hard stop, then huge forces will be applied to your belts and pulleys as everything grinds to a halt.
We broke far too many belts while we were writing and debugging our lift software, which uses a physical limit switch on the bottom end, a soft limit at the top end, and Talon position control to move the lift to any point and stay there. We adjusted the âPâ and âDâ constants so that when moving, there is a nice deceleration at the end. There are separate sets of PID constants for upward motion and downward motion (assisted by gravity).