@jwetzel1492 - How many motors are in your cc engine? I see the one.
Originally that engine (an early 2000s rs-3) only had a single powered truck. But I’ve collected a lot of spare parts, so it now has two powered trucks.
Now, with some conventional locos I’ve modified to have dual powered trucks, I’ve been able to get better low speed performance and torque by running the 2 can motors in series. But I haven’t been able to get that to work when they’re hooked up to one of these PWM motor controllers. If they’re in series, only one of them will turn. So I have to run them in parallel.
@jwetzel1492 - For your speed control, did you add any acceleration limit? That is to say, if you chose 45 mph right off the bat, did you target "45 mph" on the motors immediately (via PID)? I know MTH has a constant acceleration limit but I was thinking of something more meaningful that would simulate less acceleration at low speeds. (ds/dt = f(s)) instead of (ds/dt = c) or even (ds/dt = f(t)); Unfortunately, my desired customizable f(s) doesn't have a closed form integral solution unless I can come up with something along the lines of (ds/dt = 1/f(s)) so that (f(s)ds = dt).
@A. Wells - In my code, there are 2 systems before we get to actually controlling the motor speed:
1. Control Model
2. PID Controller
Control Model Inputs:
Control Model Outputs:
- Engine RPMs (which is used by my sound algorithm)
- Desired Wheel RPMs
- Smoke percentage
- Desired Wheel RPMs
- Measured Wheel RPMs
- Speed value that is sent to the motor driver
I've implemented a couple different "Control Models". The simplest is the ToyControlModel. It only uses the Throttle and Reverser, and the Engine RPMs and DesiredWheelRPMs are just linear with respect to Throttle. It's just like using a conventional transformer. (Except that it goes through the PID controller too, so there's speed control, and the PID takes care of the non-linearity of the motor driver and can motors.) The PID does smooth out the acceleration, but it can still make pretty quick changes in speed.
But I've also implemented a SimulatorControlModel. While I've never driven a real locomotive, I have some experience with Train Simulator, and a background in physics. So the SimulatorControlModel tries to model some of the hardware inside a real locomotive, as well as some of the physics. So it's modeling:
- Rate for the prime mover to spin up
- reverser and how much power the traction motors can deliver
- rolling resistance
- air resistance
- how much smoke should be generated for a given engine rpm
I'm learning as I go and I'm sure some of my equations aren't perfect, but I'm trying to get it to generally behave like a real train.
That's way outside of my league! I'm approaching the movement from an aesthetics point of view...not whether it models the physical motion aspects of a real train. My patience would be gone in a matter of a few minutes if I was to take on that task.
I have previous motion control work where I just use a time based S curve for motor control (start point, stop point) which worked surprisingly well even with an 8 bit microcontroller. As mentioned earlier, I introduced feedback based on the current speed of the locomotive. I've since modified the concept and introduced time into the feedback: (ds/dt = f(s,t) or ds/dt = f(s)g(t)). In my case, g(t) is a constant c which is the number of times per second I update the motor speed. So, once again, I'm off the hook on any elaborate separation of variable or partial integration. I may not have mentioned f(s) is a cubic bezier curve (aka polynomials). This allows me to update the curve to my hearts content based only on four points. Quick changes in speed only happen at higher speeds in my logic and the maximum speed change is also limited. (This may have to be adjusted for negative speed changes.)
I have three speeds that I track: actual speed, current target speed, final target speed. On paper, I have made notes to use any difference between the actual speed and the target speed to induce labor/drift sound and, like you, to use the actual speed for rpm. (I have no plans to introduce sound into the system any time soon.)
The one thing that concerned me with your set-up is that you only have 4 detents/indexes per axial revolution. Doesn't this result in jerking at low speed?
@A. Wells The 4 detents per rev hasn't been a big issue. At it's slowest, my engine axles are doing about 90 rpms. So a magnet goes past my Hall detector about every 160ms. And I run a low-pass filter over the measured rpms before using them. If the train is on straight track, the measured rpms stay pretty close to constant.
My biggest issue right now is I'm stretching the limits of the gearing/traction of these particular powered trucks. I'd love to run even slower, but then bends in the track or other random friction can cause the can motors to come to a halt. (And faster than even a PID can compensate for.)
One of my next projects is to put my boards in an RMT Beep. The low-speed gearing on those is spectacular. (But I'll have to do some miniaturization on my protoboard. Very limited space inside a Beep. I might not be able to fit a tachometer inside a Beep either. But again, their low gearing might make a PID controller unnecessary.)