pan_tilt_api.cpp
Go to the documentation of this file.
00001 
00002 #include <ros/ros.h>
00003 #include <trajectory_msgs/JointTrajectory.h>
00004 #include <stdlib.h>     /* srand, rand */
00005 #include <time.h>       /* time */
00006 #include <cstdio>
00007 
00008 int main(int argc, char **argv) {
00009     ros::init(argc, argv, "pan_tilt_api");
00010     std::vector<double> q_goal(2);
00011 
00012     if (argc==3) {
00013         q_goal[0]=atof(argv[1]);
00014         q_goal[1]=atof(argv[2]);
00015     }
00016     else {
00017         srand (time(NULL));
00018         q_goal[0]=(double)((rand()%121)-60)*M_PI/180.0;
00019         q_goal[1]=(double)((rand()%61)-30)*M_PI/180.0;
00020     }
00021       ROS_INFO("Pan-Tilt Goal: [%f,%f]",q_goal[0],q_goal[1]);
00022     ros::NodeHandle nh;
00023     ros::Publisher pub_controller_command = nh.advertise<trajectory_msgs::JointTrajectory>("pan_tilt_trajectory_controller/command", 2);
00024     ros::Rate r(1); // 50 hz
00025     while (ros::ok())
00026     {
00027         trajectory_msgs::JointTrajectory traj;
00028         traj.header.stamp = ros::Time::now();
00029         traj.joint_names.push_back("head_pan_joint");
00030         traj.joint_names.push_back("head_tilt_joint");
00031         traj.points.resize(1);
00032         traj.points[0].time_from_start = ros::Duration(1.0);
00033         traj.points[0].positions = q_goal;
00034         traj.points[0].velocities.push_back(0);
00035         traj.points[0].velocities.push_back(0);
00036         pub_controller_command.publish(traj);
00037 
00038         r.sleep();
00039 
00040     }
00041 
00042 
00043 
00044 
00045 }


robotican_demos
Author(s):
autogenerated on Fri Oct 27 2017 03:02:45