Electric Locomotive control system. Touch screen driver control, includes regenerative braking, drives 4 brushless motors, displays speed MPH, system volts and power
Dependencies: BSP_DISCO_F746NG FastPWM LCD_DISCO_F746NG SD_DISCO_F746NG TS_DISCO_F746NG mbed
Electric_Loco.h@1:8ef34deb5177, 2017-11-13 (annotated)
- Committer:
- JonFreeman
- Date:
- Mon Nov 13 09:53:00 2017 +0000
- Revision:
- 1:8ef34deb5177
Brushless Motor electric locomotive congtrol system; Drives 4 motors using touch-screen control.; Displays speed MPH, system volts and power
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JonFreeman | 1:8ef34deb5177 | 1 | /* Updated 12 Nov 2017 |
JonFreeman | 1:8ef34deb5177 | 2 | Jon Freeman |
JonFreeman | 1:8ef34deb5177 | 3 | |
JonFreeman | 1:8ef34deb5177 | 4 | 5" and 7.25" gauge Electric Locomotive Controller - ST DISCO-F746NG |
JonFreeman | 1:8ef34deb5177 | 5 | Uses built in display and touch screen. |
JonFreeman | 1:8ef34deb5177 | 6 | |
JonFreeman | 1:8ef34deb5177 | 7 | Display shows 'analogue' moving coil meter movements for : |
JonFreeman | 1:8ef34deb5177 | 8 | Locomotive speed Miles per Hour |
JonFreeman | 1:8ef34deb5177 | 9 | System voltage (range 20v - 90v or thereabouts) |
JonFreeman | 1:8ef34deb5177 | 10 | Power Watts delivered to drive motors. |
JonFreeman | 1:8ef34deb5177 | 11 | |
JonFreeman | 1:8ef34deb5177 | 12 | Touch screen has three 'buttons', these are currently unused, and are where the meter movements show. |
JonFreeman | 1:8ef34deb5177 | 13 | Idea is to use two for two horns, |
JonFreeman | 1:8ef34deb5177 | 14 | |
JonFreeman | 1:8ef34deb5177 | 15 | Display has 'slider' touch control. This drives the loco. |
JonFreeman | 1:8ef34deb5177 | 16 | Control in central position when not driving or drfting. |
JonFreeman | 1:8ef34deb5177 | 17 | Moving towards bottom of screen applies regenerative braking - move further down applies harder braking. |
JonFreeman | 1:8ef34deb5177 | 18 | Moving towards top of screen powers drive motors, move further up applies more torque (current controller implemented) |
JonFreeman | 1:8ef34deb5177 | 19 | Take finger off and control drifts down to central 'neutral' position. |
JonFreeman | 1:8ef34deb5177 | 20 | */ |
JonFreeman | 1:8ef34deb5177 | 21 | #define MAX_TOUCHES 6 // Touch screen can decode up to this many simultaneous finger press positions |
JonFreeman | 1:8ef34deb5177 | 22 | #define NEUTRAL_VAL 150 // Number of pixels |
JonFreeman | 1:8ef34deb5177 | 23 | |
JonFreeman | 1:8ef34deb5177 | 24 | #define SLIDERX 418 // slider graphic x position |
JonFreeman | 1:8ef34deb5177 | 25 | #define SLIDERY 2 // slider graphic y position |
JonFreeman | 1:8ef34deb5177 | 26 | #define SLIDERW 50 // pixel width of slider |
JonFreeman | 1:8ef34deb5177 | 27 | #define SLIDERH 268 // pixel height of slider |
JonFreeman | 1:8ef34deb5177 | 28 | |
JonFreeman | 1:8ef34deb5177 | 29 | // To get speedo reading correctly, need to use correct gear ratio and wheel size info |
JonFreeman | 1:8ef34deb5177 | 30 | //#define BOGIE_5_INCH |
JonFreeman | 1:8ef34deb5177 | 31 | #define BOGIE_7_and_a_quarter_INCH |
JonFreeman | 1:8ef34deb5177 | 32 | |
JonFreeman | 1:8ef34deb5177 | 33 | const int |
JonFreeman | 1:8ef34deb5177 | 34 | |
JonFreeman | 1:8ef34deb5177 | 35 | NUMBER_OF_MOTORS = 4, // 1 to 6 motors |
JonFreeman | 1:8ef34deb5177 | 36 | |
JonFreeman | 1:8ef34deb5177 | 37 | BUTTON_RAD = (SLIDERW / 2) - 4, // radius of circular 'knob' in slider control |
JonFreeman | 1:8ef34deb5177 | 38 | MIN_POS = BUTTON_RAD + 5, // top of screen |
JonFreeman | 1:8ef34deb5177 | 39 | MAX_POS = SLIDERH - (BUTTON_RAD + 1), // bottom of screen |
JonFreeman | 1:8ef34deb5177 | 40 | CIRC_CTR = SLIDERX + BUTTON_RAD + 4; |
JonFreeman | 1:8ef34deb5177 | 41 | |
JonFreeman | 1:8ef34deb5177 | 42 | static const double |
JonFreeman | 1:8ef34deb5177 | 43 | #ifdef BOGIE_7_and_a_quarter_INCH |
JonFreeman | 1:8ef34deb5177 | 44 | MOTOR_PINION_T = 17.0, // motor pinion teeth, wheel gear teeth and wheel dia required to calculate speed and distance. |
JonFreeman | 1:8ef34deb5177 | 45 | WHEEL_GEAR_T = 76.0, |
JonFreeman | 1:8ef34deb5177 | 46 | WHEEL_DIA_MM = 147.0, |
JonFreeman | 1:8ef34deb5177 | 47 | #endif |
JonFreeman | 1:8ef34deb5177 | 48 | #ifdef BOGIE_5_INCH |
JonFreeman | 1:8ef34deb5177 | 49 | MOTOR_PINION_T = 27.0, // motor pinion teeth, wheel gear teeth and wheel dia required to calculate speed and distance. |
JonFreeman | 1:8ef34deb5177 | 50 | WHEEL_GEAR_T = 85.0, |
JonFreeman | 1:8ef34deb5177 | 51 | WHEEL_DIA_MM = 98.0, |
JonFreeman | 1:8ef34deb5177 | 52 | #endif |
JonFreeman | 1:8ef34deb5177 | 53 | PI = 4.0 * atan(1.0), |
JonFreeman | 1:8ef34deb5177 | 54 | WHEEL_CIRCUMFERENCE_METRE = PI * WHEEL_DIA_MM / 1000.0, |
JonFreeman | 1:8ef34deb5177 | 55 | PULSES_PER_WHEEL_REV = 32.0 * WHEEL_GEAR_T / MOTOR_PINION_T, |
JonFreeman | 1:8ef34deb5177 | 56 | PULSES_PER_METRE = PULSES_PER_WHEEL_REV / WHEEL_CIRCUMFERENCE_METRE, |
JonFreeman | 1:8ef34deb5177 | 57 | rpm2mph = 60.0 // = Motor Revs per hour; |
JonFreeman | 1:8ef34deb5177 | 58 | * (MOTOR_PINION_T / WHEEL_GEAR_T) // = Wheel rev per hour |
JonFreeman | 1:8ef34deb5177 | 59 | * WHEEL_CIRCUMFERENCE_METRE // = metres per hour |
JonFreeman | 1:8ef34deb5177 | 60 | * 39.37 // = inches per hour |
JonFreeman | 1:8ef34deb5177 | 61 | / (1760 * 36) // = miles per hour |
JonFreeman | 1:8ef34deb5177 | 62 | ; |
JonFreeman | 1:8ef34deb5177 | 63 | |
JonFreeman | 1:8ef34deb5177 | 64 | const double LOCO_HANDBRAKE_ESCAPE_SPEED = 0.5; |
JonFreeman | 1:8ef34deb5177 | 65 | |
JonFreeman | 1:8ef34deb5177 | 66 | enum {NO_DPS, ONE_DP}; |
JonFreeman | 1:8ef34deb5177 | 67 | // Assign unique number to every button we may use, and keep count of total number of them |
JonFreeman | 1:8ef34deb5177 | 68 | enum { |
JonFreeman | 1:8ef34deb5177 | 69 | ENTER, SLIDER, SPEEDO_BUT, VMETER_BUT, AMETER_BUT, |
JonFreeman | 1:8ef34deb5177 | 70 | NUMOF_BUTTONS} ; // button names |
JonFreeman | 1:8ef34deb5177 | 71 | enum { |
JonFreeman | 1:8ef34deb5177 | 72 | STATES, INACTIVE, RUN, NEUTRAL_DRIFT, REGEN_BRAKE, PARK, HANDBRAKE_SLIPPING}; |
JonFreeman | 1:8ef34deb5177 | 73 | |
JonFreeman | 1:8ef34deb5177 | 74 | struct slide { int position; int oldpos; int state; int direction; bool recalc_run; bool handbrake_slipping; |
JonFreeman | 1:8ef34deb5177 | 75 | double handbrake_effort; double loco_speed; } ; |
JonFreeman | 1:8ef34deb5177 | 76 | struct point { int x; int y; } ; |
JonFreeman | 1:8ef34deb5177 | 77 | //struct rect { struct point a, b; } ; |
JonFreeman | 1:8ef34deb5177 | 78 | struct key { int keynum; int x; int y; bool pressed; } ; |
JonFreeman | 1:8ef34deb5177 | 79 | struct ky_bd { int count, slider_y; key ky[MAX_TOUCHES + 1]; bool sli; } ; |
JonFreeman | 1:8ef34deb5177 | 80 |