Go to the documentation of this file.00001 #include <string>
00002 #include <ros/ros.h>
00003 #include <sensor_msgs/JointState.h>
00004 #include <tf/transform_broadcaster.h>
00005
00006 int main(int argc, char** argv) {
00007 ros::init(argc, argv, "state_publisher");
00008 ros::NodeHandle n;
00009 ros::Publisher joint_pub = n.advertise<sensor_msgs::JointState>("joint_states", 1);
00010 tf::TransformBroadcaster broadcaster;
00011 ros::Rate loop_rate(30);
00012
00013 const double degree = M_PI/180;
00014
00015
00016 double tilt = 0, tinc = degree, swivel=0, angle=0, height=0, hinc=0.005;
00017
00018
00019 geometry_msgs::TransformStamped odom_trans;
00020 sensor_msgs::JointState joint_state;
00021 odom_trans.header.frame_id = "odom";
00022 odom_trans.child_frame_id = "body";
00023
00024 while (ros::ok()) {
00025
00026 joint_state.header.stamp = ros::Time::now();
00027 joint_state.name.resize(3);
00028 joint_state.position.resize(3);
00029 joint_state.name[0] ="shoulder_joint_x";
00030 joint_state.position[0] = height;
00031 joint_state.name[1] ="shoulder_joint_y";
00032 joint_state.position[1] = swivel;
00033 joint_state.name[2] ="shoulder_joint_z";
00034 joint_state.position[2] = tilt;
00035
00036
00037
00038
00039 odom_trans.header.stamp = ros::Time::now();
00040 odom_trans.transform.translation.x = 0;cos(angle)*2;
00041 odom_trans.transform.translation.y = 0;sin(angle)*2;
00042 odom_trans.transform.translation.z = 0;
00043 odom_trans.transform.rotation = tf::createQuaternionMsgFromYaw(0);
00044
00045
00046 joint_pub.publish(joint_state);
00047 broadcaster.sendTransform(odom_trans);
00048
00049
00050 tilt += tinc;
00051 if (tilt<-.5 || tilt>0) tinc *= -1;
00052 height += hinc;
00053 if (height>.2 || height<0) hinc *= -1;
00054 swivel += degree;
00055 angle += degree/4;
00056
00057
00058 loop_rate.sleep();
00059 }
00060
00061
00062 return 0;
00063 }