MakeBlock Drive Updated Updated library for MakeBlock Ranger

Loading...
Searching...
No Matches
MeStepperOnBoard.h
Go to the documentation of this file.
1
62#ifndef MeStepperOnBoard_h
63#define MeStepperOnBoard_h
64
65#if ARDUINO >= 100
66 #include "Arduino.h"
67#else
68 #include "WProgram.h"
69 #include "stdlib.h"
70 #include "wiring.h"
71#endif
72
73#define NUM_SLOTS 4
74#define SLOT_NUM_PINS 8
75
76 typedef struct megaPi_slot
77 {
78 uint8_t pin[SLOT_NUM_PINS];
79 } megaPi_slot_type;
80
81 extern megaPi_slot_type megaPi_slots[NUM_SLOTS];
82
83// These defs cause trouble on some versions of Arduino
84#undef round
85 typedef void (*cb)(int,int);
91 class MeStepperOnBoard
92{
93 public:
100 MeStepperOnBoard();
101
107 MeStepperOnBoard(int slot);
108
123 void setMicroStep(int8_t value);
124
139 void setpin(int slot);
140
155 void moveTo(long absolute);
156
175 void moveTo(long absolute, int16_t extId, cb callback);
176
191 void move(long relative);
192
211 void move(long relative, int16_t extId, cb callback);
212
227 boolean run(void);
228
243 boolean runSpeed(void);
244
259 void setMaxSpeed(float speed);
260
275 void setAcceleration(float acceleration);
276
291 void setSpeed(float speed);
292
307 float speed(void);
308
323 long distanceToGo(void);
324
339 long targetPosition(void);
340
355 long currentPosition(void);
356
371 void setCurrentPosition(long position);
372
387 void runToPosition(void);
388
403 boolean runSpeedToPosition(void);
404
419 void runToNewPosition(long position);
420
435 void disableOutputs(void);
436
451 void enableOutputs(void);
452
467 void update(void);
482 virtual void step(void);
483
498 int16_t getPort(void);
499
500 protected:
515 void computeNewSpeed();
516 private:
517 uint8_t _dir_data;
518 uint8_t _step_data;
519 uint8_t _enable_pin;
520 uint8_t _micro_step_pin1;
521 uint8_t _micro_step_pin2;
522 uint8_t _micro_step_pin3;
523 uint8_t _reset_pin;
524 uint8_t _sleep_pin;
525 uint8_t _micro_step;
526 uint8_t _dir; // 2 or 4
527 long _currentPos; // Steps
528 long _targetPos; // Steps
529 float _speed; // Steps per second
530 float _maxSpeed;
531 float _acceleration;
532 unsigned long _stepInterval;
533 unsigned long _lastStepTime;
535 long _n;
536
538 float _c0;
539
541 float _cn;
542
544 float _cmin; // at max speed
545 cb _callback;
546 int16_t _slot;
547 int16_t _extId;
548 boolean _moving;
549 int16_t _mode;
550 boolean _enabled;
551};
552
553#endif
MeStepperOnBoard
Driver for Me Stepper on MegaPi.
Definition MeStepperOnBoard.h:92
MeStepperOnBoard::runSpeed
boolean runSpeed(void)
Definition MeStepperOnBoard.cpp:334
MeStepperOnBoard::update
void update(void)
Definition MeStepperOnBoard.cpp:834
MeStepperOnBoard::runToNewPosition
void runToNewPosition(long position)
Definition MeStepperOnBoard.cpp:774
MeStepperOnBoard::targetPosition
long targetPosition(void)
Definition MeStepperOnBoard.cpp:397
MeStepperOnBoard::step
virtual void step(void)
Definition MeStepperOnBoard.cpp:692
MeStepperOnBoard::getPort
int16_t getPort(void)
Definition MeStepperOnBoard.cpp:872
MeStepperOnBoard::run
boolean run(void)
Definition MeStepperOnBoard.cpp:548
MeStepperOnBoard::moveTo
void moveTo(long absolute)
Definition MeStepperOnBoard.cpp:239
MeStepperOnBoard::setAcceleration
void setAcceleration(float acceleration)
Definition MeStepperOnBoard.cpp:605
MeStepperOnBoard::setSpeed
void setSpeed(float speed)
Definition MeStepperOnBoard.cpp:636
MeStepperOnBoard::MeStepperOnBoard
MeStepperOnBoard()
Definition MeStepperOnBoard.cpp:78
MeStepperOnBoard::currentPosition
long currentPosition(void)
Definition MeStepperOnBoard.cpp:416
MeStepperOnBoard::setpin
void setpin(int slot)
Definition MeStepperOnBoard.cpp:193
MeStepperOnBoard::setMicroStep
void setMicroStep(int8_t value)
Definition MeStepperOnBoard.cpp:136
MeStepperOnBoard::runToPosition
void runToPosition(void)
Definition MeStepperOnBoard.cpp:721
MeStepperOnBoard::speed
float speed(void)
Definition MeStepperOnBoard.cpp:673
MeStepperOnBoard::distanceToGo
long distanceToGo(void)
Definition MeStepperOnBoard.cpp:378
MeStepperOnBoard::move
void move(long relative)
Definition MeStepperOnBoard.cpp:292
MeStepperOnBoard::setMaxSpeed
void setMaxSpeed(float speed)
Definition MeStepperOnBoard.cpp:576
MeStepperOnBoard::computeNewSpeed
void computeNewSpeed()
Definition MeStepperOnBoard.cpp:456
MeStepperOnBoard::disableOutputs
void disableOutputs(void)
Definition MeStepperOnBoard.cpp:794
MeStepperOnBoard::runSpeedToPosition
boolean runSpeedToPosition(void)
Definition MeStepperOnBoard.cpp:743
MeStepperOnBoard::enableOutputs
void enableOutputs(void)
Definition MeStepperOnBoard.cpp:814
MeStepperOnBoard::setCurrentPosition
void setCurrentPosition(long position)
Definition MeStepperOnBoard.cpp:435
megaPi_slot
Definition MeStepperOnBoard.h:77