force_compensator.cpp
Go to the documentation of this file.
1 
25 
26 
28  cmd_pub_ = node_.advertise<heron_msgs::Drive>("cmd_drive",1000);
29  eff_pub_ = node_.advertise<geometry_msgs::Wrench>("eff_wrench",1000);
30 }
31 
32 // Take in a thrust requirement and return the electronic input (into the motor controller) required to achieve given thrust.
33 //TODO:Once better thruster models are known, this should be changed to something more complex than just a linear scaling.
35  //saturate
36 
37  double output = 0;
38  if (thrust > 0)
39  output = thrust * (MAX_OUTPUT/MAX_FWD_THRUST);
40  else if (thrust < 0)
41  output = thrust * (MAX_OUTPUT/MAX_BCK_THRUST);
42  return output;
43 }
44 
45 double ForceCompensator::saturate_thrusters (double thrust) {
46  thrust = std::min(MAX_FWD_THRUST,thrust);
47  thrust = std::max(-1*MAX_BCK_THRUST,thrust);
48  return thrust;
49 }
50 
51 
52 //Take in wrench command and output cmd_drive messages to achieve the given wrench command
53 void ForceCompensator::pub_thrust_cmd (geometry_msgs::Wrench output) {
54  heron_msgs::Drive cmd_output;
55  double fx = output.force.x;
56  double tauz = output.torque.z;
57 
58 
59  //yaw torque maxed out at max torque achievable with the help of reverse thrust
60  double max_tauz = MAX_BCK_THRUST*2*BOAT_WIDTH;
61  tauz = std::min(tauz, max_tauz);
62  tauz = std::max(tauz, -max_tauz);
63 
64  //Guarantee atleast max yaw torque
65  double left_thrust = -tauz/(2*BOAT_WIDTH);
66  double right_thrust = tauz/(2*BOAT_WIDTH);
67 
68  //Provide maximum allowable thrust after yaw torque is guaranteed
69  double max_fx = 0;
70  if (tauz >= 0) {
71  if (fx >= 0) { //forward thrust on the left thruster will be limiting factor
72  max_fx = (MAX_FWD_THRUST - left_thrust) * 2;
73  fx = std::min(max_fx,fx);
74  }
75  else { //backward thrust on the right thruster will be limiting factor
76  max_fx = (-MAX_BCK_THRUST - right_thrust) * 2;
77  fx = std::max(max_fx,fx);
78  }
79  }
80  else {
81  if (fx >= 0 ) {
82  max_fx = (MAX_FWD_THRUST - right_thrust) * 2;
83  fx = std::min(max_fx,fx);
84  }
85  else {
86  max_fx = (-MAX_BCK_THRUST - left_thrust) * 2;
87  fx = std::max(max_fx,fx);
88  }
89  }
90 
91  left_thrust += fx/2.0;
92  right_thrust += fx/2.0;
93 
94  left_thrust = saturate_thrusters (left_thrust);
95  right_thrust = saturate_thrusters (right_thrust);
96 
97  cmd_output.left = calculate_motor_setting (left_thrust);
98  cmd_output.right = calculate_motor_setting (right_thrust);
99  cmd_pub_.publish(cmd_output);
100 
101  pub_effective_wrench(left_thrust, right_thrust);
102 }
103 
104 
105 //take in left and right thrusts (0...1) settings and back calculate what the effective wrench being sent out is. This is a reverse calculation of what is done in "update_forces" and shows the user what the limitations of the thrust settings are.
106 void ForceCompensator::pub_effective_wrench(double left_thrust,double right_thrust) {
107  geometry_msgs::Wrench effective_output;
108  effective_output.force.x = left_thrust + right_thrust;
109  effective_output.torque.z = (right_thrust - left_thrust)*BOAT_WIDTH;
110  eff_pub_.publish(effective_output);
111 }
void pub_thrust_cmd(geometry_msgs::Wrench output)
#define MAX_FWD_THRUST
#define MAX_OUTPUT
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle node_
double saturate_thrusters(double thrust)
double calculate_motor_setting(double thrust)
ros::Publisher cmd_pub_
void pub_effective_wrench(double left_thrust, double right_thrust)
ForceCompensator(ros::NodeHandle &n)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Publisher eff_pub_
#define MAX_BCK_THRUST
#define BOAT_WIDTH


heron_controller
Author(s): Prasenjit Mukherjee
autogenerated on Sun Mar 14 2021 02:31:50