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