dds机器人数据收发接口
创建DDS发布服务
create_participant_pub(int domain_id)
/**
* @param domain_id id号
* @return 程序执行成功与否
* @retval int 0:成功; other:失败
*/
void robot_DDS_pub()
{
printf("robot_DDS_pub start!\n");
int err=HYYRobotBase::create_participant_pub(0);
if (1!=err)
{
printf("create_participant_pub failure!\n");
return;
}
HYYRobotBase::RotationAngle RotAngle;
const char* robot_name=HYYRobotBase::get_name_robot_device(HYYRobotBase::get_deviceName(0,NULL), 0);
double angle[10];
HYYRobotBase::RTimer timer;
HYYRobotBase::initUserTimer(&timer, 0, 1);
while (1)
{
HYYRobotBase::userTimer(&timer);
HYYRobotBase::GetGroupTargetPosition(robot_name, angle);
RotAngle.angle1 = angle[0];
RotAngle.angle2 = angle[1];
RotAngle.angle3 = angle[2];
RotAngle.angle4 = angle[3];
RotAngle.angle5 = angle[4];
RotAngle.angle6 = angle[5];
HYYRobotBase::start_publisher(RotAngle);
}
HYYRobotBase::participant_shutdown_pub();
}
DDS发布机器人关节状态
start_publisher(RotationAngle RotAngle)
/**
* @brief DDS发布机器人关节状态
*
* @param RotAngle 机器人关节数据
* @return 发布是否成功
* @retval 0:成功;
* @retval other:失败
*/
关闭DDS发布服务
participant_shutdown_pub()
/**
* @brief 关闭DDS发布服务
*
* @return int 0:成功; other:失败
*/
创建DDS订阅服务
create_participant_sub(int domain_id)
/**
* @param domain_id id号
* @return int 0:成功; other:失败
*/
void robot_DDS_sub()
{
printf("robot_DDS_sub start\n");
int err=HYYRobotBase::create_participant_sub(0);
if (1!=err)
{
printf("create_participant_pub failure!\n");
return;
}
HYYRobotBase::RotationAngle RotAngle;
const char* robot_name=HYYRobotBase::get_name_robot_device(HYYRobotBase::get_deviceName(0,NULL), 0);
double angle[10];
HYYRobotBase::RTimer timer;
HYYRobotBase::initUserTimer(&timer, 0, 1);
while (1)
{
HYYRobotBase::userTimer(&timer);
RotAngle=HYYRobotBase::start_subscriber();
angle[0]=RotAngle.angle1;
angle[1]=RotAngle.angle2;
angle[2]=RotAngle.angle3;
angle[3]=RotAngle.angle4;
angle[4]=RotAngle.angle5;
angle[5]=RotAngle.angle6;
printf("%f,%f,%f,%f,%f,%f\n",angle[0],angle[1],angle[2],angle[3],angle[4],angle[5]);
HYYRobotBase::SetGroupPosition(robot_name, angle);
}
}
DDS订阅机器人关节状态
start_subscriber
/**
* @return RotationAngle 机器人关节数据
*/
关闭DDS订阅服务
participant_shutdown_sub
/**
* @return int 0:成功; other:失败
*/