test_forward_command_sine_node.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <vector>
19 #include <string>
20 
21 #include <ros/ros.h>
22 #include <std_msgs/Float64MultiArray.h>
23 
25 {
26 public:
28  {
29  dof_ = 2;
30  idx_ = 1;
31 
32  output_pub_ = nh_.advertise<std_msgs::Float64MultiArray>("/torso/joint_group_position_controller/command", 1);
33 
34  ros::Duration(1.0).sleep();
35  }
36 
37 
39  {}
40 
41  void run()
42  {
43  ros::Rate r(100.0);
44 
45  ros::Time time = ros::Time::now();
46  ros::Time start_time = time;
47  double x = 0.0;
48 
49  double a = 0.6, b = 0.4, c = 0, d = 0; // torso_2dof
50 
51  std_msgs::Float64MultiArray command_msg;
52  command_msg.data.assign(dof_, 0.0);
53 
54  while (ros::ok())
55  {
56  time = ros::Time::now();
57  x = (time - start_time).toSec();
58 
59  double vel = a*sin(b*x+c) + d;
60 
61  command_msg.data[idx_] = vel;
62 
63  output_pub_.publish(command_msg);
64 
65  ros::spinOnce();
66  r.sleep();
67  }
68  }
69 
70 
73  unsigned int dof_;
74  unsigned int idx_;
75 };
76 
77 
78 
79 int main(int argc, char **argv)
80 {
81  ros::init(argc, argv, "test_forward_command_execution_node");
82 
84  fcet.run();
85  ros::spin();
86  return 0;
87 }
d
int main(int argc, char **argv)
void publish(const boost::shared_ptr< M > &message) const
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
ROSCPP_DECL bool ok()
TFSIMD_FORCE_INLINE const tfScalar & x() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
r
bool sleep()
static Time now()
ROSCPP_DECL void spinOnce()
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Thu Apr 8 2021 02:40:01