MakeBlock Drive Updated Updated library for MakeBlock Ranger

Loading...
Searching...
No Matches
MeEncoderNew.h
Go to the documentation of this file.
1
63#ifndef ME_LEGOENCODER_H
64#define ME_LEGOENCODER_H
65#include <Arduino.h>
66#include <stdbool.h>
67#include "MeConfig.h"
68#include "MePort.h"
69
70#define LEONARDO_PORT1
71
72#if defined(UNO_PORT1) //10:PB3 11:PB2
73#define SDA_PORT PORTB
74#define SDA_PIN 3
75#define SCL_PORT PORTB
76#define SCL_PIN 2
77#define I2C_SLOWMODE 1
78#elif defined(UNO_PORT2) //3:PD3 9:PB1
79#define SDA_PORT PORTD
80#define SDA_PIN 3
81#define SCL_PORT PORTB
82#define SCL_PIN 1
83#define I2C_SLOWMODE 1
84#elif defined(LEONARDO_PORT1) //11:PB7 8:PB4
85#define SDA_PORT PORTB
86#define SDA_PIN 7
87#define SCL_PORT PORTB
88#define SCL_PIN 4
89#define I2C_SLOWMODE 1
90#elif defined(LEONARDO_PORT2) //13:PC7 12:PD6
91#define SDA_PORT PORTC
92#define SDA_PIN 7
93#define SCL_PORT PORTD
94#define SCL_PIN 6
95#define I2C_SLOWMODE 1
96#else
97// change sda scl if you use a different pin mapping
98#endif
99
100#define PULSE_PER_C 8
101
107 class MeEncoderNew{
108 public:
117 MeEncoderNew(uint8_t addr,uint8_t slot);
118
125 MeEncoderNew(uint8_t slot);
126
133 MeEncoderNew(void);
134
149 void begin(void);
150
167 void setAddr(uint8_t i2cAddr,uint8_t slot);
168
181 void reset(void);
182
201 void move(long angle, float speed = 220, float lock_state = 1);
202
221 void moveTo(long angle, float speed = 220, float lock_state = 1);
222
241 void runTurns(long turns, float speed = 220,float lock_state = 1);
242
257 void runSpeed(float speed,float lock_state = 1);
258
273 float getCurrentSpeed(void);
274
289 void setCurrentPosition(long pulse_counter);
290
305 long getCurrentPosition(void);
306
325 void setSpeedPID(float p,float i,float d);
326
345 void setPosPID(float p,float i,float d);
346
365 void getSpeedPID(float * p,float * i,float * d);
366
385 void getPosPID(float * p,float * i,float * d);
386
401 float getRatio(void);
402
417 void setRatio(float r);
418
433 int getPulse(void);
434
449 void setPulse(int p);
450
465 void setDevid(uint8_t devid);
466
481 void setMode(uint8_t mode);
482
497 void setPWM(int pwm);
498
517 void runSpeedAndTime(float speed, float time, float lock_state = 1);
518
534 boolean isTarPosReached(void);
535
549 void getFirmwareVersion(char *buffer);
550
551 private:
566 void sendCmd(void);
567
568 uint8_t _slot;
569 uint8_t address;
570 unsigned long _lastTime;
571 char cmdBuf[18];
572};
573
574#endif
575
576
577
MeConfig.h
Configuration file of library.
MePort.h
Header for MePort.cpp module.
MeEncoderNew
Driver for Me Encoder New module.
Definition MeEncoderNew.h:107
MeEncoderNew::getFirmwareVersion
void getFirmwareVersion(char *buffer)
Definition MeEncoderNew.cpp:812
MeEncoderNew::setRatio
void setRatio(float r)
Definition MeEncoderNew.cpp:651
MeEncoderNew::isTarPosReached
boolean isTarPosReached(void)
Definition MeEncoderNew.cpp:782
MeEncoderNew::getCurrentSpeed
float getCurrentSpeed(void)
Definition MeEncoderNew.cpp:567
MeEncoderNew::reset
void reset(void)
Definition MeEncoderNew.cpp:295
MeEncoderNew::moveTo
void moveTo(long angle, float speed=220, float lock_state=1)
Definition MeEncoderNew.cpp:223
MeEncoderNew::setCurrentPosition
void setCurrentPosition(long pulse_counter)
Definition MeEncoderNew.cpp:419
MeEncoderNew::runSpeed
void runSpeed(float speed, float lock_state=1)
Definition MeEncoderNew.cpp:250
MeEncoderNew::getRatio
float getRatio(void)
Definition MeEncoderNew.cpp:620
MeEncoderNew::getPulse
int getPulse(void)
Definition MeEncoderNew.cpp:673
MeEncoderNew::setPulse
void setPulse(int p)
Definition MeEncoderNew.cpp:704
MeEncoderNew::setAddr
void setAddr(uint8_t i2cAddr, uint8_t slot)
Definition MeEncoderNew.cpp:170
MeEncoderNew::setPosPID
void setPosPID(float p, float i, float d)
Definition MeEncoderNew.cpp:349
MeEncoderNew::begin
void begin(void)
Definition MeEncoderNew.cpp:149
MeEncoderNew::setDevid
void setDevid(uint8_t devid)
Definition MeEncoderNew.cpp:726
MeEncoderNew::MeEncoderNew
MeEncoderNew(void)
Definition MeEncoderNew.cpp:130
MeEncoderNew::getPosPID
void getPosPID(float *p, float *i, float *d)
Definition MeEncoderNew.cpp:524
MeEncoderNew::setMode
void setMode(uint8_t mode)
Definition MeEncoderNew.cpp:373
MeEncoderNew::runSpeedAndTime
void runSpeedAndTime(float speed, float time, float lock_state=1)
Definition MeEncoderNew.cpp:752
MeEncoderNew::getCurrentPosition
long getCurrentPosition(void)
Definition MeEncoderNew.cpp:442
MeEncoderNew::setSpeedPID
void setSpeedPID(float p, float i, float d)
Definition MeEncoderNew.cpp:321
MeEncoderNew::runTurns
void runTurns(long turns, float speed=220, float lock_state=1)
Definition MeEncoderNew.cpp:278
MeEncoderNew::move
void move(long angle, float speed=220, float lock_state=1)
Definition MeEncoderNew.cpp:194
MeEncoderNew::setPWM
void setPWM(int pwm)
Definition MeEncoderNew.cpp:396
MeEncoderNew::getSpeedPID
void getSpeedPID(float *p, float *i, float *d)
Definition MeEncoderNew.cpp:477