Rover: add support for L298N dual H-Bridge motor driver
The L298N H-bridge requires two pins to control the direction of each motor. http://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-control-tutorial-l298n-pwm-h-bridge/
I'm not sure how common this motor driver is but we could add support for this by using an extra relay pin for each motor. The output for the extra relay pins could probably always just be the inverse of the existing pins although it's possible we might want to set both pins to the same value if we know we want the motor to stop (i.e. the vehicle is disarmed or input throttle is zero).
This request comes from this thread on discourse: https://discuss.ardupilot.org/t/radiolink-pixhawk-ardurover-and-l298n-h-bridge/25228
it's very common, and it's the base driver motor for all common 3D printers like mendel model and with sanguinololu boards.
hello,brushed with relay already use relay 0 and 1, so this controler is already supported !
the motor brake feature isn't implemented thus. (aka both relay on 0)
TB6612 need two relay_pin too
Hello, Can you give the wiring diagram for connecting the L298N Dual H-Bridge motor driver to Pixhawk?
@khancyr How do I configure the relay pins to use the L298N motor driver?
See my comment on this thread: https://discuss.ardupilot.org/t/radiolink-pixhawk-ardurover-and-l298n-h-bridge/25228/10?u=ebaker310
I just encountered the same issue and I'd appreciate if those kind of ESCs would be supported.
Those kind of H-Bridge drivers are quite common.
@SatishAkula91 They are basically "Normal (PWM)" type using 2 PWM output signals. One for forward and one for reverse. (Both outputs should not be high at the same time). I'm using Skid Steering so I have 2 Motors. That would be something like:
- SERVO1_FUNCTION ForwardThrottleLeft
- SERVO2_FUNCTION BackwardsThrottleLeft
- SERVO3_FUNCTION ForwardThrottleRight
- SERVO4_FUNCTION BackwardsThrottleRight
I'm slightly confused. While I see why @khancyr says that these kind of controllers are already supported, I still don't get it to run since SERVOx_MIN output is limited to 800 as minimum, but those controllers need 0 as minimum. With 800, the motor is spinning at 0% throttle.
Am I doing something wrong?
@heeplr , hello,
You need to set the PWM_TYPE to BrushedWithRelay ! https://ardupilot.org/rover/docs/parameters.html#mot-pwm-type-motor-output-pwm-type
I did that (and rebooted) and still SERVO1_MAX has a valid range of 500 to 2200 (not 800 as written above). I tried rover v3.5.2 and 4.0.0.
on PWM the output is a real pwm not a rcpwm, so we don't care about SERVOx_MIN/MAX. Those are hard setted to 1000 - 2000 for easier calculation and do 0 - 100% duty cycle mapping !
ok, i'm one step closer. @khancyr thanks a lot for clarifying and thus saving me a ton of time troubleshooting.
After I did a factory reset, I get 0-100% duty cycle mapping. (The 0% throttle position is very very small, though. So the Motor only stops spinning when the throttle is exactly at the right position and even slight touches starts running it.)
But now i'm struggling with relays. There are two Problems:
- according to http://ardupilot.org/rover/docs/common-brushed-motors.html the Relay can be assigned to an AUX Pin, but it only works with my Pixhawk 2.4.8 when I use AUX Pin 6 and AUX Pin 5. Is this an issue of my hardware or an issue with the wiki?
- Most importantly: There seems to be only one relay supported but H-Bridges need 2 Pins: Forward: Relay 1 must be HIGH, Relay 2 must be LOW Reverse: Relay 1 must be LOW, Relay 2 must be HIGH
I tried the remaining Relay Pins, but they don't seem to change. Is this already supported by ardupilot and I'm doing it wrong (again)? If it isn't, what would be a good way to implement it? (I found https://github.com/ArduPilot/ardupilot/blob/master/Rover/AP_MotorsUGV.cpp but i'm not sure what's exactly needed to cleanly implement a second relay pin that's an inverted version of the first one.)
Hi @heeplr if you are using rover, you can take a look on this branch - https://github.com/juvinski/ardupilot/tree/RoverBridgeDualRelayPins I create a DualRelaypins and the logic of the outputs are working as expected.
BTW, you can use the RCX_DZ to set a dead zone bigger and the middle point will be more easy to control.
@juvinski Cool, thank you! Your BrushedWithTwoRelays solution would be exactly what's needed.
I'm having trouble testing it, tho. (Something seems wrong with my build environment since compiled fmuv3 images don't boot - no tone, status LED stays off after FMU B/E LED stops blinking. The downloaded images work fine.)
I'll keep trying and report my findings here.
hi @heeplr ,
what kernel version are you using ?
you mean ChibiOS version or linux kernel? how to find out? i tried most recent master (recursive clone) and older versions. I gathered some build output of an older version here: https://gist.github.com/heeplr/5e34b64db7c73d4f6c9f7b5a12b53920 ... it always ends up with the same error.
Hi @heeplr I was thinking you was using beaglebone. Sorry but chibios I don't know.
@juvinski thanks anyway
@juvinski I got it running. Works like a charm. (I'm still struggling with conflicting AUX pins when using wheel encoders but that's another issue.)
Any chance for this to be merged into master as a pull request?
Hi @heeplr
I create a or for that but after some discussions https://github.com/ArduPilot/ardupilot/pull/14007