本文整理汇总了C++中SerialCommand类的典型用法代码示例。如果您正苦于以下问题:C++ SerialCommand类的具体用法?C++ SerialCommand怎么用?C++ SerialCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SerialCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SBGC_cmd_angles_unpack
uint8_t Gimbal::SBGC_cmd_angles_unpack(angulos &p, SerialCommand &cmd) {
for (uint8_t i = 0; i < 3; i++) {
switch (i)
{
case 0:
p.roll = cmd.readWord();
p.roll = p.roll*ESCALA;
break;
case 1:
p.pitch = cmd.readWord();
p.pitch = p.pitch*ESCALA;
break;
case 2:
p.yaw = cmd.readWord();
p.yaw = p.yaw*ESCALA;
break;
}
//Leemos dos veces, para consumir los datos rc_angle y rc_speed que no son necesarios.
cmd.readWord();
cmd.readWord();
}
if (cmd.checkLimit()) return 0;
else return PARSER_ERROR_WRONG_DATA_SIZE;
}
示例2: SBGC_cmd_trigger_pack
/* Packs command structure to SerialCommand object */
void SBGC_cmd_trigger_pack(SBGC_cmd_trigger_t &p, SerialCommand &cmd) {
cmd.init(SBGC_CMD_TRIGGER_PIN);
#ifdef SBGC_CMD_STRUCT_ALIGNED
memcpy(cmd.data, &p, sizeof(p));
cmd.len = sizeof(p);
#else
cmd.writeByte(p.pin);
cmd.writeByte(p.state);
#endif
}
示例3: SBGC_cmd_api_virt_ch_control_pack
/* Packs command structure to SerialCommand object */
void SBGC_cmd_api_virt_ch_control_pack(SBGC_cmd_api_virt_ch_control_t &p, SerialCommand &cmd) {
cmd.init(SBGC_CMD_API_VIRT_CH_CONTROL);
#ifdef SBGC_CMD_STRUCT_ALIGNED
memcpy(cmd.data, &p, sizeof(p));
cmd.len = sizeof(p);
#else
for(uint8_t i=0; i<SBGC_API_VIRT_NUM_CHANNELS; i++) {
cmd.writeByte(p.data[i]);
}
#endif
}
示例4: SBGC_cmd_servo_out_pack
/* Packs command structure to SerialCommand object */
void SBGC_cmd_servo_out_pack(SBGC_cmd_servo_out_t &p, SerialCommand &cmd) {
cmd.init(SBGC_CMD_SERVO_OUT);
#ifdef SBGC_CMD_STRUCT_ALIGNED
memcpy(cmd.data, &p, sizeof(p));
cmd.len = sizeof(p);
#else
for(uint8_t i=0; i<8; i++) {
cmd.writeWord(p.servo[i]);
}
#endif
}
示例5: SBGC_cmd_set_adj_vars_pack
/* Packs command structure to SerialCommand object */
void SBGC_cmd_set_adj_vars_pack(SBGC_cmd_set_adj_vars_var_t vars[], uint8_t vars_num, SerialCommand &cmd) {
cmd.init(SBGC_CMD_SET_ADJ_VARS_VAL);
cmd.writeByte(vars_num); // number of variables
#ifdef SBGC_CMD_STRUCT_ALIGNED
cmd.writeBuf(vars, sizeof(SBGC_cmd_set_adj_vars_var_t)*vars_num);
#else
for(uint8_t i=0; i<vars_num; i++) {
cmd.writeByte(vars[i].id);
cmd.writeLong(vars[i].val);
}
#endif
}
示例6: SBGC_cmd_control_ext_pack
/* Packs command structure to SerialCommand object */
void SBGC_cmd_control_ext_pack(SBGC_cmd_control_ext_t &p, SerialCommand &cmd) {
cmd.init(SBGC_CMD_CONTROL);
#ifdef SBGC_CMD_STRUCT_ALIGNED
memcpy(cmd.data, &p, sizeof(p));
cmd.len = sizeof(p);
#else
cmd.writeBuf(p.mode, 3);
for(uint8_t i=0; i<3; i++) {
cmd.writeWord(p.data[i].speed);
cmd.writeWord(p.data[i].angle);
}
#endif
}
示例7: SBGC_cmd_control_pack
/* Packs command structure to SerialCommand object */
void SBGC_cmd_control_pack(SBGC_cmd_control_t &p, SerialCommand &cmd) {
cmd.init(SBGC_CMD_CONTROL);
#ifdef SBGC_CMD_STRUCT_ALIGNED
memcpy(cmd.data, &p, sizeof(p));
cmd.len = sizeof(p);
#else
cmd.writeByte(p.mode);
cmd.writeWord(p.speedROLL);
cmd.writeWord(p.angleROLL);
cmd.writeWord(p.speedPITCH);
cmd.writeWord(p.anglePITCH);
cmd.writeWord(p.speedYAW);
cmd.writeWord(p.angleYAW);
#endif
}
示例8: executeSerialCommands
void executeSerialCommands()
{
while (Serial.available()) {
char c = Serial.read();
Serial.print(c); // echo
commandProcessor.update(c);
}
}
示例9: SBGC_cmd_set_adj_vars_unpack
/*
* Unpacks SerialCommand object to vars_buf[var_num].
* 'var_num' specifies the buffer capacity.
* On return, 'var_num' will be set to actual number of received variables.
* Returns 0 on success, PARSER_ERROR_XX code on fail.
*/
uint8_t SBGC_cmd_set_adj_vars_unpack(SBGC_cmd_set_adj_vars_var_t vars_buf[], uint8_t &vars_num, SerialCommand &cmd) {
uint8_t num = cmd.readByte(); // actual number of variables
if(num <= vars_num) {
vars_num = num;
#ifdef SBGC_CMD_STRUCT_ALIGNED
cmd.readBuf(vars_buf, sizeof(SBGC_cmd_set_adj_vars_var_t)*vars_num);
#else
for(uint8_t i=0; i<num; i++) {
vars_buf[i].id = cmd.readByte();
vars_buf[i].val = cmd.readLong();
}
#endif
if(cmd.checkLimit()) return 0;
else return PARSER_ERROR_WRONG_DATA_SIZE;
} else {
return PARSER_ERROR_BUFFER_IS_FULL;
}
}
示例10: SBGC_cmd_realtime_data_unpack
/*
* Unpacks SerialCommand object to command structure.
* Returns 0 on success, PARSER_ERROR_XX code on fail.
*/
uint8_t SBGC_cmd_realtime_data_unpack(SBGC_cmd_realtime_data_t &p, SerialCommand &cmd) {
#ifdef SBGC_CMD_STRUCT_ALIGNED
if(cmd.len <= sizeof(p)) {
memcpy(&p, cmd.data, cmd.len);
return 0;
} else {
return PARSER_ERROR_WRONG_DATA_SIZE;
}
#else
for(uint8_t i=0; i<3; i++) {
p.sensor_data[i].acc_data = cmd.readWord();
p.sensor_data[i].gyro_data = cmd.readWord();
}
p.serial_error_cnt = cmd.readWord();
p.system_error = cmd.readWord();
cmd.skipBytes(4); // reserved
cmd.readWordArr(p.rc_raw_data, SBGC_RC_NUM_CHANNELS);
cmd.readWordArr(p.imu_angle, 3);
cmd.readWordArr(p.frame_imu_angle, 3);
cmd.readWordArr(p.target_angle, 3);
p.cycle_time_us = cmd.readWord();
p.i2c_error_count = cmd.readWord();
cmd.readByte(); // reserved
p.battery_voltage = cmd.readWord();
p.state_flags1 = cmd.readByte();
p.cur_imu = cmd.readByte();
p.cur_profile = cmd.readByte();
cmd.readBuf(p.motor_power, 3);
if(cmd.id == SBGC_CMD_REALTIME_DATA_4) {
cmd.readWordArr(p.rotor_angle, 3);
cmd.readByte(); // reserved
cmd.readWordArr(p.balance_error, 3);
p.current = cmd.readWord();
cmd.readWordArr(p.magnetometer_data, 3);
p.imu_temp_celcius = cmd.readByte();
p.frame_imu_temp_celcius = cmd.readByte();
cmd.skipBytes(38);
}
if(cmd.checkLimit()) return 0;
else return PARSER_ERROR_WRONG_DATA_SIZE;
#endif
}
示例11: go
void CommandSet::go()
{
/* holonomics and shit */
float x_vel = atof(sCmd.next());
float y_vel = atof(sCmd.next());
float r_vel = atof(sCmd.next());
Serial.println(F("A"));
#ifdef FW_DEBUG
Serial.println(F("Going"));
#endif
_go(x_vel, y_vel, r_vel);
}
示例12: rotate
void CommandSet::rotate()
{
const int motor_power = atoi(sCmd.next());
const long delta = atoi(sCmd.next());
Serial.println(F("A"));
#ifdef FW_DEBUG
Serial.print(F("rotating at "));
Serial.print(motor_power);
Serial.print(F(" to "));
Serial.print(delta);
Serial.println(F(" stops"));
#endif
for (size_t i=0; i < motor_count; i++){
state.motors[i]->power = motor_power;
state.initial_displacement[i] = state.motors[i]->disp;
}
state.rotation_delta = delta;
processes.enable((state.rotation_process)->id);
write_powers();
}
示例13: grab
void CommandSet::grab()
{
const int direction = atoi(sCmd.next());
if (state.grabber_state != Open && state.grabber_state != Closed) {
Serial.println(F("N - grab"));
return;
}
Serial.println(F("A"));
#ifdef FW_DEBUG
Serial.print(F("grabbing "));
Serial.println(direction);
#endif
const pid_t pid = state.grab_handler->id;
const int motor_power = 200;
/* If we're open, doing that again will bugger the vision plate */
if (direction) {
state.grabber_state = Closing;
motorForward(grabber_port, motor_power);
processes.change(pid, 300L);
} else if (state.grabber_state != Open) {
state.grabber_state = Opening;
motorBackward(grabber_port, motor_power);
processes.change(pid, 280L);
} else {
return;
}
processes.enable(pid);
processes.forward(pid);
}
示例14: pixels
void CommandSet::pixels()
{
byte red = (byte) atoi(sCmd.next());
byte green = (byte) atoi(sCmd.next());
byte blue = (byte) atoi(sCmd.next());
Serial.println(F("A"));
#ifdef FW_DEBUG
Serial.print(F("Set pixel colour to "));
Serial.print(red,HEX);
Serial.print(green,HEX);
Serial.println(blue,HEX);
#endif
for (uint16_t i = 0; i < 10; i++) {
state.strip.setPixelColor(i, red, green, blue);
}
state.strip.show();
}
示例15: setup
void setup()
{
// initialize the serial communication:
serial.init(TTYACM0, 115200, openComport);
serial.setPacketHandler(handlePacket);
sCmd.addCommand(1, respondData);
gettimeofday(&start, NULL);
gettimeofday(&startLoop, NULL);
uiRxPacketCtr=0;
uiTxPacketCtr=0;
}