Create a customer application
mc_client_interface
mc_client_interface is an interface header file provided by the Daystar Bot SDK. You can call a high-level interface to control the Daystar Bot to perform a specified action. The header file is located in the sdk download package rc_sdk/sdk/include/mc_client_interface.h
, see below
#ifndef MC_CLIENT_INTERFACE_H
#define MC_CLIENT_INTERFACE_H
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include "common.h"
using namespace robot_control;
// SDK初始化接口
bool rcClientInterfaceInit(std::string target_ip);
// 高层运动服务接口
bool rcClientInterfaceDriverEnable(robot_control::common::NAV_OR_JOY_MODE from, bool driver_enable);
bool rcClientInterfaceDirectionMovement(robot_control::common::NAV_OR_JOY_MODE from, common::ROBOT_TWIST rc_direct, int64_t time_millis);
bool rcClientInterfaceBodyHighAdjust(robot_control::common::NAV_OR_JOY_MODE from, int scale);
bool rcClientInterfaceSetScene(robot_control::common::NAV_OR_JOY_MODE from, common::SCENE_TYPE scene);
bool rcClientInterfaceDemoControl(common::NAV_OR_JOY_MODE from, int mode, bool enable);
bool rcClientInterfaceSpeedAdjust(robot_control::common::NAV_OR_JOY_MODE from, int scale);
bool rcClientInterfaceDriverSoftEstop(robot_control::common::NAV_OR_JOY_MODE from);
bool rcClientInterfacercResumeSoftEstop(robot_control::common::NAV_OR_JOY_MODE from);
bool rcClientInterfaceSetNavOrJoyControl(common::NAV_OR_JOY_MODE nav_joy);
// 底层运动服务接口
bool rcClientInterfaceClearDriverError(unsigned int mask);
bool rcClientInterfaceReCalibrateAllDriverAndSave(bool is_rough);
// 清除BISS错误接口缺失
bool rcClientInterfaceZeroTorqueSensor(robot_control::common::NAV_OR_JOY_MODE from);
// 设备状态服务接口
bool rcClientInterfaceGetCommonStatus(common::ROBOT_COMMON_STATUS *com_state);
bool rcClientInterfaceGetJointsStatus(common::ROBOT_JOINTS_STATUS *state);
// 底层服务接口
bool rcClientInterfaceGetChargeState(common::JETSON_CHARGE_STATE *charge_state);
bool rcClientInterfaceEnterOrExitCharge(robot_control::common::NAV_OR_JOY_MODE from, bool driver_enable);
bool rcClientInterfaceGetImuData(common::MC_MOTION_IMU_DATA *imu_data);
bool rcClientInterfaceGetImuStreamData(std::vector<common::MC_MOTION_IMU_DATA> *imu_data_list);
// 故障服务接口
bool rcClientInterfaceLogUpdate(std::vector<std::string> &log_list);
// 系统信息服务接口
std::string rcClientInterfaceGetMcVersion(const int& index);
std::string rcClientInterfaceGetRobotName(const int& index);
// 停障服务接口
bool rcClientInterfaceSetGuardian(common::NAV_OR_JOY_MODE from, float velocity_decay_ratio, std::string trigger_source);
bool rcClientInterfaceSetGuardianSwitch(robot_control::common::NAV_OR_JOY_MODE from, bool enable);
#endif // MC_CLIENT_INTERFACE_H
According to the application described above, the functions used are
bool rcClientInterfaceInit(std::string target_ip);
initialize the SDKbool rcClientInterfaceDriverEnable(robot_control::common::NAV_OR_JOY_MODE from, bool driver_enable);
enablebool rcClientInterfaceSetScene(robot_control::common::NAV_OR_JOY_MODE from, common::SCENE_TYPE scene);
set up robot scenebool rcClientInterfaceSpeedAdjust(robot_control::common::NAV_OR_JOY_MODE from, int scale);
set robot moving speed coefficientbool rcClientInterfaceGetCommonStatus(common::ROBOT_COMMON_STATUS *com_state);
read robot statusrcClientInterfaceDirectionMovement(robot_control::common::NAV_OR_JOY_MODE from, common::ROBOT_TWIST rc_direct, int64_t time_millis);
control robot movement
Create application files
Next, integrate the sdk to create your application project.
The following describes the hypothetical workpath is /home/daystar/sdk_test_project
enter the following commands in turn. Copy the sdk so library file and. h header file to the corresponding directory of the application project (select sdk arm or x86 so Library File according to the development platform used), create app_test.cpp file, write and call sdk interface and application logic.
cd /home/daystar/sdk_test_project
mkdir include src libs
cp /sdk/include/* include/
cp /sdk/lib/arm/* libs/
cd src
touch app_test.cpp
Next let's edit app_test.cpp
- include header file:
#include "include/mc_client_interface.h"
- call SDK functions to implement application logic
// 初始化
rcClientInterfaceInit("192.168.100.103");
common::NAV_OR_JOY_MODE mode = common::NAV_OR_JOY_MODE::joy_control;
// 上使能
rcClientInterfaceDriverEnable(mode, true);
// 设置行走步态
common::SCENE_TYPE scene = common::WALKING;
rcClientInterfaceSetScene(mode, scene);
// 设置行走最大速度系数(1-100)
float max_speed_factor = 1;
rcClientInterfaceSpeedAdjust(mode, max_speed_factor);
// 获取机器人状态
common::ROBOT_COMMON_STATUS status;
rcClientInterfaceGetCommonStatus(&status);
// 设置以0.5m/s的速度往前行走
common::ROBOT_TWIST direction = {{0.5, 0.0, 0.0}, {0.0, 0.0, 0.0}};
rcClientInterfaceDirectionMovement(mode, direction, status.heartbeat);
The full code is
#include "mc_client_interface.h"
#include <unistd.h>
int main(int argc, char **argv)
{
common::NAV_OR_JOY_MODE mode = common::NAV_OR_JOY_MODE::joy_control;
// 初始化
rcClientInterfaceInit("192.168.100.103");
// 上使能
rcClientInterfaceDriverEnable(mode, true);
// 设置行走场景
common::SCENE_TYPE scene = common::WALKING;
rcClientInterfaceSetScene(mode, scene);
usleep(5000000); // 等待5秒,趴下切换到行走
// 设置行走最大速度系数(1-100)
float max_speed_factor = 1;
rcClientInterfaceSpeedAdjust(mode, max_speed_factor);
// 控制机器人以0.5m/s的速度往前行走1秒,推荐频率100ms发送一次
common::ROBOT_COMMON_STATUS status;
common::ROBOT_TWIST direction = {{0.5, 0.0, 0.0}, {0.0, 0.0, 0.0}};
int32_t count = 10;
for (size_t i = 0; i < count; i++)
{
rcClientInterfaceGetCommonStatus(&status);
rcClientInterfaceDirectionMovement(mode, direction, status.heartbeat);
usleep(100000);
}
return 0;
}
Compile application files
when the application logic is written, the next step is to compile the application files.
In sdk_test_project/CMakeLists.txt file to add a compilation Command, will just write the routine to add to generate the corresponding executable file, and then save the file.
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
set(MC_CLIENT_LIB ${CMAKE_SOURCE_DIR}/libs/arm/libmc_client.so) # for rc_sdk
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
set(MC_CLIENT_LIB ${CMAKE_SOURCE_DIR}/libs/x86_64/libmc_client.so) # for rc_sdk
endif()
# Add executable
add_executable(app_test
src/app_test.cpp)
target_include_directories(app_test PRIVATE
include
)
target_link_libraries(app_test PRIVATE ${MC_CLIENT_LIB})
Finally compile the routine to run
cd /home/daystar/sdk_test_project
mkdir build
cd build
cmake ..
make
Run Application
connect to the robot network (for example, IS_Plus_001), ensure that the development device and the robot are in the same LAN, open a terminal, and run the following commands to run the application.
cd /home/daystar/sdk_test_project/build
sudo ./app_test
Attention
the application will forward the control command to the Daystar Bot robot through the operation control service, so please ensure that the robot is in a normal operation State before running the application, please refer to the "App binding" article for details.