joint_state_publisher_mock.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Pilz GmbH & Co. KG
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef PILZ_TESTUTILS_JOINT_STATE_PUBLISHER_MOCK_H
19 #define PILZ_TESTUTILS_JOINT_STATE_PUBLISHER_MOCK_H
20 
21 #include <atomic>
22 #include <mutex>
23 #include <string>
24 #include <thread>
25 #include <vector>
26 
27 #include <ros/ros.h>
28 
29 #include <sensor_msgs/JointState.h>
30 
31 namespace pilz_testutils
32 {
39 {
40  typedef sensor_msgs::JointState JointState;
41  typedef sensor_msgs::JointStateConstPtr JointStateConstPtr;
42 
43 public:
45 
47 
48  JointStatePublisherMock(const JointStatePublisherMock& other) = delete;
50 
51  void startPublishingAsync(const double& joint1_start_position = 0.0);
52 
53  void setJoint1Velocity(const double& vel);
54 
61  void goHome();
62 
63  void stopPublishing();
64 
68  JointStateConstPtr getNextMessage();
69 
70 private:
71  void run();
72  void createNextMessage();
73  void publish();
74  void updateNextMessage();
75  void updateJoint1Position();
76 
77 private:
80  std::vector<std::string> joint_names_;
81  std::atomic_bool stop_flag_;
82  std::atomic_bool go_home_flag_;
83  std::thread publisher_thread_;
84  double joint1_position_{ 0.0 };
85  double joint1_velocity_{ 0.0 };
87  JointState next_msg_;
88  std::mutex next_msg_mutex_;
89 };
90 
91 } // namespace pilz_testutils
92 
93 #endif
void startPublishingAsync(const double &joint1_start_position=0.0)
JointStateConstPtr getNextMessage()
Return the message which will be published next.
void goHome()
Go back to home position (position=velocity=0.0).
sensor_msgs::JointStateConstPtr JointStateConstPtr
JointStatePublisherMock & operator=(const JointStatePublisherMock &other)=delete
Mocks the joint_states interface. Can simulate robot movement by changing the position of the first j...


pilz_testutils
Author(s):
autogenerated on Mon Feb 28 2022 23:13:41