egoShield
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
egoShield Class Reference

Watchdog timer interrupt handler, for examining the buttons periodically. More...

#include <egoShieldTeach.h>

Public Member Functions

 egoShield (void)
 Constructor of egoShield class. More...
 
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. More...
 
void loop (void)
 Contains the main logic of the shield functionality, e.g. transition between states (idle, play, record and pause).
 

Public Attributes

uStepper stepper
 Creates an uStepper instance.
 

Private Member Functions

void resetButton (buttons *btn)
 Function for resetting the state of a button seperately. More...
 
void resetAllButton ()
 Resets the state of all 4 buttons at once.
 
void inputs (void)
 Reads the four buttons and writes their value; no push, short push or long push, to global variables.
 
uint8_t buttonState (uint8_t button, uint8_t nmbr)
 Returns the button state of the appropriate button. More...
 
void idleMode (void)
 Holds the idle logic; page to show, what buttons to enable etc.
 
void playMode (void)
 Holds the play logic, showing play page and running the recorded sequence.
 
void recordMode (void)
 Holds the record logic, showing the record page and recording positions from user input.
 
void pauseMode (void)
 Holds the pause logic, showing the pause page and pausing the playing of a sequence.
 
void timeMode (void)
 Holds the timelapse logic, showing the timelapse page.
 
void manForward (void)
 Holds the manual forward logic for driving the stepper motor manually with the pushbuttons.
 
void manBackward (void)
 Holds the manual backward logic for driving the stepper motor manually with the pushbuttons.
 
void startPage (void)
 Holds the code for the start page of the OLED.
 
void idlePage (bool pidMode, float pos)
 Holds the code for the idle page of the OLED. More...
 
void recordPage (bool pidMode, bool recorded, uint8_t index, float pos)
 Holds the code for the record page of the OLED. More...
 
void playPage (bool loopMode, bool pidMode, uint8_t index, bool mode)
 Holds the code for the play page of the OLED. More...
 
void pausePage (bool loopMode, bool pidMode, uint8_t index)
 Holds the code for the pause page of the OLED. More...
 
void changeVelocity (bool speedDirection=1)
 Holds the code for the changing velocity during sequence play.
 
void debounce (buttons *btn, uint8_t sample)
 This function handles the debouncing and tracking of whether buttons are pressed, released or held. More...
 

Private Attributes

SoftwareSerial * BTSerial
 
U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI * u8g2
 
uint8_t place
 
uint8_t endmove
 
float pos [CNT]
 
bool pidFlag
 
bool record
 
bool loopMode
 
bool longPushFlag [4]
 
char state
 
uint8_t rec
 
uint8_t play
 
uint8_t fw
 
uint8_t bw
 
float setPoint
 
uint16_t acceleration
 
uint16_t velocity
 
uint8_t microStepping
 
uint16_t faultTolerance
 
uint16_t faultHysteresis
 
float pTerm
 
float iTerm
 
float dTerm
 
float stepSize
 
uint16_t interval
 
float resolution
 
bool brakeFlag
 
volatile buttons forwardBtn = {0x1F, DEPRESSED, 0, 0, 0}
 
volatile buttons playBtn = {0x1F, DEPRESSED, 0, 0, 0}
 
volatile buttons recordBtn = {0x1F, DEPRESSED, 0, 0, 0}
 
volatile buttons backwardsBtn = {0x1F, DEPRESSED, 0, 0, 0}
 

Friends

void used
 
