Dual Brushless Motor ESC, 10-62V, up to 50A per motor. Motors ganged or independent, multiple control input methods, cycle-by-cycle current limit, speed mode and torque mode control. Motors tiny to kW. Speed limit and other parameters easily set in firmware. As used in 'The Brushless Brutalist' locomotive - www.jons-workshop.com. See also Model Engineer magazine June-October 2019.
Dependencies: mbed BufferedSerial Servo PCT2075 FastPWM
Update 17th August 2020 Radio control inputs completed
Radio_Control_In.cpp@11:bfb73f083009, 2019-01-19 (annotated)
- Committer:
- JonFreeman
- Date:
- Sat Jan 19 11:45:01 2019 +0000
- Revision:
- 11:bfb73f083009
- Child:
- 12:d1d21a2941ef
Tidied class parameter passing, serial problem fixed (was hardware)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JonFreeman | 11:bfb73f083009 | 1 | #include "mbed.h" |
JonFreeman | 11:bfb73f083009 | 2 | #include "BufferedSerial.h" |
JonFreeman | 11:bfb73f083009 | 3 | #include "Radio_Control_In.h" |
JonFreeman | 11:bfb73f083009 | 4 | /**class RControl_In |
JonFreeman | 11:bfb73f083009 | 5 | Jon Freeman |
JonFreeman | 11:bfb73f083009 | 6 | Jan 2019 |
JonFreeman | 11:bfb73f083009 | 7 | |
JonFreeman | 11:bfb73f083009 | 8 | Checks for __-__ duration 800-2200us |
JonFreeman | 11:bfb73f083009 | 9 | Checks repetition rate in range 5-25ms |
JonFreeman | 11:bfb73f083009 | 10 | */ |
JonFreeman | 11:bfb73f083009 | 11 | extern BufferedSerial pc; |
JonFreeman | 11:bfb73f083009 | 12 | |
JonFreeman | 11:bfb73f083009 | 13 | // RControl_In::RControl_In () { // Default Constructor |
JonFreeman | 11:bfb73f083009 | 14 | // pulse_width_us = period_us = pulse_count = 0; |
JonFreeman | 11:bfb73f083009 | 15 | // lost_chan_return_value = 0.0; |
JonFreeman | 11:bfb73f083009 | 16 | // } ; |
JonFreeman | 11:bfb73f083009 | 17 | // RControl_In::RControl_In (PinName inp) : pulse_in(inp) { // Default Constructor |
JonFreeman | 11:bfb73f083009 | 18 | // pulse_width_us = period_us = pulse_count = 0; |
JonFreeman | 11:bfb73f083009 | 19 | // lost_chan_return_value = 0.0; |
JonFreeman | 11:bfb73f083009 | 20 | // } ; |
JonFreeman | 11:bfb73f083009 | 21 | /** |
JonFreeman | 11:bfb73f083009 | 22 | */ |
JonFreeman | 11:bfb73f083009 | 23 | void RControl_In::set_lost_chan_return_value (double d) { |
JonFreeman | 11:bfb73f083009 | 24 | lost_chan_return_value = d; |
JonFreeman | 11:bfb73f083009 | 25 | } |
JonFreeman | 11:bfb73f083009 | 26 | |
JonFreeman | 11:bfb73f083009 | 27 | uint32_t RControl_In::pulsewidth () |
JonFreeman | 11:bfb73f083009 | 28 | { |
JonFreeman | 11:bfb73f083009 | 29 | return pulse_width_us; |
JonFreeman | 11:bfb73f083009 | 30 | } |
JonFreeman | 11:bfb73f083009 | 31 | |
JonFreeman | 11:bfb73f083009 | 32 | uint32_t RControl_In::pulsecount () |
JonFreeman | 11:bfb73f083009 | 33 | { |
JonFreeman | 11:bfb73f083009 | 34 | return pulse_count; |
JonFreeman | 11:bfb73f083009 | 35 | } |
JonFreeman | 11:bfb73f083009 | 36 | |
JonFreeman | 11:bfb73f083009 | 37 | uint32_t RControl_In::period () |
JonFreeman | 11:bfb73f083009 | 38 | { |
JonFreeman | 11:bfb73f083009 | 39 | return period_us; |
JonFreeman | 11:bfb73f083009 | 40 | } |
JonFreeman | 11:bfb73f083009 | 41 | |
JonFreeman | 11:bfb73f083009 | 42 | bool RControl_In::validate_rx () |
JonFreeman | 11:bfb73f083009 | 43 | { // Tests for pulse width and repetition rates being believable |
JonFreeman | 11:bfb73f083009 | 44 | return !((period_us < 5000) || (period_us > 25000) || (pulse_width_us < 800) || (pulse_width_us > 2200)); |
JonFreeman | 11:bfb73f083009 | 45 | } |
JonFreeman | 11:bfb73f083009 | 46 | |
JonFreeman | 11:bfb73f083009 | 47 | double RControl_In::normalised () { |
JonFreeman | 11:bfb73f083009 | 48 | if (!validate_rx()) { |
JonFreeman | 11:bfb73f083009 | 49 | pc.printf ("Invalid RCin\r\n"); |
JonFreeman | 11:bfb73f083009 | 50 | return lost_chan_return_value; // ** WHAT TO RETURN WHEN RC NOT ACTIVE ? ** This is now user settable |
JonFreeman | 11:bfb73f083009 | 51 | } // Defaults to returning 0.0, user should call set_lost_chan_value (value) to alter |
JonFreeman | 11:bfb73f083009 | 52 | double norm = (double) (pulse_width_us - 1000); // left with -200 to + 1200 allowing for some margin |
JonFreeman | 11:bfb73f083009 | 53 | norm /= 1000.0; |
JonFreeman | 11:bfb73f083009 | 54 | if (norm > 1.0) |
JonFreeman | 11:bfb73f083009 | 55 | norm = 1.0; |
JonFreeman | 11:bfb73f083009 | 56 | if (norm < 0.0) |
JonFreeman | 11:bfb73f083009 | 57 | norm = 0.0; |
JonFreeman | 11:bfb73f083009 | 58 | return norm; |
JonFreeman | 11:bfb73f083009 | 59 | } |
JonFreeman | 11:bfb73f083009 | 60 | |
JonFreeman | 11:bfb73f083009 | 61 | void RControl_In::RadC_rise () // December 2018 - Could not make Servo port bidirectional, fix by using PC_14 and 15 as inputs |
JonFreeman | 11:bfb73f083009 | 62 | { |
JonFreeman | 11:bfb73f083009 | 63 | period_us = t.read_us (); |
JonFreeman | 11:bfb73f083009 | 64 | t.reset (); |
JonFreeman | 11:bfb73f083009 | 65 | t.start (); |
JonFreeman | 11:bfb73f083009 | 66 | } |
JonFreeman | 11:bfb73f083009 | 67 | |
JonFreeman | 11:bfb73f083009 | 68 | void RControl_In::RadC_fall () |
JonFreeman | 11:bfb73f083009 | 69 | { |
JonFreeman | 11:bfb73f083009 | 70 | pulse_width_us = t.read_us (); |
JonFreeman | 11:bfb73f083009 | 71 | pulse_count++; |
JonFreeman | 11:bfb73f083009 | 72 | } |
JonFreeman | 11:bfb73f083009 | 73 | // end of RControl_In class |