Jon Freeman / Mbed 2 deprecated Loco_10_17_SD

Dependencies:   BSP_DISCO_F746NG FastPWM LCD_DISCO_F746NG SD_DISCO_F746NG TS_DISCO_F746NG mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Electric_Loco.h Source File

Electric_Loco.h

00001 /*  Updated 12 Nov 2017
00002     Jon Freeman
00003 
00004   5" and 7.25" gauge Electric Locomotive Controller - ST DISCO-F746NG
00005 Uses built in display and touch screen.
00006 
00007 Display shows 'analogue' moving coil meter movements for :
00008     Locomotive speed Miles per Hour
00009     System voltage (range 20v - 90v or thereabouts)
00010     Power Watts delivered to drive motors.
00011 
00012 Touch screen has three 'buttons', these are currently unused, and are where the meter movements show.
00013 Idea is to use two for two horns,
00014 
00015 Display has 'slider' touch control. This drives the loco.
00016 Control in central position when not driving or drfting.
00017 Moving towards bottom of screen applies regenerative braking - move further down applies harder braking.
00018 Moving towards top of screen powers drive motors, move further up applies more torque (current controller implemented)
00019 Take finger off and control drifts down to central 'neutral' position.
00020 */
00021 #define MAX_TOUCHES 6       //  Touch screen can decode up to this many simultaneous finger press positions
00022 #define NEUTRAL_VAL   150   //  Number of pixels
00023 
00024 #define SLIDERX 418         //  slider graphic x position
00025 #define SLIDERY 2           //  slider graphic y position
00026 #define SLIDERW 50          //  pixel width of slider
00027 #define SLIDERH 268         //  pixel height of slider
00028 
00029 //  To get speedo reading correctly, need to use correct gear ratio and wheel size info
00030 //#define BOGIE_5_INCH
00031 #define BOGIE_7_and_a_quarter_INCH
00032 
00033 const   int
00034 
00035     NUMBER_OF_MOTORS    = 4,    //  1 to 6 motors
00036 
00037     BUTTON_RAD  = (SLIDERW / 2) - 4,    //  radius of circular 'knob' in slider control
00038     MIN_POS     = BUTTON_RAD + 5,               //  top of screen
00039     MAX_POS     = SLIDERH - (BUTTON_RAD + 1),   //  bottom of screen
00040     CIRC_CTR = SLIDERX + BUTTON_RAD + 4;
00041 
00042 static const double
00043 #ifdef  BOGIE_7_and_a_quarter_INCH
00044     MOTOR_PINION_T  = 17.0, //  motor pinion teeth, wheel gear teeth and wheel dia required to calculate speed and distance.
00045     WHEEL_GEAR_T    = 76.0,
00046     WHEEL_DIA_MM    = 147.0,
00047 #endif
00048 #ifdef  BOGIE_5_INCH
00049     MOTOR_PINION_T  = 27.0, //  motor pinion teeth, wheel gear teeth and wheel dia required to calculate speed and distance.
00050     WHEEL_GEAR_T    = 85.0,
00051     WHEEL_DIA_MM    = 98.0,
00052 #endif
00053     PI = 4.0 * atan(1.0),
00054     WHEEL_CIRCUMFERENCE_METRE = PI * WHEEL_DIA_MM / 1000.0,
00055     PULSES_PER_WHEEL_REV    = 32.0 * WHEEL_GEAR_T / MOTOR_PINION_T,
00056     PULSES_PER_METRE        = PULSES_PER_WHEEL_REV / WHEEL_CIRCUMFERENCE_METRE,
00057     rpm2mph         = 60.0                                      //  = Motor Revs per hour;
00058                   * (MOTOR_PINION_T / WHEEL_GEAR_T)   //  = Wheel rev per hour
00059                   * WHEEL_CIRCUMFERENCE_METRE         //  = metres per hour
00060                   * 39.37                             //  = inches per hour
00061                   / (1760 * 36)                       //  = miles per hour
00062                   ;
00063 
00064 const   double LOCO_HANDBRAKE_ESCAPE_SPEED = 0.5;
00065 
00066 enum    {NO_DPS, ONE_DP};
00067 //  Assign unique number to every button we may use, and keep count of total number of them
00068 enum        {
00069             ENTER, SLIDER, SPEEDO_BUT, VMETER_BUT, AMETER_BUT,
00070             NUMOF_BUTTONS}  ;   //  button names
00071 enum        {
00072             STATES, INACTIVE, RUN, NEUTRAL_DRIFT, REGEN_BRAKE, PARK, HANDBRAKE_SLIPPING};
00073 
00074 struct  slide   {   int position;    int    oldpos; int state; int direction;   bool recalc_run;    bool handbrake_slipping;    
00075                     double handbrake_effort;   double   loco_speed;  }   ;
00076 struct  point   {   int x;    int y;  }   ;
00077 //struct  rect    {   struct point a, b; }   ;
00078 struct  key     {   int keynum; int x;  int y;  bool pressed;  }   ;
00079 struct  ky_bd   {   int count,  slider_y; key ky[MAX_TOUCHES + 1];   bool  sli;   }  ;
00080