egoShield
egoShieldS.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * File: egoShieldS.h *
3 * Version: 1.1.0 *
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 ********************************************************************************************/
83 #ifndef egoShield_h
84 #define egoShield_h
85 
86 
87 #ifdef ARDUINO_AVR_USTEPPER_S
88  #include "uStepperS.h"
89 #endif
90 
91 #ifdef ARDUINO_AVR_USTEPPER_S_LITE
92  #include "uStepperSLite.h"
93 #endif
94 
95 #include "Arduino.h"
96 #include <avr/pgmspace.h>
97 #include "screen.h"
98 #define NOPAGE 0
99 #define RECORDPAGE 1
100 #define IDLEPAGE 2
101 #define PLAYPAGE 3
102 #define PAUSEPAGE 4
103 #define TIMEPAGE 5
104 
105 #define DRAWPAGE(x) do\
106  {\
107  if(this->screen->busFailure)\
108  {\
109  cli();\
110  this->lastPage = NOPAGE;\
111  this->screen->init();\
112  x;\
113  sei();\
114  }\
115  else\
116  {\
117  x;\
118  }\
119  }\
120  while(this->screen->busFailure);\
121 
122 
123 #define BWBT 5
124 
125 #define PLBT 4
126 
127 #define RECBT 3
128 
129 #define FWBT 6
130 
131 #define CNT 50
132 
133 #define OPTO 2
134 
136 #define FULL 1
137 
138 #define HALF 2
139 
140 #define QUARTER 4
141 
142 #define EIGHT 8
143 
144 #define SIXTEEN 16
145 
149 typedef struct {
150  uint8_t debounce,
151  state,
152  holdCnt,
153  btn;
154  uint16_t time;
155 } buttons;
156 
157 #define DEPRESSED 0
158 #define PRESSED 1
159 #define HOLD 2
161 #define HOLDTIME 50
162 #define HOLDTICK 4
165 #define RESETWDT asm volatile("WDR \n\t")
166 
176 extern "C" void TIMER4_COMPA_vect(void) __attribute__ ((signal,used));
177 
178 class egoShield
179 {
180 public:
186  egoShield(void);
210  void egoShield::setup(uint16_t acc = 1500,
211  uint16_t vel = 100,
212  float P = 1.0,
213  float I = 0.02,
214  float D = 0.006,
215  float res = 1,
216  int8_t stallsens = 2,
217  uint16_t shutterDelay = 250);
221  //void loop(void);
225  #ifdef ARDUINO_AVR_USTEPPER_S
226  uStepperS stepper;
227  #endif
228 
229  #ifdef ARDUINO_AVR_USTEPPER_S_LITE
230  uStepperSLite stepper;
231  #endif
232 
233 protected:
234  Screen *screen;
236  //SoftwareSerial *BTSerial;
237  uint8_t lastPage = NOPAGE;
239  uint8_t place;
241  uint8_t endmove;
243  float pos[CNT];
245  bool pidFlag;
247  bool record;
249  bool loopMode;
251  bool longPushFlag[4];
253  char state;
255  uint8_t rec;
257  uint8_t play;
259  uint8_t fw;
261  uint8_t bw;
263  float setPoint;
265  uint16_t acceleration;
267  uint16_t velocity;
269  uint8_t microStepping;
271  uint16_t faultTolerance;
273  uint16_t faultHysteresis;
275  float pTerm;
277  float iTerm;
279  float dTerm;
281  float stepSize;
283  uint16_t interval;
285  float resolution;
287  int8_t stallSensitivity;
289  bool brakeFlag;
290  /* Declaration of structs for each button*/
291  volatile buttons forwardBtn = {0x1F, DEPRESSED, 0, 0, 0},
292  playBtn = {0x1F, DEPRESSED, 0, 0, 0},
293  recordBtn = {0x1F, DEPRESSED, 0, 0, 0},
294  backwardsBtn = {0x1F, DEPRESSED, 0, 0, 0};
296  uint16_t shutterDelay;
297 
298  unsigned char* loadVideoBuffer(unsigned char *data, unsigned char length);
304  void resetButton(buttons *btn);
308  void resetAllButton();
312  void inputs(void);
325  uint8_t buttonState(uint8_t button, uint8_t nmbr);
329  void idleMode(void);
333  void playMode(void);
337  void pauseMode(void);
341  void timeMode(void);
345  void manForward(void);
349  void manBackward(void);
353  void startPage(void);
361  void idlePage(bool pidMode, float pos);
373  void recordPage(bool pidMode, bool recorded, uint8_t index, float pos);
383  void playPage(bool loopMode, bool pidMode, uint8_t index, bool mode);
393  void pausePage(bool loopMode, bool pidMode, uint8_t index);
401  void timePage(uint8_t step, bool pidMode);
405  void changeVelocity(void);
413  void recordMode(void);
414  void debounce(buttons *btn, uint8_t sample);
415  friend void TIMER4_COMPA_vect(void) __attribute__ ((signal,used));
416 };
417 
418 class egoShieldTimeLapse : public egoShield
419 {
420 public:
421  void loop(void);
422 };
423 
424 class egoShieldTeach : public egoShield
425 {
426 public:
427  void loop(void);
428 };
429 #endif
egoShield
Definition: egoShieldS.h:177
egoShield::pidFlag
bool pidFlag
Definition: egoShieldS.h:244
egoShield::acceleration
uint16_t acceleration
Definition: egoShieldS.h:264
egoShield::changeVelocity
void changeVelocity(void)
Holds the code for the changing velocity during sequence play.
Definition: egoShieldS.cpp:476
egoShield::bw
uint8_t bw
Definition: egoShieldS.h:260
egoShield::egoShield
egoShield(void)
Constructor of egoShield class.
Definition: egoShieldS.cpp:49
egoShield::stallSensitivity
int8_t stallSensitivity
Definition: egoShieldS.h:286
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:776
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:871
egoShieldTeach
Definition: egoShieldS.h:423
egoShield::interval
uint16_t interval
Definition: egoShieldS.h:282
egoShield::rec
uint8_t rec
Definition: egoShieldS.h:254
egoShield::setPoint
float setPoint
Definition: egoShieldS.h:262
screen.h
class definitions for the screen handling
egoShield::longPushFlag
bool longPushFlag[4]
Definition: egoShieldS.h:250
egoShield::timePage
void timePage(uint8_t step, bool pidMode)
Holds the code for the timelapse page of the OLED.
Definition: egoShieldS.cpp:1056
egoShield::iTerm
float iTerm
Definition: egoShieldS.h:276
egoShield::screen
Screen * screen
Contains the main logic of the shield functionality, e.g. transition between states (idle,...
Definition: egoShieldS.h:233
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:270
Screen
Definition: screen.h:293
egoShield::recordMode
void recordMode(void)
This function handles the debouncing and tracking of whether buttons are pressed, released or held.
Definition: egoShieldS.cpp:186
egoShield::pTerm
float pTerm
Definition: egoShieldS.h:274
egoShield::idlePage
void idlePage(bool pidMode, float pos)
Holds the code for the idle page of the OLED.
Definition: egoShieldS.cpp:711
egoShield::resetAllButton
void resetAllButton()
Resets the state of all 4 buttons at once.
Definition: egoShieldS.cpp:1280
egoShield::resolution
float resolution
Definition: egoShieldS.h:284
egoShield::pos
float pos[CNT]
Definition: egoShieldS.h:242
egoShield::state
char state
Definition: egoShieldS.h:252
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
egoShield::lastPage
uint8_t lastPage
Definition: egoShieldS.h:236
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:295
egoShield::stepSize
float stepSize
Definition: egoShieldS.h:280
egoShield::fw
uint8_t fw
Definition: egoShieldS.h:258
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:382
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:256
egoShield::microStepping
uint8_t microStepping
Definition: egoShieldS.h:268
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:539
CNT
#define CNT
Definition: egoShieldS.h:130
egoShieldTimeLapse
Definition: egoShieldS.h:417
egoShield::startPage
void startPage(void)
Holds the code for the start page of the OLED.
Definition: egoShieldS.cpp:705
egoShield::faultHysteresis
uint16_t faultHysteresis
Definition: egoShieldS.h:272
egoShield::velocity
uint16_t velocity
Definition: egoShieldS.h:266
egoShield::idleMode
void idleMode(void)
Holds the idle logic; page to show, what buttons to enable etc.
Definition: egoShieldS.cpp:283
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:697
egoShield::pauseMode
void pauseMode(void)
Holds the pause logic, showing the pause page and pausing the playing of a sequence.
Definition: egoShieldS.cpp:507
egoShield::loopMode
bool loopMode
Definition: egoShieldS.h:248
egoShield::dTerm
float dTerm
Definition: egoShieldS.h:278
egoShield::brakeFlag
bool brakeFlag
Definition: egoShieldS.h:288
egoShield::record
bool record
Definition: egoShieldS.h:246
egoShield::resetButton
void resetButton(buttons *btn)
Function for resetting the state of a button seperately.
Definition: egoShieldS.cpp:1272
buttons
struct to hold information required to debounce button.
Definition: egoShieldS.h:148
egoShield::place
uint8_t place
Definition: egoShieldS.h:238
egoShield::endmove
uint8_t endmove
Definition: egoShieldS.h:240
egoShield::pausePage
void pausePage(bool loopMode, bool pidMode, uint8_t index)
Holds the code for the pause page of the OLED.
Definition: egoShieldS.cpp:990