Here's a new script with current sensor and sensorless compensation. If set to UseCurrentSensors = TRUE, it tests for sensor faults in two circumstances:
(1) At startup. If there's a fault at startup, there'll be no motor compensation. This gives a very obvious, and pretty unpleasant, driving feel to let you know that there's a problem, but it will let you get home to work on fixing it.
(2) When running. If there's a fault once MainLoop has been entered, it just switches to sensorless compensation. This may not even feel significantly different (except on the bot) until the next time you start the unit - at which point it will do (1) above. If the fault is momentary, it will actually go right back to sensor compensation.
The attached script is configured for the mobot. I will post a generic analog version along with the full CANbus files to the cloud, but I'm still slogging through getting and checking all the software and hardware files for that. To tune this, I suggest the following procedure.
(1) Set to UseCurrentSensors = TRUE and increase MotorResistance in the usual way until there's a hint of instability, and then turn it back a bit. Do only forward and backward moves at first, then add turning (except turn-in-place) and obstacles and check for stable behavior over the full speed range.
(2) If there's any difference between acceleration at low speeds and acceleration at mid through high speeds, add a bit of LoadBoost_D to get snappier low speed acceleration. You may have to lower Acceleration and Deceleration as you increase LoadBoost_D.
(3) Now check turn-in-place. If starting a turn-in-place is balky, add some CompTurnBoost. Then re-check for over-compensation when going straight and reduce MotorResistance if necessary.
(4) Now, switch it to UseCurrentSensors = FALSE and check for balkiness in initial movement, both straight forward and backwards and for turn-in-place. If starting movement is iffy, add a bit of LowIBoost - just enough so that it starts moving better. As before, you won't have any load compensation under ca. PWM = 100, but this will help it get off the blocks.
If you want to check out the sensor fault detection, here's how to do so.
(1) If you can easily disconnect a sensor output (or pull it to ground through a 5K resistor to keep current to 0.5 mA), do that before startup and there should be no motor compensation. Then leave the sensor connected and not pulled down during startup, but disconnect it or pull it down after the script is running, and you should get sensorless compensation.
(2) If creating a physical fault isn't convenient, you can fake it in the script.
To fake a fault before startup, look in the script before MainLoop: for the line:
- Code: Select all
IF (abs(ILeft) > 20) OR (abs(IRight) > 20) THEN
and just before that add a line that says:
- Code: Select all
ILeft = 100
There should be no motor compensation.
Now delete that added line, and check for fault detection while running. Go to the FindSensorCurrents: subroutine and look for the line:
- Code: Select all
M1Power = GetValue(_MOTPWR,1)
and just before that add:
- Code: Select all
ILeft = 100
This will make it do sensorless compensation even though set to UseCurrentSensors=TRUE.
Of course, when done, get rid of the ILeft = 100 line to get back to normal operation.