model_urdf.cpp
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     // robot state
00016     double tilt = 0, tinc = degree, swivel=0, angle=0, height=0, hinc=0.005;
00017 
00018     // message declarations
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         //update joint_state
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         // update transform
00038         // (moving in a circle with radius=2)
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         //send the joint state and transform
00046         joint_pub.publish(joint_state);
00047         broadcaster.sendTransform(odom_trans);
00048 
00049         // Create new robot state
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         // This will adjust as needed per iteration
00058         loop_rate.sleep();
00059     }
00060 
00061 
00062     return 0;
00063 }


diver_kinematics
Author(s):
autogenerated on Fri Feb 7 2014 11:36:53