|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Automatic 2 Speed Drivetrain Shifting Code
I've been looking into automatic drivetrain shifting code. I've found this thread pretty helpful so far, specifically
apalrd's post. I've basically been looking all over this search. I've also found 254's driving code here and here, but I just don't know enough C++ to understand exactly how it works (or if it even auto-shifts! - I was told that they do but I can't find where it happens). Anyways, I'm just looking for some kind of rundown on how exactly you'd determine whether to shift up or down. So far I've come up with this: Code:
if (input > shiftersInputThreshhold && m.encoder.getRate() > shiftersSpeedThreshhold
// Make sure not to shift too much
&& (System.currentTimeMillis() - lastShift) > shiftersShiftTimeLimit * 1000) {
m.gearShifterController.setSecondGear();
lastShift = System.currentTimeMillis();
} else {
m.gearShifterController.setFirstGear();
}
My goal here is for it to shift when the robot is going fast enough that it needs to, and have enough torque to push others around. Oh and one last thing, should shifting take turning into account? Right now that's a little bit difficult to do with my code (for implementation reasons). What benefit would something like this Code:
if(abs(turn) > 0) doNotShiftGears() |
|
#2
|
|||
|
|||
|
Re: Automatic 2 Speed Drivetrain Shifting Code
Here is how we implemented auto shifting this year. It seemed to work well but we decided we wanted to be able to manually control our shifting due to interlocking that we implemented between the chassis and other systems.
https://github.com/runnymederobotics...b232a55ebd?w=1 |
|
#3
|
||||
|
||||
|
Re: Automatic 2 Speed Drivetrain Shifting Code
We've never used one in competition, but I have a basic idea of how to get started. It's helpful to have a simple functions that approximates the fps of each joystick value. You want to be continuously checking for certain parameters that would cause shifting, so set up code to measure the speed of the wheels and also the acceleration. You need to make sure that you wait 1 second between shifts, and that you don't end up shifting while the driver is turning. The most useful is if somebody starts pushing you, and you need to shift to the slow gear to push them away. This can be detected if the actual speed of the robot is >10% away from where the joysticks are and if the average deceleration over the last second or so exceeds a certain amount. The problem with this is when the drivers hit a wall, it shifts into high gear and wears down the gear. Also, I've never tried it, but it may be possible to reach the max speed faster if you start in one gear, then shift up. If you want to try this, I would try starting with code that puts you in your slow gear when you are traveling slowly, and something that puts you in high gear if it detects that the driver has commanded a speed faster than a certain constant.
|
|
#4
|
||||
|
||||
|
Re: Automatic 2 Speed Drivetrain Shifting Code
Quote:
Also why did you multiply Constants.AUTO_SHIFT_DOWN_THRESHOLD.get() * Constants.CHASSIS_MAX_LOW_ENCODER_RATE.get() ? The code makes sense, but I don't think it does exactly what we'd like. Thanks for sharing though. |
|
#5
|
|||
|
|||
|
Re: Automatic 2 Speed Drivetrain Shifting Code
Quote:
We did that second part because our AUTO_SHIFT_THRESHOLD variables are meant to be percentages of our max low speed. No problem. The way that we were able to distinguish between driving straight and rotating was by taking the average encoder rate. This way when you turn, rate will be around 0 and would shift to low gear. |
|
#6
|
||||
|
||||
|
Re: Automatic 2 Speed Drivetrain Shifting Code
Makes sense. I'm curious, how long / how many samples did you use for calculating the average?
|
|
#7
|
||||
|
||||
|
Re: Automatic 2 Speed Drivetrain Shifting Code
Quote:
Also, is it bad to shift up if it is turning, but going forwards as well? (ie. +0.7 speed, -0.4 turn) |
|
#8
|
|||
|
|||
|
Re: Automatic 2 Speed Drivetrain Shifting Code
Quote:
About shifting up on a curve, it depends on how well your robot turns in high gear. Our robot doesn't turn well in high gear so shifting up in the middle of a curve just results in the robot driving mostly straight. |
|
#9
|
|||
|
|||
|
Re: Automatic 2 Speed Drivetrain Shifting Code
We don't auto shift. In fact we barely ever shift out of high gear in teleop. This year we are using low gear for autonomous and last year we used it to auto align to the goal, but these states were explicitly set.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|