test_forward_command_sine_node.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #include <vector>
00019 #include <string>
00020 
00021 #include <ros/ros.h>
00022 #include <std_msgs/Float64MultiArray.h>
00023 
00024 class ForwardCommandExecutionTester
00025 {
00026 public:
00027     ForwardCommandExecutionTester()
00028     {
00029         dof_ = 2;
00030         idx_ = 1;
00031 
00032         output_pub_ = nh_.advertise<std_msgs::Float64MultiArray>("/torso/joint_group_position_controller/command", 1);
00033 
00034         ros::Duration(1.0).sleep();
00035     }
00036 
00037 
00038     ~ForwardCommandExecutionTester()
00039     {}
00040 
00041     void run()
00042     {
00043         ros::Rate r(100.0);
00044 
00045         ros::Time time = ros::Time::now();
00046         ros::Time start_time = time;
00047         double x = 0.0;
00048 
00049         double a = 0.6, b = 0.4, c = 0, d = 0;      // torso_2dof
00050 
00051         std_msgs::Float64MultiArray command_msg;
00052         command_msg.data.assign(dof_, 0.0);
00053 
00054         while (ros::ok())
00055         {
00056             time = ros::Time::now();
00057             x = (time - start_time).toSec();
00058 
00059             double vel = a*sin(b*x+c) + d;
00060 
00061             command_msg.data[idx_] = vel;
00062 
00063             output_pub_.publish(command_msg);
00064 
00065             ros::spinOnce();
00066             r.sleep();
00067         }
00068     }
00069 
00070 
00071     ros::NodeHandle nh_;
00072     ros::Publisher output_pub_;
00073     unsigned int dof_;
00074     unsigned int idx_;
00075 };
00076 
00077 
00078 
00079 int main(int argc, char **argv)
00080 {
00081     ros::init(argc, argv, "test_forward_command_execution_node");
00082 
00083     ForwardCommandExecutionTester fcet;
00084     fcet.run();
00085     ros::spin();
00086     return 0;
00087 }


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Thu Jun 6 2019 21:19:26