egoShield
egoShieldS.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * File: egoShieldS.h *
3 * Version: 1.1.1 *
4 * Date: April 1st, 2020 *
5 * Author: Mogens Groth Nicolaisen *
6 * *
7 *********************************************************************************************
8 * (C) 2020 *
9 * *
10 * uStepper ApS *
11 * www.ustepper.com *
12 * administration@ustepper.com *
13 * *
14 * The code contained in this file is released under the following open source license: *
15 * *
16 * Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International *
17 * *
18 * The code in this file is provided without warranty of any kind - use at own risk! *
19 * neither uStepper ApS nor the author, can be held responsible for any damage *
20 * caused by the use of the code contained in this file ! *
21 * *
22 ********************************************************************************************/
87 #ifndef egoShield_h
88 #define egoShield_h
89 
90 
91 #ifdef ARDUINO_AVR_USTEPPER_S
92  #include "uStepperS.h"
93 #endif
94 
95 #ifdef ARDUINO_AVR_USTEPPER_S_LITE
96  #include "uStepperSLite.h"
97 #endif
98 
99 #include "Arduino.h"
100 #include <avr/pgmspace.h>
101 #include "screen.h"
102 #define NOPAGE 0
103 #define RECORDPAGE 1
104 #define IDLEPAGE 2
105 #define PLAYPAGE 3
106 #define PAUSEPAGE 4
107 #define TIMEPAGE 5
108 
109 #define DRAWPAGE(x) do\
110  {\
111  if(this->screen->busFailure)\
112  {\
113  cli();\
114  this->lastPage = NOPAGE;\
115  this->screen->init();\
116  x;\
117  sei();\
118  }\
119  else\
120  {\
121  x;\
122  }\
123  }\
124  while(this->screen->busFailure);\
125 
126 
127 #define BWBT 5
128 
129 #define PLBT 4
130 
131 #define RECBT 3
132 
133 #define FWBT 6
134 
135 #define CNT 50
136 
137 #define OPTO 2
138 
140 #define FULL 1
141 
142 #define HALF 2
143 
144 #define QUARTER 4
145 
146 #define EIGHT 8
147 
148 #define SIXTEEN 16
149 
153 typedef struct {
154  uint8_t debounce,
157  btn;
158  uint16_t time;
159 } buttons;
160 
161 #define DEPRESSED 0
162 #define PRESSED 1
163 #define HOLD 2
165 #define HOLDTIME 50
166 #define HOLDTICK 4
169 #define RESETWDT asm volatile("WDR \n\t")
170 
180 extern "C" void TIMER4_COMPA_vect(void) __attribute__ ((signal,used));
181 
183 {
184 public:
190  egoShield(void);
214  void egoShield::setup(uint16_t acc = 1500,
215  uint16_t vel = 100,
216  float P = 1.0,
217  float I = 0.02,
218  float D = 0.006,
219  float res = 1,
220  int8_t stallsens = 2,
221  uint16_t shutterDelay = 250);
225  //void loop(void);
229  #ifdef ARDUINO_AVR_USTEPPER_S
230  uStepperS stepper;
231  #endif
232 
233  #ifdef ARDUINO_AVR_USTEPPER_S_LITE
234  uStepperSLite stepper;
235  #endif
236 
237 protected:
240  //SoftwareSerial *BTSerial;
241  uint8_t lastPage = NOPAGE;
243  uint8_t place;
245  uint8_t endmove;
247  float pos[CNT];
249  bool pidFlag;
251  bool record;
253  bool loopMode;
255  bool longPushFlag[4];
257  char state;
259  uint8_t rec;
261  uint8_t play;
263  uint8_t fw;
265  uint8_t bw;
267  float setPoint;
269  uint16_t acceleration;
271  uint16_t velocity;
273  uint8_t microStepping;
275  uint16_t faultTolerance;
277  uint16_t faultHysteresis;
279  float pTerm;
281  float iTerm;
283  float dTerm;
285  float stepSize;
287  uint16_t interval;
289  float resolution;
293  bool brakeFlag;
294  /* Declaration of structs for each button*/
295  volatile buttons forwardBtn = {0x1F, DEPRESSED, 0, 0, 0},
296  playBtn = {0x1F, DEPRESSED, 0, 0, 0},
297  recordBtn = {0x1F, DEPRESSED, 0, 0, 0},
298  backwardsBtn = {0x1F, DEPRESSED, 0, 0, 0};
300  uint16_t shutterDelay;
301 
302  unsigned char* loadVideoBuffer(unsigned char *data, unsigned char length);
308  void resetButton(buttons *btn);
312  void resetAllButton();
316  void inputs(void);
329  uint8_t buttonState(uint8_t button, uint8_t nmbr);
333  void idleMode(void);
337  void playMode(void);
341  void pauseMode(void);
345  void timeMode(void);
349  void manForward(void);
353  void manBackward(void);
357  void startPage(void);
365  void idlePage(bool pidMode, float pos);
377  void recordPage(bool pidMode, bool recorded, uint8_t index, float pos);
387  void playPage(bool loopMode, bool pidMode, uint8_t index, bool mode);
397  void pausePage(bool loopMode, bool pidMode, uint8_t index);
405  void timePage(uint8_t step, bool pidMode);
409  void changeVelocity(void);
417  void recordMode(void);
418  void debounce(buttons *btn, uint8_t sample);
419  friend void TIMER4_COMPA_vect(void) __attribute__ ((signal,used));
420 };
421 
423 {
424 public:
425  void loop(void);
426 };
427 
428 class egoShieldTeach : public egoShield
429 {
430 public:
431  void loop(void);
432 };
433 #endif
buttons::holdCnt
uint8_t holdCnt
Definition: egoShieldS.h:156
egoShield
Definition: egoShieldS.h:182
egoShield::pidFlag
bool pidFlag
Definition: egoShieldS.h:249
egoShield::acceleration
uint16_t acceleration
Definition: egoShieldS.h:269
egoShield::changeVelocity
void changeVelocity(void)
Holds the code for the changing velocity during sequence play.
Definition: egoShieldS.cpp:479
egoShield::bw
uint8_t bw
Definition: egoShieldS.h:265
egoShield::egoShield
egoShield(void)
Constructor of egoShield class.
Definition: egoShieldS.cpp:49
egoShield::stallSensitivity
int8_t stallSensitivity
Definition: egoShieldS.h:291
egoShield::recordPage
void recordPage(bool pidMode, bool recorded, uint8_t index, float pos)
Holds the code for the record page of the OLED.
Definition: egoShieldS.cpp:778
egoShield::playPage
void playPage(bool loopMode, bool pidMode, uint8_t index, bool mode)
Holds the code for the play page of the OLED.
Definition: egoShieldS.cpp:873
egoShieldTeach
Definition: egoShieldS.h:428
egoShield::interval
uint16_t interval
Definition: egoShieldS.h:287
buttons::btn
uint8_t btn
Definition: egoShieldS.h:157
egoShield::rec
uint8_t rec
Definition: egoShieldS.h:259
buttons::state
uint8_t state
Definition: egoShieldS.h:155
egoShield::setPoint
float setPoint
Definition: egoShieldS.h:267
screen.h
class definitions for the screen handling
egoShield::longPushFlag
bool longPushFlag[4]
Definition: egoShieldS.h:255
egoShield::timePage
void timePage(uint8_t step, bool pidMode)
Holds the code for the timelapse page of the OLED.
Definition: egoShieldS.cpp:1058
egoShield::iTerm
float iTerm
Definition: egoShieldS.h:281
egoShield::screen
Screen * screen
Contains the main logic of the shield functionality, e.g. transition between states (idle,...
Definition: egoShieldS.h:238
egoShield::buttonState
uint8_t buttonState(uint8_t button, uint8_t nmbr)
Returns the button state of the appropriate button.
egoShield::faultTolerance
uint16_t faultTolerance
Definition: egoShieldS.h:275
Screen
Definition: screen.h:294
egoShield::recordMode
void recordMode(void)
This function handles the debouncing and tracking of whether buttons are pressed, released or held.
Definition: egoShieldS.cpp:189
egoShield::pTerm
float pTerm
Definition: egoShieldS.h:279
egoShield::idlePage
void idlePage(bool pidMode, float pos)
Holds the code for the idle page of the OLED.
Definition: egoShieldS.cpp:713
egoShield::resetAllButton
void resetAllButton()
Resets the state of all 4 buttons at once.
Definition: egoShieldS.cpp:1282
egoShield::resolution
float resolution
Definition: egoShieldS.h:289
egoShield::pos
float pos[CNT]
Definition: egoShieldS.h:247
egoShield::state
char state
Definition: egoShieldS.h:257
egoShield::setup
void setup(uint16_t acc=1500, uint16_t vel=100, float P=1.0, float I=0.02, float D=0.006, float res=1, int8_t stallsens=2, uint16_t shutterDelay=250)
Initializes buttons, OLED, uStepper and BT-module.
Definition: egoShieldS.cpp:53
buttons::time
uint16_t time
Definition: egoShieldS.h:158
egoShield::lastPage
uint8_t lastPage
Definition: egoShieldS.h:241
egoShield::manBackward
void manBackward(void)
Holds the manual backward logic for driving the stepper motor manually with the pushbuttons.
egoShield::shutterDelay
uint16_t shutterDelay
Definition: egoShieldS.h:300
egoShield::stepSize
float stepSize
Definition: egoShieldS.h:285
egoShield::fw
uint8_t fw
Definition: egoShieldS.h:263
egoShield::TIMER4_COMPA_vect
friend void TIMER4_COMPA_vect(void) __attribute__((signal
Watchdog timer interrupt handler, for examining the buttons periodically.
Definition: egoShieldS.cpp:38
egoShield::playMode
void playMode(void)
Holds the play logic, showing play page and running the recorded sequence.
Definition: egoShieldS.cpp:385
TIMER4_COMPA_vect
void TIMER4_COMPA_vect(void) __attribute__((signal
Watchdog timer interrupt handler, for examining the buttons periodically.
Definition: egoShieldS.cpp:38
egoShield::play
uint8_t play
Definition: egoShieldS.h:261
egoShield::microStepping
uint8_t microStepping
Definition: egoShieldS.h:273
egoShield::manForward
void manForward(void)
Holds the manual forward logic for driving the stepper motor manually with the pushbuttons.
egoShield::timeMode
void timeMode(void)
Holds the timelapse logic, showing the timelapse page.
Definition: egoShieldS.cpp:542
CNT
#define CNT
Definition: egoShieldS.h:135
egoShieldTimeLapse
Definition: egoShieldS.h:422
egoShield::startPage
void startPage(void)
Holds the code for the start page of the OLED.
Definition: egoShieldS.cpp:707
egoShield::faultHysteresis
uint16_t faultHysteresis
Definition: egoShieldS.h:277
egoShield::velocity
uint16_t velocity
Definition: egoShieldS.h:271
egoShield::idleMode
void idleMode(void)
Holds the idle logic; page to show, what buttons to enable etc.
Definition: egoShieldS.cpp:286
egoShield::inputs
void inputs(void)
Reads the four buttons and writes their value; no push, short push or long push, to global variables.
Definition: egoShieldS.cpp:699
egoShield::pauseMode
void pauseMode(void)
Holds the pause logic, showing the pause page and pausing the playing of a sequence.
Definition: egoShieldS.cpp:510
egoShield::loopMode
bool loopMode
Definition: egoShieldS.h:253
egoShield::dTerm
float dTerm
Definition: egoShieldS.h:283
egoShield::brakeFlag
bool brakeFlag
Definition: egoShieldS.h:293
egoShield::record
bool record
Definition: egoShieldS.h:251
egoShield::resetButton
void resetButton(buttons *btn)
Function for resetting the state of a button seperately.
Definition: egoShieldS.cpp:1274
buttons
struct to hold information required to debounce button.
Definition: egoShieldS.h:153
buttons::debounce
uint8_t debounce
Definition: egoShieldS.h:154
egoShield::place
uint8_t place
Definition: egoShieldS.h:243
egoShield::endmove
uint8_t endmove
Definition: egoShieldS.h:245
egoShield::pausePage
void pausePage(bool loopMode, bool pidMode, uint8_t index)
Holds the code for the pause page of the OLED.
Definition: egoShieldS.cpp:992