基于 ros_control 驱动机械臂

gazebo_ros_control 可以模拟机械臂的真实控制过程,关于如何用话题 “/joint_group_pos_controller/command” 在gazebo控制机械臂,代码如下:

#include "ros/ros.h"
#include "std_msgs/Float64MultiArray.h"
#include "std_msgs/MultiArrayLayout.h"
#include "std_msgs/MultiArrayDimension.h"

int main(int argc, char **argv)
{
    ros::init(argc, argv, "Pose_publish");
    ros::NodeHandle nh;
 
    ros::Publisher chatter_pub = nh.advertise<std_msgs::Float64MultiArray>("/joint_group_pos_controller/command", 1000);
 
    ros::Rate loop_rate(10);
    while (ros::ok())
    {
        std_msgs::Float64MultiArray msg;
        std_msgs::MultiArrayDimension dim;
        dim.label="";
        dim.size=6;
        dim.stride=1;
        msg.layout.dim.push_back(dim);
        msg.data.push_back(1.57);//自己写的,可行
        msg.data.push_back(-1.57);
        msg.data.push_back(1.57);
        msg.data.push_back(0.0);
        msg.data.push_back(0.0);
        msg.data.push_back(0.0);
 
        chatter_pub.publish(msg);
        ros::spinOnce();
        loop_rate.sleep();
    }
    return 0;
}
 

你可能感兴趣的:(机器人)