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 
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 };
88  std::mutex next_msg_mutex_;
89 };
90 
91 } // namespace pilz_testutils
92 
93 #endif
pilz_testutils::JointStatePublisherMock::~JointStatePublisherMock
~JointStatePublisherMock()
Definition: joint_state_publisher_mock.cpp:45
pilz_testutils::JointStatePublisherMock::operator=
JointStatePublisherMock & operator=(const JointStatePublisherMock &other)=delete
pilz_testutils::JointStatePublisherMock::run
void run()
Definition: joint_state_publisher_mock.cpp:84
ros::Publisher
pilz_testutils::JointStatePublisherMock::createNextMessage
void createNextMessage()
Definition: joint_state_publisher_mock.cpp:104
pilz_testutils::JointStatePublisherMock::next_time_stamp_
ros::Time next_time_stamp_
Definition: joint_state_publisher_mock.h:86
pilz_testutils::JointStatePublisherMock::pub_
ros::Publisher pub_
Definition: joint_state_publisher_mock.h:79
ros.h
pilz_testutils::JointStatePublisherMock::JointStateConstPtr
sensor_msgs::JointStateConstPtr JointStateConstPtr
Definition: joint_state_publisher_mock.h:41
pilz_testutils::JointStatePublisherMock::stop_flag_
std::atomic_bool stop_flag_
Definition: joint_state_publisher_mock.h:81
pilz_testutils::JointStatePublisherMock::go_home_flag_
std::atomic_bool go_home_flag_
Definition: joint_state_publisher_mock.h:82
pilz_testutils::JointStatePublisherMock::updateNextMessage
void updateNextMessage()
Definition: joint_state_publisher_mock.cpp:120
pilz_testutils::JointStatePublisherMock
Mocks the joint_states interface. Can simulate robot movement by changing the position of the first j...
Definition: joint_state_publisher_mock.h:38
pilz_testutils::JointStatePublisherMock::joint1_position_
double joint1_position_
Definition: joint_state_publisher_mock.h:84
pilz_testutils::JointStatePublisherMock::joint1_velocity_
double joint1_velocity_
Definition: joint_state_publisher_mock.h:85
pilz_testutils::JointStatePublisherMock::updateJoint1Position
void updateJoint1Position()
Definition: joint_state_publisher_mock.cpp:126
pilz_testutils::JointStatePublisherMock::getNextMessage
JointStateConstPtr getNextMessage()
Return the message which will be published next.
Definition: joint_state_publisher_mock.cpp:78
pilz_testutils::JointStatePublisherMock::stopPublishing
void stopPublishing()
Definition: joint_state_publisher_mock.cpp:69
pilz_testutils::JointStatePublisherMock::JointState
sensor_msgs::JointState JointState
Definition: joint_state_publisher_mock.h:40
pilz_testutils
Definition: joint_state_publisher_mock.h:31
pilz_testutils::JointStatePublisherMock::publish
void publish()
Definition: joint_state_publisher_mock.cpp:115
ros::Time
pilz_testutils::JointStatePublisherMock::joint_names_
std::vector< std::string > joint_names_
Definition: joint_state_publisher_mock.h:80
pilz_testutils::JointStatePublisherMock::next_msg_mutex_
std::mutex next_msg_mutex_
Definition: joint_state_publisher_mock.h:88
pilz_testutils::JointStatePublisherMock::nh_
ros::NodeHandle nh_
Definition: joint_state_publisher_mock.h:78
pilz_testutils::JointStatePublisherMock::next_msg_
JointState next_msg_
Definition: joint_state_publisher_mock.h:87
pilz_testutils::JointStatePublisherMock::JointStatePublisherMock
JointStatePublisherMock()
Definition: joint_state_publisher_mock.cpp:37
pilz_testutils::JointStatePublisherMock::setJoint1Velocity
void setJoint1Velocity(const double &vel)
Definition: joint_state_publisher_mock.cpp:57
pilz_testutils::JointStatePublisherMock::publisher_thread_
std::thread publisher_thread_
Definition: joint_state_publisher_mock.h:83
pilz_testutils::JointStatePublisherMock::goHome
void goHome()
Go back to home position (position=velocity=0.0).
Definition: joint_state_publisher_mock.cpp:64
ros::NodeHandle
pilz_testutils::JointStatePublisherMock::startPublishingAsync
void startPublishingAsync(const double &joint1_start_position=0.0)
Definition: joint_state_publisher_mock.cpp:50


pilz_testutils
Author(s):
autogenerated on Sat Nov 25 2023 03:16:57