add ChangeID example.

This commit is contained in:
Yichao Zhang 2024-01-03 15:59:27 +08:00
parent faa3349525
commit 39175a791e
2 changed files with 55 additions and 0 deletions

View File

@ -23,6 +23,9 @@ target_link_libraries(example_b1_motor ${EXTRA_LIBS})
add_executable(example_goM8010_6_motor example/example_goM8010_6_motor.cpp)
target_link_libraries(example_goM8010_6_motor ${EXTRA_LIBS})
add_executable(changeID example/changeID.cpp)
target_link_libraries(changeID ${EXTRA_LIBS})
set(LIBRARY_OUTPUT_PATH "../lib")
add_subdirectory(thirdparty/pybind11)
pybind11_add_module(unitree_actuator_sdk thirdparty/python_wrapper/wrapper.cpp)

52
example/changeID.cpp Executable file
View File

@ -0,0 +1,52 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include "serialPort/SerialPort.h"
#include "unitreeMotor/unitreeMotor.h"
#define BroadAllMotorID 0xBB
#define MotorPulsator 11
int main(){
char serial_name[100];
MotorCmd motor_s;
MotorData motor_r;
motor_s.motorType = MotorType::B1; // set the motor type, A1 or B1
motor_r.motorType = motor_s.motorType;
printf("Please input the name of serial port.(e.g. Linux:/dev/ttyUSB0, Windows:\\\\.\\COM3)\n");
scanf("%s",serial_name);
printf("The serial port is %s\n", serial_name);
SerialPort serial(serial_name); // set the serial port name
motor_s.id = BroadAllMotorID;
motor_s.mode = 10;
serial.sendRecv(&motor_s, &motor_r);
usleep(100000); //sleep 0.1s
//进入拨轮模式修改ID
motor_s.mode = MotorPulsator;
motor_s.modify_data(&motor_s);
serial.send(motor_s.get_motor_send_data(), motor_s.hex_len);
printf("Please turn the motor.\n");
printf("One time: id=0; Two times: id=1, Three times: id=2\n");
printf("ID can only be 0, 1, 2\n");
printf("Once finished, press 'a'\n");
// int c;
while(getchar() != (int)'a');
printf("Turn finished\n");
//保存ID
motor_s.mode = 0;
motor_s.modify_data(&motor_s);
serial.send(motor_s.get_motor_send_data(), motor_s.hex_len);
return 0;
}