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 }
ForwardCommandExecutionTester::output_pub_
ros::Publisher output_pub_
Definition: test_forward_command_sine_node.cpp:72
ForwardCommandExecutionTester::nh_
ros::NodeHandle nh_
Definition: test_forward_command_sine_node.cpp:71
ros::Publisher
ForwardCommandExecutionTester
Definition: test_forward_command_sine_node.cpp:24
ForwardCommandExecutionTester::idx_
unsigned int idx_
Definition: test_forward_command_sine_node.cpp:74
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
ForwardCommandExecutionTester::~ForwardCommandExecutionTester
~ForwardCommandExecutionTester()
Definition: test_forward_command_sine_node.cpp:38
r
r
ros::spinOnce
ROSCPP_DECL void spinOnce()
ForwardCommandExecutionTester::run
void run()
Definition: test_forward_command_sine_node.cpp:41
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
ros::ok
ROSCPP_DECL bool ok()
ForwardCommandExecutionTester::dof_
unsigned int dof_
Definition: test_forward_command_sine_node.cpp:73
setup.d
d
Definition: setup.py:6
ros::Time
main
int main(int argc, char **argv)
Definition: test_forward_command_sine_node.cpp:79
ForwardCommandExecutionTester::ForwardCommandExecutionTester
ForwardCommandExecutionTester()
Definition: test_forward_command_sine_node.cpp:27
ros::Rate
ros::spin
ROSCPP_DECL void spin()
ros::Duration::sleep
bool sleep() const
ros::Duration
ros::NodeHandle
ros::Time::now
static Time now()


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Mon May 1 2023 02:44:43