motor_data_checker.hpp
Go to the documentation of this file.
1 /*
2 * @file motor_data_checker.hpp
3 * @author toni <toni@shadowrobot.com>
4 * @date 25 Oct 2011
5 *
6 /* Copyright 2011 Shadow Robot Company Ltd.
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 *
21 * @brief This is a class to check that all expected initialization data have been received from each motor.
22 *
23 *
24 */
25 
26 #ifndef MOTOR_DATA_CHECKER_HPP_
27 #define MOTOR_DATA_CHECKER_HPP_
28 
29 #include <ros/ros.h>
30 #include <vector>
31 #include <boost/array.hpp>
32 #include <boost/smart_ptr.hpp>
33 #include <boost/ptr_container/ptr_vector.hpp>
36 
37 extern "C"
38 {
41 }
42 
43 namespace generic_updater
44 {
46 {
47 public:
48  explicit MessageFromMotorChecker(int id)
49  : motor_id_(id), received_(false)
50  {
51  }
52 
54  {
55  }
56 
57  int motor_id_;
58 
59  virtual void set_received();
60 
61  bool get_received();
62 
63 protected:
64  bool received_;
65 };
66 
69 {
70 public:
71  explicit SlowMessageFromMotorChecker(int id);
72 
73  boost::array<bool, MOTOR_SLOW_DATA_LAST + 1> slow_data_received;
74 
75  virtual void set_received(FROM_MOTOR_SLOW_DATA_TYPE slow_data_type);
76 };
77 
79 {
80 public:
82  : msg_type(msg_type)
83  {
84  }
85 
87  std::vector<MessageFromMotorChecker *> msg_from_motor_checkers;
88 
89  int find(int motor_id);
90 };
91 
92 /*
93 * MotorDataChecker checks if all expected messages from the motors
94 * have been received
95 */
97 {
98 public:
99  MotorDataChecker(std::vector<shadow_joints::Joint> joints_vector,
100  std::vector<UpdateConfig> initialization_configs_vector);
101 
102  ~MotorDataChecker();
103 
104  /*
105  * Checks the message as received. Checking if we received the specified motor_data_type
106  * or the motor_slow_data_type.
107  * Checks a certain message coming from a certain joint (motor)
108  * Joints without a motor are not expected to provide any information
109  *
110  * @param joint_tmp joint iterator containing the data of the joint
111  * @param motor_data_type the type of the received data
112  * @param motor_slow_data_type the type of the received sub-data (used if the motor_data_type is MOTOR_DATA_SLOW_MISC)
113  * @return true if all expected messages have already been received
114  */
115  bool check_message(std::vector<shadow_joints::Joint>::iterator joint_tmp,
116  FROM_MOTOR_DATA_TYPE motor_data_type, int16u motor_slow_data_type);
117 
118  /*
119  * Initializes the Motor Data Checker to the not received state for each message
120  * Should be used when reinitializing
121  *
122  * @param joints_vector the vector with the joints (motors) from which information is coming
123  * @param initialization_configs_vector vector containing the initialization commands whose answers need to be checked
124  */
125  void init(std::vector<shadow_joints::Joint> joints_vector,
126  std::vector<UpdateConfig> initialization_configs_vector);
127 
128 protected:
129  static const double timeout;
134 
135  void timer_callback(const ros::TimerEvent &event);
136 
137  bool is_everything_checked();
138 
139  int find(FROM_MOTOR_DATA_TYPE motor_data_type);
140 
141  std::vector<MessageChecker> msg_checkers_;
142 };
143 } // namespace generic_updater
144 
145 /* For the emacs weenies in the crowd.
146  Local Variables:
147  c-basic-offset: 2
148  End:
149 */
150 
151 #endif /* MOTOR_DATA_CHECKER_HPP_ */
unsigned short int16u
void init(const M_string &remappings)
operation_mode::device_update_state::DeviceUpdateState update_state
MessageChecker(FROM_MOTOR_DATA_TYPE msg_type)
boost::array< bool, MOTOR_SLOW_DATA_LAST+1 > slow_data_received
std::vector< MessageFromMotorChecker * > msg_from_motor_checkers
std::vector< MessageChecker > msg_checkers_
FROM_MOTOR_SLOW_DATA_TYPE
FROM_MOTOR_DATA_TYPE


sr_robot_lib
Author(s): Ugo Cupcic, Toni Oliver
autogenerated on Tue Oct 13 2020 04:01:57