4 #include <driver/uart.h>
6 #include <soc/io_mux_reg.h>
50 Packet(
const uint8_t* data,
int len) {
51 for (
int i = 0; i < len; i++) {
52 _data.push_back(data[i]);
56 template <
typename... Args>
61 _data.push_back(
static_cast<uint8_t
>(c));
68 position & 0xFF, position >> 8,
69 time & 0xFF, time >> 8);
74 low & 0xFF, low >> 8, high & 0xFF, high >> 8);
86 _data.push_back(0x55);
87 _data.push_back(0x55);
92 template <
typename... Args>
99 static uint8_t
_checksum(
const std::vector<uint8_t>& data,
100 int offset = 2,
int end_offset = 0) {
102 for (
int i = offset; i < data.size() - end_offset; i++)
108 if (
_data.size() < 4)
114 if (
_data.size() < 6)
117 if (c !=
_data.back())
127 for (
auto x :
_data) {
131 printf(
"%02X", (
int)x);
142 return angle * 1000 / 240;
147 float position = pos.
deg();
148 int time = t.count();
149 if (position < 0 || position > 240)
150 ESP_LOGE(
"LX16A",
"Position out of range");
152 ESP_LOGE(
"LX16A",
"Time is negative");
154 ESP_LOGE(
"LX16A",
"Time is out of range");
160 float position = pos.
deg();
161 if (position < 0 || position > 240)
162 ESP_LOGE(
"LX16A",
"Position out of range");
169 int bottom = b.
deg();
171 if (bottom < 0 || bottom > 240)
172 ESP_LOGE(
"LX16A",
"Bottom limit out of range");
173 if (top < 0 || top > 240)
174 ESP_LOGE(
"LX16A",
"Top limit out of range");
181 ESP_LOGE(
"LX16A",
"Invalid ID specified");
Definition: lx16a.hpp:139
static int posFromDeg(float angle)
Definition: lx16a.hpp:141
static Packet limit(Id id, rb::Angle b, rb::Angle t)
Definition: lx16a.hpp:168
static Packet move(Id id, rb::Angle pos, std::chrono::milliseconds t)
Definition: lx16a.hpp:146
static Packet move(Id id, rb::Angle pos)
Definition: lx16a.hpp:159
static Packet setId(Id oldId, Id newId)
Definition: lx16a.hpp:179
Definition: RBControl_angle.hpp:11
static Angle deg(_T d)
Definition: RBControl_angle.hpp:20
Command
Definition: lx16a.hpp:14
@ SERVO_ANGLE_LIMIT_WRITE
@ SERVO_ANGLE_OFFSET_WRITE
@ SERVO_MOVE_TIME_WAIT_WRITE
@ SERVO_LOAD_OR_UNLOAD_WRITE
@ SERVO_ANGLE_OFFSET_READ
@ SERVO_TEMP_MAX_LIMIT_READ
@ SERVO_OR_MOTOR_MODE_WRITE
@ SERVO_MOVE_TIME_WAIT_READ
@ SERVO_ANGLE_OFFSET_ADJUST
@ SERVO_OR_MOTOR_MODE_READ
@ SERVO_TEMP_MAX_LIMIT_WRITE
@ SERVO_LOAD_OR_UNLOAD_READ
uint8_t Id
Definition: lx16a.hpp:45
static Packet move(Id id, uint16_t position, uint16_t time)
Definition: lx16a.hpp:66
Packet(Id id, Command c, Args... data)
Definition: lx16a.hpp:57
static Packet limitAngle(Id id, uint16_t low, uint16_t high)
Definition: lx16a.hpp:72
void _pushData()
Definition: lx16a.hpp:90
static uint8_t _checksum(const std::vector< uint8_t > &data, int offset=2, int end_offset=0)
Definition: lx16a.hpp:99
bool valid() const
Definition: lx16a.hpp:113
std::vector< uint8_t > _data
Definition: lx16a.hpp:136
Packet(const uint8_t *data, int len)
Definition: lx16a.hpp:50
static Packet setId(Id id, Id newId)
Definition: lx16a.hpp:77
int size() const
Definition: lx16a.hpp:107
static Packet getId(Id id)
Definition: lx16a.hpp:81
void _pushData(uint8_t d, Args... data)
Definition: lx16a.hpp:93
void dump()
Definition: lx16a.hpp:124
void _buildHeader()
Definition: lx16a.hpp:85