gearbox.h
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
27 #ifndef _GEARBOX_H_
28 #define _GEARBOX_H_
29 
35 #include <ros/ros.h>
36 #include <iostream>
37 #include <boost/lexical_cast.hpp>
38 #include <tcp_client/class_tcp.h>
39 
40 #include <atlascar_base/GearboxStatus.h>
41 #include <atlascar_base/GearboxCommand.h>
42 
43 #include <topic_priority/topic_priority.h>
44 
45 #include <diagnostic_updater/diagnostic_updater.h>
46 #include <diagnostic_updater/publisher.h>
47 
48 namespace atlascar_base
49 {
50 
59 class Gearbox
60 {
61  public:
81  Gearbox(const ros::NodeHandle& nh);
82 
86  ~Gearbox();
87 
94  void init();
95 
101  void setupMessaging();
102 
108  void loop();
112  private:
113 
114  void diagnostics(diagnostic_updater::DiagnosticStatusWrapper& stat)
115  {
117  {
118  stat.summary(diagnostic_msgs::DiagnosticStatus::ERROR, "No connection to hardware.");
119  stat.add("Status","Check ethernet connection!");
120  stat.add("Trying to connect to",ip_);
121  }else
122  stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "No problems.");
123  }
124 
131  int maintainConnection();
132 
139  void commandCallback(const atlascar_base::GearboxCommandPtr& command);
140 
141  int receiveMessage(string& message);
142 
143  int interpreterMessage(string& message);
144 
146  enum {OFFLINE=0, ONLINE};
147 
149  ros::NodeHandle nh_;
151  ros::Subscriber command_sub_;
153  ros::Publisher status_pub_;
155  tcp_client* comm_;
157  TopicQueuePriority<atlascar_base::GearboxCommandPtr> command_queue_;
161  bool verbose_;
163  atlascar_base::GearboxCommandPtr command_;
165  atlascar_base::GearboxCommandPtr safety_command_;
167  atlascar_base::GearboxStatus status_;
169  std::string ip_;
171  int port_;
172 
173  //Create the diagnostics class
174  diagnostic_updater::Updater updater_;
175  diagnostic_updater::HeaderlessTopicDiagnostic status_freq_;
178 };
179 
180 }
181 
182 #endif
ros::Subscriber command_sub_
Ros command subscriber.
Definition: gearbox.h:151
atlascar_base::GearboxStatus status_
Status message.
Definition: gearbox.h:167
~Gearbox()
Class destructor.
Definition: gearbox.cpp:52
Gearbox(const ros::NodeHandle &nh)
Class constructor.
Definition: gearbox.cpp:38
diagnostic_updater::HeaderlessTopicDiagnostic status_freq_
Definition: gearbox.h:175
bool verbose_
Verbose mode.
Definition: gearbox.h:161
int maintainConnection()
Keep connection alive.
Definition: gearbox.cpp:140
tcp_client * comm_
TCP client communication class pointer.
Definition: gearbox.h:155
int interpreterMessage(string &message)
Definition: gearbox.cpp:177
TopicQueuePriority< atlascar_base::GearboxCommandPtr > command_queue_
Command queue holding class.
Definition: gearbox.h:157
atlascar_base::GearboxCommandPtr safety_command_
Safety command message pointer.
Definition: gearbox.h:165
void loop()
Start main control loop.
Definition: gearbox.cpp:79
ros::Publisher status_pub_
Ros status publisher.
Definition: gearbox.h:153
diagnostic_updater::Updater updater_
Definition: gearbox.h:174
ros::NodeHandle nh_
Ros node handler.
Definition: gearbox.h:149
double status_min_frequency_
Definition: gearbox.h:177
atlascar_base::GearboxCommandPtr command_
Command message pointer.
Definition: gearbox.h:163
void commandCallback(const atlascar_base::GearboxCommandPtr &command)
Command message handler.
Definition: gearbox.cpp:135
double status_max_frequency_
Definition: gearbox.h:176
This class is not fully documented!
Definition: gearbox.h:59
int receiveMessage(string &message)
Definition: gearbox.cpp:231
std::string ip_
Definition: gearbox.h:169
void setupMessaging()
Start ros message subscribing and advertising.
Definition: gearbox.cpp:73
void diagnostics(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: gearbox.h:114
int connection_status_
Current connection status.
Definition: gearbox.h:159
void init()
Initialize the class.
Definition: gearbox.cpp:56


atlascar_base
Author(s): Jorge Almeida, Sérgio Pinho, Miguel Oliveira, Pedro Salvado, Andre Oliveira and Pedro Pinheiro
autogenerated on Mon Mar 2 2015 01:31:23