HLR  0.0.1
VirtualServo.hpp
1 #ifndef VIRTUALSERVO_HPP
2 #define VIRTUALSERVO_HPP
3 
4 #include <string>
5 
6 #include "ros/ros.h"
7 #include "std_msgs/Float64.h"
8 #include "urdf/model.h"
9 
10 namespace HLR
11 {
12 namespace Simulation
13 {
18 {
19 public:
25  VirtualServo(const urdf::JointConstSharedPtr& joint_shared_ptr,
26  const std::string& robot_description);
27 
32  void start_update_thread();
33 
37  void notify_change();
38 
44  bool is_update_received() const;
45 
50  void set_speed(double servo_speed);
51 
56  void set_target_pos(double servo_target_pos);
57 
61  void stop_movement();
62 
67  double get_current_pos() const;
68 
73  double get_max_speed() const;
74 
79  double get_max_rad() const;
80 
85  double get_min_rad() const;
86 
92  bool is_moving() const;
93 
94 private:
101  bool use_speed();
102 
108  double steps_to_target_time() const;
109 
115  double steps_to_target_speed() const;
116 
121  void set_servo(double pos);
122 
127  void update_servo();
128 
132  std::string servo_name;
133 
137  std::string ros_namespace;
138 
142  double current_pos;
143 
147  double target_pos;
148 
152  double speed;
153 
157  double max_speed;
158 
162  double min_rad;
163 
167  double max_rad;
168 
172  bool update_received;
173 
177  bool moving;
178 
182  ros::NodeHandle n;
183 
187  ros::Publisher joint_pub;
188 
192  int8_t not_set;
193 
197  uint8_t update_rate;
198 
202  long cmd_time;
203 
207  ros::Rate rate;
208 };
209 }
210 }
211 
212 #endif /* VIRTUALSERVO_HPP */
void set_target_pos(double servo_target_pos)
Target position to move the servo.
VirtualServo is used to simulate realistic movement of the servo.
Definition: VirtualServo.hpp:17
void stop_movement()
Stop the servo from moving.
bool is_moving() const
Servo moving true or false.
bool is_update_received() const
Getter for update bool.
double get_max_rad() const
Maximum angle in radians of the servo.
void notify_change()
Sets update received to true.
VirtualServo(const urdf::JointConstSharedPtr &joint_shared_ptr, const std::string &robot_description)
Constructor for VirtualServo.
double get_current_pos() const
Get the current position of the servo.
double get_max_speed() const
Maximum speed of the servo.
void set_speed(double servo_speed)
Set servo speed.
double get_min_rad() const
Minimum angle in radians of the servo.
void start_update_thread()
Starts a thread running the private function Update servo and detaches it.