移动小车,包括四个轮子+一个手臂+一个夹具
描述机器人几何关系的两个主要方面:links and joints。
<robot name="origins">
<link name="base_link">
<visual>
<geometry>
<box size="0.2 .3 .1"/>
</geometry>
<origin rpy="0 0 0" xyz="0 0 0.05"/>
<material name="white">
<color rgba="1 1 1 1"/>
</material>
</visual>
</link>
link:几何定义,材料定义,原点定义
link定义完成后需要定义joint
<joint name="base_to_wheel1" type="fixed">
<parent link="base_link"/>
<child link="wheel_1"/>
<origin xyz="0 0 0"/>
</joint>
joint:关节连接类型(fixed , revolute , continuous , floating , or planar)、父、子关系、
当关节类型选为revolute:需要添加limit:
例如:
<joint name="arm_1_to_arm_base" type="revolute">
<parent link="arm_base"/>
<child link="arm_1"/>
<axis xyz="1 0 0"/>
<origin xyz="0 0 0.15"/>
<limit effort ="1000.0" lower="-1.0" upper="1.0" velocity="0.5"/>
</joint>
effort (maximum force supported by the joint);
lower to assign the lower limit of a joint (radian per revolute joints, meters for prismatic joints);
upper for the upper limit;
velocity for enforcing the maximum joint velocity;
<launch>
<arg name="model" />
<arg name="gui" default="true" />
<param name="robot_description" textfile="$(arg model)" />
<param name="use_gui" value="$(arg gui)" />
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
</launch>
运行命令
roslaunch robot_learning_test robot1.launch model:="`rospack find robot_learning_test`/robot_description/urdf/robot1.urdf"
也可以将urdf文件路径写到launch文件里:
<arg name="model" default="/home/ma/catkin_ws1/src/robot_learning_test/robot_description/urdf/robot1.urdf" />
修改完的运行命令为:
roslaunch robot_learning_test robot1.launch
比URDF的机器人描述文件更好
在/home/ma/catkin_ws1/src/robot_learning_test/src下
新建state_publisher.cpp
#include
#include
#include
#include
int main(int argc, char** argv) {
ros::init(argc, argv, "state_publisher");
ros::NodeHandle n;
ros::Publisher joint_pub = n.advertise<sensor_msgs::JointState>("joint_states", 1);
tf::TransformBroadcaster broadcaster;
ros::Rate loop_rate(30);
const double degree = M_PI/180;
// robot state
double inc= 0.005, base_arm_inc= 0.005, arm1_armbase_inc= 0.005, arm2_arm1_inc= 0.005;
double angle= 0 ,base_arm = 0, arm1_armbase = 0, arm2_arm1 = 0;
// message declarations
geometry_msgs::TransformStamped odom_trans;
sensor_msgs::JointState joint_state;
odom_trans.header.frame_id = "odom";
odom_trans.child_frame_id = "base_link";
while (ros::ok()) {
//update joint_state
joint_state.header.stamp = ros::Time::now();
joint_state.name.resize(3);
joint_state.position.resize(3);
joint_state.name[0] ="base_to_arm_base";
joint_state.position[0] = base_arm;
joint_state.name[1] ="arm_1_to_arm_base";
joint_state.position[1] = arm1_armbase;
joint_state.name[2] ="arm_2_to_arm_1";
joint_state.position[2] = arm2_arm1;
// update transform
// (moving in a circle with radius)
odom_trans.header.stamp = ros::Time::now();
//odom_trans.transform.translation.x = cos(angle);
// odom_trans.transform.translation.y = sin(angle);
// odom_trans.transform.translation.z = 0.0;
odom_trans.transform.rotation = tf::createQuaternionMsgFromYaw(angle);
//send the joint state and transform
joint_pub.publish(joint_state);
broadcaster.sendTransform(odom_trans);
// Create new robot state
arm2_arm1 += arm2_arm1_inc;
if (arm2_arm1<-1.5 || arm2_arm1>1.5) arm2_arm1_inc *= -1;
arm1_armbase += arm1_armbase_inc;
if (arm1_armbase>1.2 || arm1_armbase<-1.0) arm1_armbase_inc *= -1;
base_arm += base_arm_inc;
if (base_arm>1. || base_arm<-1.0) base_arm_inc *= -1;
angle += degree/8;
// This will adjust as needed per iteration
loop_rate.sleep();
}
return 0;
}
add_executable(state_publisher src/state_publisher.cpp)
target_link_libraries(state_publisher
${catkin_LIBRARIES}
)
catkin_make
roslaunch robot_learning_test robot1.launch
rviz
rosrun robot_learning_test state_publisher
rostopic list
rostopic echo /joint_states
待添加
20190425
20190426
20190503
教程:
https://blog.csdn.net/answerMack/article/details/89791263