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
dro.h@0:23cc72b18e74, 2017-11-12 (annotated)
- Committer:
- JonFreeman
- Date:
- Sun Nov 12 06:26:29 2017 +0000
- Revision:
- 0:23cc72b18e74
Electric loco controller up to Nov 2017 includes SD odometer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JonFreeman | 0:23cc72b18e74 | 1 | /* Updated 12 Nov 2017 |
JonFreeman | 0:23cc72b18e74 | 2 | Jon Freeman |
JonFreeman | 0:23cc72b18e74 | 3 | |
JonFreeman | 0:23cc72b18e74 | 4 | 5" and 7.25" gauge Electric Locomotive Controller - ST DISCO-F746NG |
JonFreeman | 0:23cc72b18e74 | 5 | Uses built in display and touch screen. |
JonFreeman | 0:23cc72b18e74 | 6 | |
JonFreeman | 0:23cc72b18e74 | 7 | Display shows 'analogue' moving coil meter movements for : |
JonFreeman | 0:23cc72b18e74 | 8 | Locomotive speed Miles per Hour |
JonFreeman | 0:23cc72b18e74 | 9 | System voltage (range 20v - 90v or thereabouts) |
JonFreeman | 0:23cc72b18e74 | 10 | Power Watts delivered to drive motors. |
JonFreeman | 0:23cc72b18e74 | 11 | |
JonFreeman | 0:23cc72b18e74 | 12 | Touch screen has three 'buttons', these are currently unused, and are where the meter movements show. |
JonFreeman | 0:23cc72b18e74 | 13 | Idea is to use two for two horns, |
JonFreeman | 0:23cc72b18e74 | 14 | |
JonFreeman | 0:23cc72b18e74 | 15 | Display has 'slider' touch control. This drives the loco. |
JonFreeman | 0:23cc72b18e74 | 16 | Control in central position when not driving or drfting. |
JonFreeman | 0:23cc72b18e74 | 17 | Moving towards bottom of screen applies regenerative braking - move further down applies harder braking. |
JonFreeman | 0:23cc72b18e74 | 18 | Moving towards top of screen powers drive motors, move further up applies more torque (current controller implemented) |
JonFreeman | 0:23cc72b18e74 | 19 | Take finger off and control drifts down to central 'neutral' position. |
JonFreeman | 0:23cc72b18e74 | 20 | */ |
JonFreeman | 0:23cc72b18e74 | 21 | #define MAX_TOUCHES 6 // Touch screen can decode up to this many simultaneous finger press positions |
JonFreeman | 0:23cc72b18e74 | 22 | #define NEUTRAL_VAL 150 // Number of pixels |
JonFreeman | 0:23cc72b18e74 | 23 | |
JonFreeman | 0:23cc72b18e74 | 24 | #define SLIDERX 418 // slider graphic x position |
JonFreeman | 0:23cc72b18e74 | 25 | #define SLIDERY 2 // slider graphic y position |
JonFreeman | 0:23cc72b18e74 | 26 | #define SLIDERW 50 // pixel width of slider |
JonFreeman | 0:23cc72b18e74 | 27 | #define SLIDERH 268 // pixel height of slider |
JonFreeman | 0:23cc72b18e74 | 28 | const int |
JonFreeman | 0:23cc72b18e74 | 29 | BUTTON_RAD = (SLIDERW / 2) - 4, // radius of circular 'knob' in slider control |
JonFreeman | 0:23cc72b18e74 | 30 | MIN_POS = BUTTON_RAD + 5, // top of screen |
JonFreeman | 0:23cc72b18e74 | 31 | MAX_POS = SLIDERH - (BUTTON_RAD + 1), // bottom of screen |
JonFreeman | 0:23cc72b18e74 | 32 | CIRC_CTR = SLIDERX + BUTTON_RAD + 4; |
JonFreeman | 0:23cc72b18e74 | 33 | |
JonFreeman | 0:23cc72b18e74 | 34 | static const double PI = 4.0 * atan(1.0); |
JonFreeman | 0:23cc72b18e74 | 35 | const double LOCO_HANDBRAKE_ESCAPE_SPEED = 0.5; |
JonFreeman | 0:23cc72b18e74 | 36 | |
JonFreeman | 0:23cc72b18e74 | 37 | enum {NO_DPS, ONE_DP}; |
JonFreeman | 0:23cc72b18e74 | 38 | // Assign unique number to every button we may use, and keep count of total number of them |
JonFreeman | 0:23cc72b18e74 | 39 | enum { |
JonFreeman | 0:23cc72b18e74 | 40 | ENTER, SLIDER, SPEEDO_BUT, VMETER_BUT, AMETER_BUT, |
JonFreeman | 0:23cc72b18e74 | 41 | NUMOF_BUTTONS} ; // button names |
JonFreeman | 0:23cc72b18e74 | 42 | enum { |
JonFreeman | 0:23cc72b18e74 | 43 | STATES, INACTIVE, RUN, NEUTRAL_DRIFT, REGEN_BRAKE, PARK, HANDBRAKE_SLIPPING}; |
JonFreeman | 0:23cc72b18e74 | 44 | |
JonFreeman | 0:23cc72b18e74 | 45 | struct slide { int position; int oldpos; int state; int direction; bool recalc_run; bool handbrake_slipping; |
JonFreeman | 0:23cc72b18e74 | 46 | double handbrake_effort; double loco_speed; } ; |
JonFreeman | 0:23cc72b18e74 | 47 | struct point { int x; int y; } ; |
JonFreeman | 0:23cc72b18e74 | 48 | //struct rect { struct point a, b; } ; |
JonFreeman | 0:23cc72b18e74 | 49 | struct key { int keynum; int x; int y; bool pressed; } ; |
JonFreeman | 0:23cc72b18e74 | 50 | struct ky_bd { int count, slider_y; key ky[MAX_TOUCHES + 1]; bool sli; } ; |
JonFreeman | 0:23cc72b18e74 | 51 |