MakeBlock Drive Updated Updated library for MakeBlock Ranger

Loading...
Searching...
No Matches
MeSmartServo.h
Go to the documentation of this file.
1
64#ifndef MeSmartServo_H
65#define MeSmartServo_H
66
67#include <stdint.h>
68#include <stdbool.h>
69#include <Arduino.h>
70#include "MeConfig.h"
71#include "MeSerial.h"
72
73#ifdef ME_PORT_DEFINED
74#include "MePort.h"
75#endif /* ME_PORT_DEFINED */
76
77#define ALL_DEVICE 0xff // Broadcast command identifies
78#define CUSTOM_TYPE 0x00 // 0x00 indicates no external module
79
80#define CTL_ASSIGN_DEV_ID 0x10 // Assignment device ID
81#define CTL_SYSTEM_RESET 0x11 // reset from host
82#define CTL_READ_DEV_VERSION 0x12 // read the firmware version
83#define CTL_SET_BAUD_RATE 0x13 // Set the bandrate
84#define CTL_CMD_TEST 0x14 // Just for test
85#define CTL_ERROR_CODE 0x15 // error code
86
87#define SMART_SERVO 0x60
88 /* Secondary command */
89 #define SET_SERVO_PID 0x10
90 #define SET_SERVO_ABSOLUTE_POS 0x11
91 #define SET_SERVO_RELATIVE_POS 0x12
92 #define SET_SERVO_CONTINUOUS_ROTATION 0x13
93 #define SET_SERVO_MOTION_COMPENSATION 0x14
94 #define CLR_SERVO_MOTION_COMPENSATION 0x15
95 #define SET_SERVO_BREAK 0x16
96 #define SET_SERVO_RGB_LED 0x17
97 #define SERVO_SHARKE_HAND 0x18
98 #define SET_SERVO_CMD_MODE 0x19
99
100 #define GET_SERVO_STATUS 0x20
101 #define GET_SERVO_PID 0x21
102 #define GET_SERVO_CUR_POS 0x22
103 #define GET_SERVO_SPEED 0x23
104 #define GET_SERVO_MOTION_COMPENSATION 0x24
105 #define GET_SERVO_TEMPERATURE 0x25
106 #define GET_SERVO_ELECTRIC_CURRENT 0x26
107 #define GET_SERVO_VOLTAGE 0x27
108
109 #define SET_SERVO_CURRENT_ANGLE_ZERO_DEGREES 0x30
110 #define SET_SERVO_ABSOLUTE_ANGLE 0x31
111 #define SET_SERVO_RELATIVE_ANGLE 0x32
112 #define SET_SERVO_ABSOLUTE_ANGLE_LONG 0x33
113 #define SET_SERVO_RELATIVE_ANGLE_LONG 0x34
114 #define SET_SERVO_PWM_MOVE 0x35
115 #define GET_SERVO_CUR_ANGLE 0x36
116 #define SET_SERVO_INIT_ANGLE 0x37
117 #define REPORT_WHEN_REACH_THE_SET_POSITION 0x40
118
119#define START_SYSEX 0xF0 // start a MIDI Sysex message
120#define END_SYSEX 0xF7 // end a MIDI Sysex message
121
122/* report error code */
123#define PROCESS_SUC 0x0F
124#define PROCESS_BUSY 0x10
125#define PROCESS_ERROR 0x11
126#define WRONG_TYPE_OF_SERVICE 0x12
127
128#define DEFAULT_UART_BUF_SIZE 64
129
130 typedef struct{
131 uint8_t dev_id;
132 uint8_t srv_id;
133 uint8_t value[DEFAULT_UART_BUF_SIZE - 2];
134}sysex_message_type;
135
136 typedef struct{
137 uint8_t service_id;
138 void (*request_fun)(void *arg);
139 void (*response_fun)(void *arg);
140}Cmd_list_tab_type;
141
142 union sysex_message{
143 uint8_t storedInputData[DEFAULT_UART_BUF_SIZE];
144 sysex_message_type val;
145};
146
147 union{
148 uint8_t byteVal[8];
149 double doubleVal;
150}val8byte;
151
152 union{
153 uint8_t byteVal[4];
154 float floatVal;
155 long longVal;
156}val4byte;
157
158 union{
159 uint8_t byteVal[2];
160 short shortVal;
161}val2byte;
162
163 union{
164 uint8_t byteVal[1];
165 uint8_t charVal;
166}val1byte;
167
168 typedef struct
169{
170 long angleValue;
171 float servoSpeed;
172 float voltage;
173 float temperature;
174 float current;
175}servo_device_type;
176
177 typedef void (*smartServoCb)(uint8_t);
178
184#ifndef ME_PORT_DEFINED
185 class MeSmartServo
186#else /* !ME_PORT_DEFINED */
187class MeSmartServo : public MeSerial
188#endif /* !ME_PORT_DEFINED */
189{
190 public:
191#ifdef ME_PORT_DEFINED
198 MeSmartServo();
199
206 MeSmartServo(uint8_t port);
207#else // ME_PORT_DEFINED
218 MeSmartServo(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic);
219#endif // ME_PORT_DEFINED
220
237 uint8_t readByte(uint8_t *argv,int16_t idx);
238
257 short readShort(uint8_t *argv,int16_t idx,boolean ignore_high);
258
275 float readFloat(uint8_t *argv,int16_t idx);
276
293 long readLong(uint8_t *argv,int idx);
294
309 uint8_t sendByte(uint8_t val);
310
327 uint8_t sendShort(int16_t val,boolean ignore_high);
328
343 uint8_t sendFloat(float val);
344
359 uint8_t sendLong(long val);
360
375 boolean assignDevIdRequest(void);
376
397 boolean moveTo(uint8_t dev_id,long angle_value,float speed,smartServoCb callback = NULL);
398
419 boolean move(uint8_t dev_id,long angle_value,float speed,smartServoCb callback = NULL);
420
435 boolean setZero(uint8_t dev_id);
436
453 boolean setBreak(uint8_t dev_id, uint8_t breakStatus);
454
475 boolean setRGBLed(uint8_t dev_id, uint8_t r_value, uint8_t g_value, uint8_t b_value);
476
491 boolean handSharke(uint8_t dev_id);
492
509 boolean setPwmMove(uint8_t dev_id, int16_t pwm_value);
510
529 boolean setInitAngle(uint8_t dev_id,uint8_t = 0,int16_t = 40);
530
545 long getAngleRequest(uint8_t devId);
546
561 float getSpeedRequest(uint8_t devId);
562
577 float getVoltageRequest(uint8_t devId);
578
593 float getTempRequest(uint8_t devId);
594
609 float getCurrentRequest(uint8_t devId);
610
625 void assignDevIdResponse(void *arg);
626
641 void errorCodeCheckResponse(void *arg);
642
657 void smartServoCmdResponse(void *arg);
658
673 void processSysexMessage(void);
674
689 void smartServoEventHandle(void);
690
691 private:
692 union sysex_message sysex;
693 volatile int16_t sysexBytesRead;
694 volatile uint8_t servo_num_max;
695 volatile uint16_t resFlag;
696 volatile servo_device_type servo_dev_list[8];
697 volatile long cmdTimeOutValue;
698 volatile boolean parsingSysex;
699 smartServoCb _callback;
700};
701#endif
MeConfig.h
Configuration file of library.
MePort.h
Header for MePort.cpp module.
MeSerial.h
Header for for MeSerial.cpp module.
MeSerial
Driver for serial.
Definition MeSerial.h:67
MeSmartServo
Driver for Me Smart Servo device.
Definition MeSmartServo.h:189
MeSmartServo::getSpeedRequest
float getSpeedRequest(uint8_t devId)
Definition MeSmartServo.cpp:879
MeSmartServo::readByte
uint8_t readByte(uint8_t *argv, int16_t idx)
Definition MeSmartServo.cpp:134
MeSmartServo::smartServoEventHandle
void smartServoEventHandle(void)
Definition MeSmartServo.cpp:1117
MeSmartServo::setRGBLed
boolean setRGBLed(uint8_t dev_id, uint8_t r_value, uint8_t g_value, uint8_t b_value)
Definition MeSmartServo.cpp:644
MeSmartServo::processSysexMessage
void processSysexMessage(void)
Definition MeSmartServo.cpp:1082
MeSmartServo::sendByte
uint8_t sendByte(uint8_t val)
Definition MeSmartServo.cpp:268
MeSmartServo::assignDevIdResponse
void assignDevIdResponse(void *arg)
Definition MeSmartServo.cpp:1054
MeSmartServo::setPwmMove
boolean setPwmMove(uint8_t dev_id, int16_t pwm_value)
Definition MeSmartServo.cpp:738
MeSmartServo::sendLong
uint8_t sendLong(long val)
Definition MeSmartServo.cpp:367
MeSmartServo::sendFloat
uint8_t sendFloat(float val)
Definition MeSmartServo.cpp:333
MeSmartServo::MeSmartServo
MeSmartServo()
Definition MeSmartServo.cpp:76
MeSmartServo::readShort
short readShort(uint8_t *argv, int16_t idx, boolean ignore_high)
Definition MeSmartServo.cpp:161
MeSmartServo::smartServoCmdResponse
void smartServoCmdResponse(void *arg)
Definition MeSmartServo.cpp:1194
MeSmartServo::handSharke
boolean handSharke(uint8_t dev_id)
Definition MeSmartServo.cpp:692
MeSmartServo::moveTo
boolean moveTo(uint8_t dev_id, long angle_value, float speed, smartServoCb callback=NULL)
Definition MeSmartServo.cpp:445
MeSmartServo::getTempRequest
float getTempRequest(uint8_t devId)
Definition MeSmartServo.cpp:966
MeSmartServo::setZero
boolean setZero(uint8_t dev_id)
Definition MeSmartServo.cpp:547
MeSmartServo::errorCodeCheckResponse
void errorCodeCheckResponse(void *arg)
Definition MeSmartServo.cpp:1166
MeSmartServo::move
boolean move(uint8_t dev_id, long angle_value, float speed, smartServoCb callback=NULL)
Definition MeSmartServo.cpp:499
MeSmartServo::sendShort
uint8_t sendShort(int16_t val, boolean ignore_high)
Definition MeSmartServo.cpp:298
MeSmartServo::assignDevIdRequest
boolean assignDevIdRequest(void)
Definition MeSmartServo.cpp:401
MeSmartServo::getAngleRequest
long getAngleRequest(uint8_t devId)
Definition MeSmartServo.cpp:835
MeSmartServo::getCurrentRequest
float getCurrentRequest(uint8_t devId)
Definition MeSmartServo.cpp:1010
MeSmartServo::readLong
long readLong(uint8_t *argv, int idx)
Definition MeSmartServo.cpp:232
MeSmartServo::getVoltageRequest
float getVoltageRequest(uint8_t devId)
Definition MeSmartServo.cpp:923
MeSmartServo::readFloat
float readFloat(uint8_t *argv, int16_t idx)
Definition MeSmartServo.cpp:194
MeSmartServo::setBreak
boolean setBreak(uint8_t dev_id, uint8_t breakStatus)
Definition MeSmartServo.cpp:593
MeSmartServo::setInitAngle
boolean setInitAngle(uint8_t dev_id, uint8_t=0, int16_t=40)
Definition MeSmartServo.cpp:788
Cmd_list_tab_type
Definition MeSmartServo.h:136
servo_device_type
Definition MeSmartServo.h:169
sysex_message_type
Definition MeSmartServo.h:130
sysex_message
Definition MeSmartServo.h:142