Tetrapod Project
contact_sensor.h
Go to the documentation of this file.
1 /*******************************************************************/
2 /* AUTHOR: Paal Arthur S. Thorseth */
3 /* ORGN: Dept of Eng Cybernetics, NTNU Trondheim */
4 /* FILE: contact_sensor.h */
5 /* DATE: May 19, 2021 */
6 /* */
7 /* Copyright (C) 2021 Paal Arthur S. Thorseth, */
8 /* Adrian B. Ghansah */
9 /* */
10 /* This program is free software: you can redistribute it */
11 /* and/or modify it under the terms of the GNU General */
12 /* Public License as published by the Free Software Foundation, */
13 /* either version 3 of the License, or (at your option) any */
14 /* later version. */
15 /* */
16 /* This program is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty */
18 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */
19 /* See the GNU General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU General Public */
22 /* License along with this program. If not, see */
23 /* <https://www.gnu.org/licenses/>. */
24 /* */
25 /*******************************************************************/
26 
27 #pragma once
28 
29 // Gazebo
30 #include <gazebo/gazebo.hh>
31 #include <gazebo/gazebo_client.hh>
32 #include <gazebo/physics/physics.hh>
33 #include <gazebo/transport/transport.hh>
34 #include <gazebo/msgs/msgs.hh>
35 
36 // ROS
37 #include "ros/ros.h"
38 #include "ros/callback_queue.h"
39 #include "std_msgs/Int8MultiArray.h"
40 
41 // Boost
42 #include <boost/algorithm/string.hpp>
43 
46 {
48  public: ContactSensor();
49 
51  public: virtual ~ContactSensor();
52 
56  public: void OnFlContactCallback(const ConstContactsPtr &_msg);
57 
61  public: void OnFrContactCallback(const ConstContactsPtr &_msg);
62 
66  public: void OnRlContactCallback(const ConstContactsPtr &_msg);
67 
71  public: void OnRrContactCallback(const ConstContactsPtr &_msg);
72 
75  public: void PublishQueueThread();
76 
78  protected: void InitGazebo();
79 
81  protected: void InitRos();
82 
85  protected: void InitRosQueueThreads();
86 
89  private: int footContacts[4];
90 
92  private: gazebo::transport::NodePtr gazeboNode;
93 
95  private: gazebo::transport::SubscriberPtr flContactSensorSub;
96 
98  private: gazebo::transport::SubscriberPtr frContactSensorSub;
99 
101  private: gazebo::transport::SubscriberPtr rlContactSensorSub;
102 
104  private: gazebo::transport::SubscriberPtr rrContactSensorSub;
105 
107  private: std::unique_ptr<ros::NodeHandle> rosNode;
108 
110  private: ros::Publisher contactStatePub;
111 
113  private: ros::CallbackQueue rosPublishQueue;
114 
116  private: std::thread rosPublishQueueThread;
117 };
A plugin for the contact sensors.
virtual ~ContactSensor()
Destructor.
std::unique_ptr< ros::NodeHandle > rosNode
Node used for ROS transport.
void OnRlContactCallback(const ConstContactsPtr &_msg)
The OnRlContactCallback function handles an incoming contact message from the rear left contact senso...
void InitRos()
The InitRos function is called to initialize ROS.
void InitRosQueueThreads()
The InitRosQueueThreads function is called to initialize the ROS Publish and Process Queue Threads.
void OnFrContactCallback(const ConstContactsPtr &_msg)
The OnFrContactCallback function handles an incoming contact message from the front right contact sen...
int footContacts[4]
Vector of foot contacts, zero indicates no contact and one indicates contact.
gazebo::transport::SubscriberPtr rrContactSensorSub
Gazebo rear right contact sensor Subscriber.
gazebo::transport::NodePtr gazeboNode
Node used for Gazebo transport.
void PublishQueueThread()
The PublishQueueThread function is a ROS helper function that publish state messages.
void OnRrContactCallback(const ConstContactsPtr &_msg)
The OnRrContactCallback function handles an incoming contact message from the rear rear contact senso...
std::thread rosPublishQueueThread
Thread running the rosPublishQueue.
void OnFlContactCallback(const ConstContactsPtr &_msg)
The OnFlContactCallback function handles an incoming contact message from the front left contact sens...
gazebo::transport::SubscriberPtr rlContactSensorSub
Gazebo rear left contact sensor Subscriber.
ros::Publisher contactStatePub
ROS Contact State Publisher.
ros::CallbackQueue rosPublishQueue
ROS callbackque that helps publish messages.
gazebo::transport::SubscriberPtr frContactSensorSub
Gazebo front right contact sensor Subscriber.
ContactSensor()
Constructor.
gazebo::transport::SubscriberPtr flContactSensorSub
Gazebo front left contact sensor Subscriber.
void InitGazebo()
The InitRos function is called to initialize Gazebo.