egoShield
All Classes Files Functions Variables Friends Macros Pages
egoShieldTeach.cpp
Go to the documentation of this file.
1 /********************************************************************************************
2 * File: egoShieldTeach.cpp *
3 * Version: 1.0.0 *
4 * Date: January 10th, 2018 *
5 * Author: Mogens Groth Nicolaisen *
6 * *
7 *********************************************************************************************
8 * egoShield class *
9 * *
10 * This file contains the implementation of the class methods, incorporated in the *
11 * egoShield Arduino library. The library is used by instantiating an egoShield object *
12 * by calling of the overloaded constructor: *
13 * *
14 * example: *
15 * *
16 * egoShield ego; *
17 * *
18 * The instantiation above creates an egoShield object *
19 * after instantiation of the object, the object setup function should be called within *
20 * Arduino's setup function, and the object loop function should be run within the Arduino's *
21 * loop function: *
22 * *
23 * example: *
24 * *
25 * egoShield ego; *
26 * *
27 * void setup() *
28 * { *
29 * ego.setup(); *
30 * } *
31 * *
32 * void loop() *
33 * { *
34 * ego.loop(); *
35 * } *
36 * *
37 * *
38 *********************************************************************************************
39 * (C) 2018 *
40 * *
41 * uStepper ApS *
42 * www.ustepper.com *
43 * administration@ustepper.com *
44 * *
45 * The code contained in this file is released under the following open source license: *
46 * *
47 * Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International *
48 * *
49 * The code in this file is provided without warranty of any kind - use at own risk! *
50 * neither uStepper ApS nor the author, can be held responsible for any damage *
51 * caused by the use of the code contained in this file ! *
52 * *
53 ********************************************************************************************/
64 #include "egoShieldTeach.h"
65 
66 egoShield *egoPointer;
67 
68 extern "C" {
69  void WDT_vect(void)
70  {
71  egoPointer->inputs(); //examine buttons
72  WDTCSR |= (1<<WDIE); //Enable Watchdog interrupt
73  }
74 }
75 
77 {
78  u8g2 = new U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI(U8G2_R0, /* clock=*/ 11, /* data=*/ 9, /* cs=*/ U8X8_PIN_NONE, /* dc=*/ 2, /* reset=*/ 10);
79 }
80 
81 void egoShield::setup(uint16_t acc, uint16_t vel, uint8_t uStep, uint16_t fTol, uint16_t fHys, float P, float I, float D, float res)//brake mode?
82 {
83  egoPointer = this; //We need a global pointer with the address of the egoShield object, for the watchdog interrupt handler to access the object
84 
85  cli(); //Make sure we dont get interrupted while initializing
86  //Setup Watchdog timer, no prescaler (16ms interrupt period)
87  RESETWDT;
88  WDTCSR = (1 << WDCE) | (1 << WDE);
89  WDTCSR |= (1 << WDIE) | (1 << WDE);
90 
91  //Store initialization inputs in egoShield object
92  this->acceleration = acc;
93  this->velocity = vel;
94  this->microStepping = uStep;
95  this->faultTolerance = fTol;
96  this->faultHysteresis = fHys;
97  this->pTerm = P;
98  this->iTerm = I;
99  this->dTerm = D;
100  this->resolution = res;
101  this->stepSize = 2;
102  this->interval = 2000;
103 
104  brakeFlag = 1; //Flag to indicate whether brake should be activated or not
105 
106  stepper.setup(PID,this->microStepping,this->faultTolerance,this->faultHysteresis,this->pTerm,this->iTerm,this->dTerm,1); //initialize ustepper object
107  u8g2->begin();//start display
108 
109  // Check whether the uStepper is mounted on a motor with a magnet attached. If not, show an error message untill mounted correctly
110  do
111  {
112  u8g2->firstPage();
113  do
114  {
115  u8g2->setFontMode(1);
116  u8g2->setDrawColor(1);
117  u8g2->setFontDirection(0);
118  u8g2->setFont(u8g2_font_6x10_tf);
119 
120  u8g2->drawStr(2,10,"Magnet not present !");
121  } while ( u8g2->nextPage() );
122  }
123  while(stepper.encoder.detectMagnet() == 2 || stepper.encoder.detectMagnet() == 1);
124 
125  this->startPage();//show startpage
126  stepper.encoder.setHome(); //Set home to current position
127  stepper.setMaxVelocity(this->velocity);
128  stepper.setMaxAcceleration(this->acceleration);
129  stepper.moveToEnd(1);
130  stepper.moveToAngle(30,HARD);
131  while(stepper.getMotorState());
132  stepper.encoder.setHome();
133  pidFlag = 1;//enable PID
134  //Setup IO pins
135  pinMode(FWBT ,INPUT);
136  pinMode(PLBT ,INPUT);
137  pinMode(RECBT ,INPUT);
138  pinMode(BWBT ,INPUT);
139  pinMode(OPTO,OUTPUT);
140  digitalWrite(OPTO ,HIGH);
141  digitalWrite(FWBT ,HIGH);//pull-up
142  digitalWrite(PLBT ,HIGH);//pull-up
143  digitalWrite(RECBT ,HIGH);//pull-up
144  digitalWrite(BWBT ,HIGH);//pull-up
145  setPoint = stepper.encoder.getAngleMoved();//set manual move setpoint to current position
146 
147 
148  delay(2000);//for 2 seconds
149  this->resetAllButton(); //Initialize buttons
150  state = 'a';//start in idle
151 }
152 
153 void egoShield::loop(void)
154 {
155  setPoint = stepper.encoder.getAngleMoved();
156  switch (state)
157  {
158  case 'a'://if we are in idle
159  idleMode();
160  break;
161 
162  case 'b'://if we are in play
163  playMode();
164  break;
165 
166  case 'c'://if we are in record
167  recordMode();
168  break;
169 
170  case 'd'://in pause
171  pauseMode();
172  break;
173  }
174 }
175 
177 {
178  static bool continousForward = 0;
179  static bool continousBackwards = 0;
180 
181  this->idlePage(pidFlag,setPoint);
182 
183  if(continousForward)
184  {
185  if(this->forwardBtn.state != HOLD)
186  {
187  stepper.hardStop(HARD);
188  continousForward = 0;
189  }
190  }
191  else if(continousBackwards)
192  {
193  if(this->backwardsBtn.state != HOLD)
194  {
195  stepper.hardStop(HARD);
196  continousBackwards = 0;
197  }
198  }
199  if(this->playBtn.btn)//if play/stop/pause is pressed for long time, invert the pid mode
200  {
201  while(this->playBtn.state == PRESSED);
202  if(this->playBtn.state == DEPRESSED)//we want to play sequence when doing a short press
203  {
204  state = 'b';
205  continousForward = 0;
206  continousBackwards = 0;
207  this->resetAllButton();
208  }
209  else
210  {
211  if(pidFlag == 0)
212  {
213  pidFlag = 1;
214  stepper.setup(PID,this->microStepping,this->faultTolerance,this->faultHysteresis,this->pTerm,this->iTerm,this->dTerm,0);//pause PID to allow manual movement
215  }
216  else
217  {
218  pidFlag = 0;
219  stepper.setup(NORMAL,this->microStepping,this->faultTolerance,this->faultHysteresis,this->pTerm,this->iTerm,this->dTerm,0);//pause PID to allow manual movement
220  stepper.hardStop(SOFT);
221  }
222  this->idlePage(pidFlag,setPoint);
223  while(this->playBtn.state == HOLD);
224  }
225  this->resetButton(&playBtn);
226  }
227  else if(this->forwardBtn.btn)//if manual forward signal
228  {
229  if(this->forwardBtn.state == HOLD)
230  {
231  if(!continousForward)
232  {
233  stepper.runContinous(CCW);
234  continousForward = 1;
235  }
236  this->forwardBtn.btn = 0;
237  }
238  else
239  {
240  stepper.moveAngle(-5.0,0);//move 5deg
241  this->forwardBtn.btn = 0;
242  }
243  }
244  else if(this->backwardsBtn.btn)//if manual backward signal
245  {
246  if(this->backwardsBtn.state == HOLD)
247  {
248  if(!continousBackwards)
249  {
250  stepper.runContinous(CW);
251  continousBackwards = 1;
252  }
253  this->backwardsBtn.btn = 0;
254  }
255  else
256  {
257  stepper.moveAngle(5.0,0);//move 5deg
258  this->backwardsBtn.btn = 0;
259  }
260  }
261  else if(this->recordBtn.btn == 1)
262  {
263  this->resetAllButton();
264  continousForward = 0;
265  continousBackwards = 0;
266  state = 'c';
267  }
268 }
269 
271 {
272  static uint8_t started = 0;
273 
274  this->playPage(loopMode,pidFlag,place,0);
275 
276  if(this->recordBtn.btn)//play/stop/pause
277  {
278  while(this->recordBtn.state == PRESSED);
279  if(this->recordBtn.state == DEPRESSED)//we want to play sequence when doing a short press
280  {
281  state = 'd';
282  this->resetAllButton();
283  return;
284  }
285  }
286  else if(this->playBtn.btn)//play/stop/pause
287  {
288  while(this->playBtn.state == PRESSED);
289  if(this->playBtn.state == DEPRESSED)//we want to play sequence when doing a short press
290  {
291  started = 1;
292  }
293  else //Long press = stop
294  {
295  place = 0;//reset array counter
296  loopMode = 0;
297  started = 0;
298  state = 'a';//idle
299  this->idlePage(pidFlag,setPoint);
300  while(this->playBtn.state == HOLD);
301  }
302  this->resetAllButton();
303  return;
304  }
305  else if(started || loopMode)
306  {
307  if(!stepper.getMotorState())
308  {
309  place++;//increment array counter
310  if(loopMode && place > endmove)
311  {
312  place = 0;
313  }
314  else if(place > endmove)//If we are at the end move
315  {
316  place = 0;//reset array counter
317  started = 0;
318  state = 'a';
319  this->resetAllButton();
320  return;
321  }
322  stepper.setMaxVelocity(this->velocity);
323  stepper.setMaxAcceleration(this->acceleration);
324  stepper.moveToAngle(pos[place],brakeFlag);
325  }
326  }
327 
328  if(this->forwardBtn.state == HOLD)//loop mode start
329  {
330  this->resetButton(&forwardBtn);
331  loopMode = 1;
332  }
333  if(this->forwardBtn.btn)//if manual backward signal
334  {
335  while(this->forwardBtn.state == PRESSED);
336  if(this->forwardBtn.state == HOLD)
337  {
338  loopMode = 1;
339  this->playPage(loopMode,pidFlag,place,0);
340  while(this->forwardBtn.state == HOLD);
341  this->forwardBtn.btn = 0;
342  }
343  else
344  {
345  changeVelocity(1);
346  this->forwardBtn.btn = 0;
347  }
348  }
349  else if(this->backwardsBtn.btn)//if manual backward signal
350  {
351  while(this->backwardsBtn.state == PRESSED);
352  if(this->backwardsBtn.state == HOLD)
353  {
354  loopMode = 0;
355  this->playPage(loopMode,pidFlag,place,0);
356  while(this->backwardsBtn.state == HOLD);
357  this->backwardsBtn.btn = 0;
358  }
359  else
360  {
361  changeVelocity(0);
362  this->backwardsBtn.btn = 0;
363  }
364  }
365 }
366 
367 void egoShield::changeVelocity(bool speedDirection)
368 {
369  if(speedDirection && this->velocity <= 9900 && this->acceleration <= 19900)//increase speed
370  {
371  this->forwardBtn.btn = 0;
372  this->velocity+=100;
373  this->acceleration+=100;
374  }
375  else if(!speedDirection && this->velocity >= 200 && this->acceleration >= 200)//decrease speed
376  {
377  this->backwardsBtn.btn = 0;
378  this->velocity-=100;
379  this->acceleration-=100;
380  }
381 }
382 
384 {
385  static bool continousForward = 0;
386  static bool continousBackwards = 0;
387 
388  this->recordPage(pidFlag,0,place,setPoint);
389 
390  if(continousForward)
391  {
392  if(this->forwardBtn.state != HOLD)
393  {
394  stepper.hardStop(HARD);
395  continousForward = 0;
396  }
397  }
398  else if(continousBackwards)
399  {
400  if(this->backwardsBtn.state != HOLD)
401  {
402  stepper.hardStop(HARD);
403  continousBackwards = 0;
404  }
405  }
406  if(this->forwardBtn.btn)//if manual forward signal
407  {
408  if(this->forwardBtn.state == HOLD)
409  {
410  if(!continousForward)
411  {
412  stepper.runContinous(CCW);
413  continousForward = 1;
414  }
415  this->forwardBtn.btn = 0;
416  }
417  else
418  {
419  stepper.moveAngle(-5.0,0);//move 5deg
420  this->forwardBtn.btn = 0;
421  }
422  }
423  else if(this->backwardsBtn.btn)//if manual backward signal
424  {
425  if(this->backwardsBtn.state == HOLD)
426  {
427  if(!continousBackwards)
428  {
429  stepper.runContinous(CW);
430  continousBackwards = 1;
431  }
432  this->backwardsBtn.btn = 0;
433  }
434  else
435  {
436  stepper.moveAngle(5.0,0);//move 5deg
437  this->backwardsBtn.btn = 0;
438  }
439  }
440  else if(this->recordBtn.btn == 1)//record position
441  {
442  this->recordBtn.btn = 0;
443  if(record == 0)//If we were not recording before
444  {
445  //stepper.encoder.setHome();//Set current position as home
446  //setPoint = 0;
447  place = 0;//Reset the array counter
448  record = 1;//Record flag
449  }
450  this->recordPage(pidFlag,1,place,setPoint);
451  delay(500);
452  if(record == 1)//If we have initialized recording
453  {
454  pos[place] = setPoint;//Save current position
455  place++;//Increment array counter
456  if(place>CNT)
457  {
458  place=0;
459  }
460  }
461  }
462  else if(this->playBtn.btn == 1)//stop pressed
463  {
464  endmove = place-1;//set the endmove to the current position
465  place = 0;//reset array counter
466  record = 0;//reset record flag
467  state = 'a';//stop state
468  continousForward = 0;
469  continousBackwards = 0;
470  this->idlePage(pidFlag,setPoint);
471  while(this->playBtn.state == HOLD);
472  this->resetAllButton();
473  }
474 }
475 
477 {
479  if(this->playBtn.btn)//play/stop/pause
480  {
481  while(this->playBtn.state == PRESSED);
482  if(this->playBtn.state == DEPRESSED) //Short press = unpause
483  {
484  state = 'b';
485  }
486  else //Long press = stop
487  {
488  state = 'a';
489  this->idlePage(pidFlag,setPoint);
490  while(this->playBtn.state == HOLD);
491  this->resetAllButton();
492  }
493  this->resetButton(&playBtn);
494  }
495 }
496 
498 {
499  this->debounce(&forwardBtn,(PINC >> 3) & 0x01);
500  this->debounce(&playBtn,(PINC >> 1) & 0x01);
501  this->debounce(&recordBtn,(PINC >> 2) & 0x01);
502  this->debounce(&backwardsBtn,(PINC >> 0) & 0x01);
503 }
504 
506 {
507  u8g2->firstPage();
508  do {
509  u8g2->drawXBM(19, 20, logo_width, logo_height, logo_bits);
510  } while ( u8g2->nextPage() );
511 }
512 
513 void egoShield::idlePage(bool pidMode, float pos)
514 {
515  char buf[20];
516  String sBuf;
517 
518  sBuf = "Position: ";
519  sBuf += (int32_t)(pos/this->resolution);
520  sBuf += " mm";
521  sBuf.toCharArray(buf, 20);
522 
523  u8g2->firstPage();
524  do {
525  u8g2->drawBox(1, 1, 128, 12);
526  u8g2->drawBox(1, 48, 128, 68);
527  u8g2->setFontMode(0);
528  u8g2->setDrawColor(0);
529  u8g2->setFontDirection(0);
530  u8g2->setFont(u8g2_font_6x10_tf);
531 
532  //Bottom bar
533  u8g2->drawXBM(5, 51, en_width, en_height, bw_bits);
534  u8g2->drawXBM(112, 51, en_width, en_height, fw_bits);
535  u8g2->drawXBM(32, 50, play_width, play_height, play_bits);
536  u8g2->drawXBM(43, 51, tt_width, tt_height, stop_bits);
537  u8g2->drawXBM(71, 51, tt_width, tt_height, rec_bits);
538  u8g2->drawXBM(85, 51, tt_width, tt_height, pse_bits);
539 
540  //Mode
541  u8g2->drawStr(2,10,"Idle");
542  if(pidMode)
543  {
544  u8g2->drawStr(45,10,"PID ON");
545  }
546  else
547  {
548  u8g2->drawStr(45,10,"PID OFF");
549  }
550  u8g2->setFontMode(1);
551  u8g2->setDrawColor(1);
552  u8g2->drawStr(2,35,buf);
553  } while ( u8g2->nextPage() );
554 }
555 
556 void egoShield::recordPage(bool pidMode, bool recorded, uint8_t index, float pos)
557 {
558  char buf[22];//char array buffer
559  String sBuf;
560 
561  u8g2->firstPage();
562  do
563  {
564  u8g2->drawBox(1, 1, 128, 12);
565  u8g2->drawBox(1, 48, 128, 68);
566  u8g2->setFontMode(0);
567  u8g2->setDrawColor(0);
568  u8g2->setFontDirection(0);
569  u8g2->setFont(u8g2_font_6x10_tf);
570 
571  u8g2->drawXBM(5, 51, en_width, en_height, bw_bits);
572  u8g2->drawXBM(112, 51, en_width, en_height, fw_bits);
573  u8g2->drawXBM(38, 51, tt_width, tt_height, stop_bits);
574  u8g2->drawXBM(76, 51, tt_width, tt_height, rec_bits);
575 
576  //Mode
577  u8g2->drawStr(2,10,"Record");
578  if(pidMode)
579  {
580  u8g2->drawStr(45,10,"PID ON");
581  }
582  else
583  {
584  u8g2->drawStr(45,10,"PID OFF");
585  }
586  u8g2->setFontMode(1);
587  u8g2->setDrawColor(1);
588  if(recorded)
589  {
590  sBuf = "Position ";
591  sBuf += index;
592  sBuf += " recorded";
593  sBuf.toCharArray(buf, 22);
594  u8g2->drawStr(2,35,buf);
595  }
596  else
597  {
598  sBuf = "Position: ";
599  sBuf += (int32_t)(pos/this->resolution);
600  sBuf += " mm";
601  sBuf.toCharArray(buf, 22);
602  u8g2->drawStr(2,35,buf);
603  }
604  } while ( u8g2->nextPage() );
605 }
606 
607 void egoShield::playPage(bool loopMode, bool pidMode, uint8_t index, bool mode)
608 {
609  char buf[5];//char array buffer
610 
611  u8g2->firstPage();
612  do
613  {
614  u8g2->drawBox(1, 1, 128, 12);
615  u8g2->drawBox(1, 48, 128, 68);
616  u8g2->setFontMode(0);
617  u8g2->setDrawColor(0);
618  u8g2->setFontDirection(0);
619  u8g2->setFont(u8g2_font_6x10_tf);
620 
621  if(loopMode)
622  {
623  u8g2->drawXBM(110, 2, loop_width, loop_height, loop_bits);
624  }
625 
626  //Bottom bar
627  u8g2->drawXBM(5, 51, en_width, en_height, bw_bits);
628  u8g2->drawXBM(112, 51, en_width, en_height, fw_bits);
629  u8g2->drawXBM(32, 50, play_width, play_height, play_bits);
630  u8g2->drawXBM(43, 51, tt_width, tt_height, stop_bits);
631  u8g2->drawXBM(77, 51, tt_width, tt_height, pse_bits);
632 
633  //Mode
634  u8g2->drawStr(2,10,"Play");
635  if(pidMode)
636  {
637  u8g2->drawStr(45,10,"PID ON");
638  }
639  else
640  {
641  u8g2->drawStr(45,10,"PID OFF");
642  }
643  u8g2->setFontMode(1);
644  u8g2->setDrawColor(1);
645  if(mode)
646  {
647  //u8g2->drawStr(2,25,"Adjust velocity");
648  }
649  else
650  {
651  u8g2->drawStr(2,25,"Moving to pos");
652  String(index).toCharArray(buf, 5);
653  u8g2->drawStr(90,25,buf);
654  }
655  u8g2->drawStr(2,40,"Speed:");
656  String(this->velocity).toCharArray(buf, 5);
657  u8g2->drawStr(60,40,buf);
658  } while ( u8g2->nextPage() );
659 }
660 
661 void egoShield::pausePage(bool loopMode, bool pidMode, uint8_t index)
662 {
663  char buf[3];//char array buffer
664 
665  u8g2->firstPage();
666  do
667  {
668  u8g2->drawBox(1, 1, 128, 12);
669  u8g2->drawBox(1, 48, 128, 68);
670  u8g2->setFontMode(0);
671  u8g2->setDrawColor(0);
672  u8g2->setFontDirection(0);
673  u8g2->setFont(u8g2_font_6x10_tf);
674 
675  if(loopMode)
676  {
677  u8g2->drawXBM(110, 2, loop_width, loop_height, loop_bits);
678  }
679 
680  //Bottom bar
681  u8g2->drawXBM(32, 50, play_width, play_height, play_bits);
682  u8g2->drawXBM(43, 51, tt_width, tt_height, stop_bits);
683 
684  //Mode
685  u8g2->drawStr(2,10,"Pause");
686  if(pidMode)
687  {
688  u8g2->drawStr(45,10,"PID ON");
689  }
690  else
691  {
692  u8g2->drawStr(45,10,"PID OFF");
693  }
694  u8g2->setFontMode(1);
695  u8g2->setDrawColor(1);
696  u8g2->drawStr(2,35,"Paused at pos");
697  String(index).toCharArray(buf, 3);
698  u8g2->drawStr(90,35,buf);
699  } while ( u8g2->nextPage() );
700 }
701 
702 //BT skal ikke have helt samme funktionalitet som oled. Hvis man vil køre frem eller tilbage manuelt, så skal man skrive x antal grader plus eller minus. Man skal også kunne stoppe
703 //mens den kører... Skærm skal vise simpel menu, hvor man kan se status på pid on/off og hvad mode man er i. Mulighederne skal også fremgå af skærmen, e.g. p = play
704 //encoder pos skal også opdateres vi bt. Vi skal kunne cleare terminalen for at få en ny menu?
705 
706 void egoShield::debounce(buttons *btn, uint8_t sample)
707 {
708  if(btn->state == DEPRESSED)
709  {
710  btn->debounce &= (0xFE + sample);
711 
712  if( (btn->debounce & 0x1F) == 0x00)
713  {
714  btn->state = PRESSED;
715  btn->btn = 1;
716  return;
717  }
718 
719  btn->debounce <<= 1;
720  btn->debounce |= 0x01;
721  }
722 
723  else if((btn->state == PRESSED) || (btn->state == HOLD))
724  {
725  btn->debounce |= sample;
726 
727  if(btn->state != HOLD)
728  {
729  if((btn->debounce & 0x1F) == 0x00)
730  {
731  if(btn->holdCnt >= HOLDTIME)
732  {
733  btn->state = HOLD;
734  }
735  btn->holdCnt++;
736  }
737  }
738 
739  if( (btn->debounce & 0x1F) == 0x1F)
740  {
741  btn->state = DEPRESSED;
742  btn->holdCnt = 0;
743  return;
744  }
745 
746  btn->debounce <<= 1;
747  btn->debounce &= 0xFE;
748  }
749 
750  if(btn->state == HOLD)
751  {
752  if(btn->time == HOLDTICK)
753  {
754  btn->btn = 1;
755  btn->time = 0;
756  }
757 
758  else
759  {
760  btn->time++;
761  }
762  }
763 }
764 
766 {
767  btn->time = 0;
768  btn->state = DEPRESSED;
769  btn->debounce = 0x1F;
770  btn->holdCnt = 0;
771  btn->btn = 0;
772 }
774 {
775  this->resetButton(&playBtn);
776  this->resetButton(&forwardBtn);
777  this->resetButton(&backwardsBtn);
778  this->resetButton(&recordBtn);
779 }
uint8_t place
uint8_t endmove
void loop(void)
Contains the main logic of the shield functionality, e.g. transition between states (idle...
void playPage(bool loopMode, bool pidMode, uint8_t index, bool mode)
Holds the code for the play page of the OLED.
Watchdog timer interrupt handler, for examining the buttons periodically.
void recordMode(void)
Holds the record logic, showing the record page and recording positions from user input...
uStepper stepper
Creates an uStepper instance.
void changeVelocity(bool speedDirection=1)
Holds the code for the changing velocity during sequence play.
void idleMode(void)
Holds the idle logic; page to show, what buttons to enable etc.
void debounce(buttons *btn, uint8_t sample)
This function handles the debouncing and tracking of whether buttons are pressed, released or held...
void resetAllButton()
Resets the state of all 4 buttons at once.
float resolution
volatile buttons recordBtn
#define BWBT
#define OPTO
uint8_t debounce
void recordPage(bool pidMode, bool recorded, uint8_t index, float pos)
Holds the code for the record page of the OLED.
uint16_t acceleration
void idlePage(bool pidMode, float pos)
Holds the code for the idle page of the OLED.
Function prototypes and definitions for the egoShield library.
U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI * u8g2
volatile buttons playBtn
void playMode(void)
Holds the play logic, showing play page and running the recorded sequence.
uint8_t microStepping
float pos[CNT]
void pauseMode(void)
Holds the pause logic, showing the pause page and pausing the playing of a sequence.
#define PLBT
void resetButton(buttons *btn)
Function for resetting the state of a button seperately.
struct to hold information required to debounce button.
#define RECBT
uint16_t time
uint16_t velocity
void inputs(void)
Reads the four buttons and writes their value; no push, short push or long push, to global variables...
#define RESETWDT
uint8_t btn
#define CNT
#define FWBT
uint8_t state
uint16_t faultTolerance
void startPage(void)
Holds the code for the start page of the OLED.
volatile buttons forwardBtn
float stepSize
void pausePage(bool loopMode, bool pidMode, uint8_t index)
Holds the code for the pause page of the OLED.
void WDT_vect(void) __attribute__((signal
float setPoint
uint16_t faultHysteresis
volatile buttons backwardsBtn
egoShield(void)
Constructor of egoShield class.
uint16_t interval
void setup(uint16_t acc=1500, uint16_t vel=1000, uint8_t uStep=SIXTEEN, uint16_t fTol=10, uint16_t fHys=5, float P=1.0, float I=0.02, float D=0.006, float res=1)
Initializes buttons, OLED, uStepper and BT-module.
uint8_t holdCnt