egoShield
egoShield.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * File: egoShield.h *
3 * Version: 0.1.0 *
4 * Date: September 4th, 2017 *
5 * Author: Mogens Groth Nicolaisen *
6 * *
7 *********************************************************************************************
8 * (C) 2017 *
9 * *
10 * ON Development IVS *
11 * www.on-development.com *
12 * administration@on-development.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 ON Development IVS nor the author, can be held responsible for any damage *
20 * caused by the use of the code contained in this file ! *
21 * *
22 ********************************************************************************************/
103 #ifndef egoShield_h
104 #define egoShield_h
105 
106 #include "uStepper.h"
107 #include "U8g2lib.h"
108 #include "SPI.h"
109 #include "Arduino.h"
110 
111 #define FWBT A3
112 #define PLBT A1
113 #define RECBT A2
114 #define BWBT A0
115 #define CNT 50
116 
118 #define FULL 1
119 
120 #define HALF 2
121 
122 #define QUARTER 4
123 
124 #define EIGHT 8
125 
126 #define SIXTEEN 16
127 
128 #define en_width 11
129 #define en_height 9
130 static unsigned char fw_bits[] = {
131  0x41, 0x00, 0xc3, 0x00, 0xc7, 0x01, 0xcf, 0x03, 0xdf, 0x07, 0xcf, 0x03,
132  0xc7, 0x01, 0xc3, 0x00, 0x41, 0x00 };
133 static unsigned char bw_bits[] = {
134  0x10, 0x04, 0x18, 0x06, 0x1c, 0x07, 0x9e, 0x07, 0xdf, 0x07, 0x9e, 0x07,
135  0x1c, 0x07, 0x18, 0x06, 0x10, 0x04 };
136 #define tt_width 10
137 #define tt_height 10
138 static unsigned char rec_bits[] = {
139  0xfc, 0x00, 0xfe, 0x01, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03,
140  0xff, 0x03, 0xff, 0x03, 0xfe, 0x01, 0xfc, 0x00 };
141 static unsigned char stop_bits[] = {
142  0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03,
143  0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03 };
144 static unsigned char pse_bits[] = {
145  0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00,
146  0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00 };
147 #define play_width 6
148 #define play_height 11
149 static unsigned char play_bits[] = {
150  0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
151 #define loop_width 11
152 #define loop_height 10
153 static unsigned char loop_bits[] = {
154  0x04, 0x00, 0x08, 0x00, 0x9e, 0x03, 0x09, 0x04, 0x05, 0x04, 0x01, 0x05,
155  0x81, 0x04, 0xce, 0x03, 0x80, 0x00, 0x00, 0x01 };
156 #define logo_width 90
157 #define logo_height 16
158 static unsigned char logo_bits[] = {
159  0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
160  0x00, 0x80, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
161  0x00, 0xc0, 0xff, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
162  0x00, 0xc0, 0xc7, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163  0x3e, 0xcf, 0x07, 0xfc, 0xe3, 0xc3, 0x7b, 0x78, 0x0f, 0x3e, 0x9c, 0x01,
164  0xdf, 0xcf, 0x3f, 0xfe, 0xf3, 0xf7, 0xff, 0xfe, 0x1f, 0x7f, 0xff, 0x03,
165  0x3e, 0xcf, 0xff, 0x78, 0x38, 0xc7, 0xf3, 0x78, 0x9e, 0x73, 0xfe, 0x03,
166  0x3c, 0x8f, 0xff, 0x79, 0xfc, 0xcf, 0xf3, 0x79, 0xde, 0xff, 0xbc, 0x01,
167  0x1c, 0x47, 0xfe, 0x78, 0xfc, 0xcf, 0xf3, 0x78, 0xbe, 0x7f, 0x1e, 0x00,
168  0x3c, 0xef, 0xf0, 0x79, 0x38, 0xc0, 0xf3, 0x79, 0xde, 0x03, 0x1e, 0x00,
169  0xbe, 0xcf, 0xff, 0x78, 0x78, 0xc4, 0xf3, 0x78, 0x9e, 0x47, 0x3e, 0x00,
170  0xfc, 0xdf, 0x7f, 0xf8, 0xf3, 0xc7, 0x7f, 0xf8, 0x0f, 0x7f, 0x7e, 0x00,
171  0x38, 0x07, 0x3f, 0xf0, 0xe1, 0xc3, 0x3f, 0xf8, 0x07, 0x3e, 0x7f, 0x00,
172  0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x7c, 0x00, 0x00, 0x00, 0x00,
173  0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00,
174  0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00 };
175 
177 {
178 public:
184  egoShield(void);
204  void egoShield::setup(uint16_t acc = 1500,
205  uint16_t vel = 1000,
206  uint8_t uStep = SIXTEEN,
207  uint16_t fTol = 10,
208  uint16_t fHys = 5,
209  float P = 1.0,
210  float I = 0.02,
211  float D = 0.006);
215  void loop(void);
219  uStepper stepper;
220 private:
222  U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI *u8g2;
224  uint8_t place;
226  uint8_t endmove;
228  float pos[CNT];
230  bool pidFlag;
232  bool record;
234  bool loopMode;
236  bool longPushFlag[4];
238  char state;
240  uint8_t rec;
242  uint8_t play;
244  uint8_t fw;
246  uint8_t bw;
248  float setPoint;
250  uint16_t acceleration;
252  uint16_t velocity;
254  uint8_t microStepping;
256  uint16_t faultTolerance;
258  uint16_t faultHysteresis;
260  float pTerm;
262  float iTerm;
264  float dTerm;
268  void inputs(void);
281  uint8_t buttonState(uint8_t button, uint8_t nmbr);
285  void idleMode(void);
289  void playMode(void);
293  void recordMode(void);
297  void pauseMode(void);
301  void fastForward(void);
305  void fastBackward(void);
309  void startPage(void);
317  void idlePage(bool pidMode, float pos);
329  void recordPage(bool pidMode, bool recorded, uint8_t index, float pos);
339  void playPage(bool loopMode, bool pidMode, uint8_t index);
349  void pausePage(bool loopMode, bool pidMode, uint8_t index);
350 };
351 #endif
uint8_t place
Definition: egoShield.h:224
uint8_t endmove
Definition: egoShield.h:226
void loop(void)
Contains the main logic of the shield functionality, e.g. transition between states (idle...
Definition: egoShield.cpp:100
void recordMode(void)
Holds the record logic, showing the record page and recording positions from user input...
Definition: egoShield.cpp:225
uStepper stepper
Creates an uStepper instance.
Definition: egoShield.h:219
float dTerm
Definition: egoShield.h:264
bool record
Definition: egoShield.h:232
void idleMode(void)
Holds the idle logic; page to show, what buttons to enable etc.
Definition: egoShield.cpp:123
uint8_t fw
Definition: egoShield.h:244
char state
Definition: egoShield.h:238
float iTerm
Definition: egoShield.h:262
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)
Initializes buttons, OLED, uStepper and BT-module.
Definition: egoShield.cpp:71
uint8_t play
Definition: egoShield.h:242
void recordPage(bool pidMode, bool recorded, uint8_t index, float pos)
Holds the code for the record page of the OLED.
Definition: egoShield.cpp:423
uint16_t acceleration
Definition: egoShield.h:250
void idlePage(bool pidMode, float pos)
Holds the code for the idle page of the OLED.
Definition: egoShield.cpp:381
#define SIXTEEN
Definition: egoShield.h:126
float pTerm
Definition: egoShield.h:260
U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI * u8g2
Definition: egoShield.h:222
void playMode(void)
Holds the play logic, showing play page and running the recorded sequence.
Definition: egoShield.cpp:178
uint8_t microStepping
Definition: egoShield.h:254
float pos[CNT]
Definition: egoShield.h:228
void pauseMode(void)
Holds the pause logic, showing the pause page and pausing the playing of a sequence.
Definition: egoShield.cpp:290
bool longPushFlag[4]
Definition: egoShield.h:236
uint8_t rec
Definition: egoShield.h:240
uint16_t velocity
Definition: egoShield.h:252
void fastForward(void)
Holds the fast forward logic for driving the stepper motor manually with the pushbuttons.
Definition: egoShield.cpp:339
void inputs(void)
Reads the four buttons and writes their value; no push, short push or long push, to global variables...
Definition: egoShield.cpp:303
void fastBackward(void)
Holds the fast backward logic for driving the stepper motor manually with the pushbuttons.
Definition: egoShield.cpp:356
bool pidFlag
Definition: egoShield.h:230
bool loopMode
Definition: egoShield.h:234
uint16_t faultTolerance
Definition: egoShield.h:256
void startPage(void)
Holds the code for the start page of the OLED.
Definition: egoShield.cpp:373
void pausePage(bool loopMode, bool pidMode, uint8_t index)
Holds the code for the pause page of the OLED.
Definition: egoShield.cpp:516
float setPoint
Definition: egoShield.h:248
uint16_t faultHysteresis
Definition: egoShield.h:258
uint8_t buttonState(uint8_t button, uint8_t nmbr)
Returns the button state of the appropriate button.
Definition: egoShield.cpp:311
uint8_t bw
Definition: egoShield.h:246
egoShield(void)
Constructor of egoShield class.
Definition: egoShield.cpp:66
void playPage(bool loopMode, bool pidMode, uint8_t index)
Holds the code for the play page of the OLED.
Definition: egoShield.cpp:473