void WDT_vect (void) __attribute__((signal
 

Detailed Description

Watchdog timer interrupt handler, for examining the buttons periodically.

The Watchdog is configured to interrupt once every 16ms, to examine the IO state of the buttons, and performing the debouncing. The debouncing algorithm looks at the last five measured IO states of each button individually, to determine whether a button has finished bouncing or not. In order to see if the button is held or just pressed, a counter (seperate for each button) is incremented every time all the last five measurements are identical and if this counter reaches the value "HOLDTIME", the button are considered held. If any IO measurement is different from the last one, the counter is reset.

Definition at line 221 of file egoShieldTeach.h.

Constructor & Destructor Documentation

◆ egoShield()

egoShield::egoShield ( void  )

Constructor of egoShield class.

This is the constructor of the egoShield class. No arguments are present in the constructor.

Definition at line 76 of file egoShieldTeach.cpp.

Member Function Documentation

◆ buttonState()

uint8_t egoShield::buttonState ( uint8_t  button,
uint8_t  nmbr 
)
private

Returns the button state of the appropriate button.

Parameters
[in]buttonis set to either of the four available buttons.
[in]nmbris used for indexing in the longPushFlag array.
Returns
0 - no push detected.
1 - short push detected.
2 - long push detected.

◆ debounce()

void egoShield::debounce ( buttons btn,
uint8_t  sample 
)
private

This function handles the debouncing and tracking of whether buttons are pressed, released or held.

Parameters
[in]btnis a pointer to the struct off the button currently being examined
[in]sampleis a representation of the current button IO state

Definition at line 706 of file egoShieldTeach.cpp.

◆ idlePage()

void egoShield::idlePage ( bool  pidMode,
float  pos 
)
private

Holds the code for the idle page of the OLED.

Parameters
[in]pidModetells if the display should show PID ON or PID OFF.
[in]posis the encoder position to be displayed.

Definition at line 513 of file egoShieldTeach.cpp.

◆ pausePage()

void egoShield::pausePage ( bool  loopMode,
bool  pidMode,
uint8_t  index 
)
private

Holds the code for the pause page of the OLED.

Parameters
[in]loopModetells if the display should show loop symbol.
[in]pidModetells if the display should show PID ON or PID OFF.
[in]indextells which step we are at.

Definition at line 661 of file egoShieldTeach.cpp.

◆ playPage()

void egoShield::playPage ( bool  loopMode,
bool  pidMode,
uint8_t  index,
bool  mode 
)
private

Holds the code for the play page of the OLED.

Parameters
[in]loopModetells if the display should show loop symbol.
[in]pidModetells if the display should show PID ON or PID OFF.
[in]indextells which step we are at.

Definition at line 607 of file egoShieldTeach.cpp.

◆ recordPage()

void egoShield::recordPage ( bool  pidMode,
bool  recorded,
uint8_t  index,
float  pos 
)
private

Holds the code for the record page of the OLED.

Parameters
[in]pidModetells if the display should show PID ON or PID OFF.
[in]recordedtells if a step has been recorded.
[in]indextells which step we are at.
[in]posis the encoder position to be displayed.

Definition at line 556 of file egoShieldTeach.cpp.

◆ resetButton()

void egoShield::resetButton ( buttons btn)
private

Function for resetting the state of a button seperately.

Parameters
[in]btnis a Pointer to the button struct variable needed to be reset

Definition at line 765 of file egoShieldTeach.cpp.

◆ setup()

void egoShield::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.

Parameters
[in]acctakes in the maximum acceleration in play mode.
[in]veltakes in the maximum velocity in play mode.
[in]uSteptakes in the microstepping setting.
[in]fToltakes in the fault tolerance for the PID in steps, i.e. how much error is allowed before correction.
[in]fHystakes fault hysteresis in steps, i.e. when is the PID deactivated again.
[in]Ptakes in the PID P term.
[in]Itakes in the PID I term.
[in]Dtakes in the PID D term.
[in]restakes in the resolution of the drive in deg/mm.

Definition at line 81 of file egoShieldTeach.cpp.

Friends And Related Function Documentation

◆ WDT_vect

void WDT_vect ( void  )
friend

Periodic interrupt to sample buttons

Definition at line 69 of file egoShieldTeach.cpp.

Member Data Documentation

◆ acceleration

uint16_t egoShield::acceleration
private

This variable holds the acceleration used during playback of the sequence

Definition at line 300 of file egoShieldTeach.h.

◆ backwardsBtn

volatile buttons egoShield::backwardsBtn = {0x1F, DEPRESSED, 0, 0, 0}
private

Declaration of structs for backwards button

Definition at line 327 of file egoShieldTeach.h.

◆ brakeFlag

bool egoShield::brakeFlag
private

This variable holds the brake flag

Definition at line 322 of file egoShieldTeach.h.

◆ BTSerial

SoftwareSerial* egoShield::BTSerial
private

Creates an SoftwareSerial instance for BT-module

Definition at line 270 of file egoShieldTeach.h.

◆ bw

uint8_t egoShield::bw
private

This variable holds the current state of the backward button, which tells whether no, short or long push has been detected

Definition at line 296 of file egoShieldTeach.h.

◆ dTerm

float egoShield::dTerm
private

This variable holds the PID D term

Definition at line 314 of file egoShieldTeach.h.

◆ endmove

uint8_t egoShield::endmove
private

This variable holds the final step number in the recorded sequence

Definition at line 276 of file egoShieldTeach.h.

◆ faultHysteresis

uint16_t egoShield::faultHysteresis
private

This variable holds the fault hysteresis setting

Definition at line 308 of file egoShieldTeach.h.

◆ faultTolerance

uint16_t egoShield::faultTolerance
private

This variable holds the fault tolerance setting

Definition at line 306 of file egoShieldTeach.h.

◆ forwardBtn

volatile buttons egoShield::forwardBtn = {0x1F, DEPRESSED, 0, 0, 0}
private

Declaration of structs for forward button

Definition at line 324 of file egoShieldTeach.h.

◆ fw

uint8_t egoShield::fw
private

This variable holds the current state of the forward button, which tells whether no, short or long push has been detected

Definition at line 294 of file egoShieldTeach.h.

◆ interval

uint16_t egoShield::interval
private

This variable holds the interval for timelapse

Definition at line 318 of file egoShieldTeach.h.

◆ iTerm

float egoShield::iTerm
private

This variable holds the PID I term

Definition at line 312 of file egoShieldTeach.h.

◆ longPushFlag

bool egoShield::longPushFlag[4]
private

This array indicates whether one of the buttons have experienced a long duration push

Definition at line 286 of file egoShieldTeach.h.

◆ loopMode

bool egoShield::loopMode
private

This variable indicates whether we are in loop mode during playback

Definition at line 284 of file egoShieldTeach.h.

◆ microStepping

uint8_t egoShield::microStepping
private

This variable holds the microstepping setting

Definition at line 304 of file egoShieldTeach.h.

◆ pidFlag

bool egoShield::pidFlag
private

This variable indicates if PID is enabled

Definition at line 280 of file egoShieldTeach.h.

◆ place

uint8_t egoShield::place
private

This variable holds the step number in the recorded sequence

Definition at line 274 of file egoShieldTeach.h.

◆ play

uint8_t egoShield::play
private

This variable holds the current state of the play button, which tells whether no, short or long push has been detected

Definition at line 292 of file egoShieldTeach.h.

◆ playBtn

volatile buttons egoShield::playBtn = {0x1F, DEPRESSED, 0, 0, 0}
private

Declaration of structs for play button

Definition at line 325 of file egoShieldTeach.h.

◆ pos

float egoShield::pos[CNT]
private

This array holds the encoder value at the recorded positions

Definition at line 278 of file egoShieldTeach.h.

◆ pTerm

float egoShield::pTerm
private

This variable holds the PID P term

Definition at line 310 of file egoShieldTeach.h.

◆ rec

uint8_t egoShield::rec
private

This variable holds the current state of the record button, which tells whether no, short or long push has been detected

Definition at line 290 of file egoShieldTeach.h.

◆ record

bool egoShield::record
private

This variable indicates whether we are recording

Definition at line 282 of file egoShieldTeach.h.

◆ recordBtn

volatile buttons egoShield::recordBtn = {0x1F, DEPRESSED, 0, 0, 0}
private

Declaration of structs for record button

Definition at line 326 of file egoShieldTeach.h.

◆ resolution

float egoShield::resolution
private

This variable holds the resolution deg/mm

Definition at line 320 of file egoShieldTeach.h.

◆ setPoint

float egoShield::setPoint
private

This variable holds the current set-point to the PID, either from manual control or during playback of the sequence

Definition at line 298 of file egoShieldTeach.h.

◆ state

char egoShield::state
private

This variable holds the current state of the program, which tells whether the program is in idle, play, record or pause mode

Definition at line 288 of file egoShieldTeach.h.

◆ stepSize

float egoShield::stepSize
private

This variable holds the stepSize for timelapse

Definition at line 316 of file egoShieldTeach.h.

◆ u8g2

U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI* egoShield::u8g2
private

Creates an u8g2 (OLED) instance

Definition at line 272 of file egoShieldTeach.h.

◆ velocity

uint16_t egoShield::velocity
private

This variable holds the velocity used during playback of the sequence

Definition at line 302 of file egoShieldTeach.h.


The documentation for this class was generated from the following files: