|
15 | 15 | from controller.common.lut import LUT
|
16 | 16 | from controller.wingsail.controllers import WingsailController
|
17 | 17 |
|
18 |
| -SCALING_INTERCEPT = 1 |
19 |
| - |
20 | 18 |
|
21 | 19 | def main(args=None):
|
22 | 20 | rclpy.init(args=args)
|
@@ -78,8 +76,8 @@ def __declare_ros_parameters(self):
|
78 | 76 | ("pub_period_sec", rclpy.Parameter.Type.DOUBLE),
|
79 | 77 | ("reynolds_number", rclpy.Parameter.Type.DOUBLE_ARRAY),
|
80 | 78 | ("angle_of_attack", rclpy.Parameter.Type.DOUBLE_ARRAY),
|
81 |
| - ("apparent_wind_threshold", rclpy.Parameter.Type.DOUBLE), |
82 |
| - ("scaling_coef", rclpy.Parameter.Type.DOUBLE), |
| 79 | + ("apparent_wind_lower_threshold", rclpy.Parameter.Type.DOUBLE), |
| 80 | + ("apparent_wind_upper_threshold", rclpy.Parameter.Type.DOUBLE), |
83 | 81 | ],
|
84 | 82 | )
|
85 | 83 |
|
@@ -146,20 +144,26 @@ def __publish(self):
|
146 | 144 |
|
147 | 145 | apparent_speed = self.__filtered_wind_sensor.speed.speed
|
148 | 146 | apparent_direction = self.__filtered_wind_sensor.direction
|
149 |
| - apparent_threshold = ( |
150 |
| - self.get_parameter("apparent_wind_threshold").get_parameter_value().double_value |
| 147 | + apparent_lower_threshold = ( |
| 148 | + self.get_parameter("apparent_wind_lower_threshold").get_parameter_value().double_value |
| 149 | + ) |
| 150 | + apparent_upper_threshold = ( |
| 151 | + self.get_parameter("apparent_wind_upper_threshold").get_parameter_value().double_value |
151 | 152 | )
|
152 | 153 |
|
153 |
| - # Sets trim tab angle, scales if apparent wind speed is above threshold |
154 | 154 | self.__trim_tab_angle = self.__wingsailController.get_trim_tab_angle(
|
155 | 155 | apparent_speed, apparent_direction
|
156 | 156 | )
|
157 |
| - if apparent_speed > apparent_threshold: |
158 |
| - coef = self.get_parameter("scaling_coef").get_parameter_value().double_value |
159 |
| - speed_difference = apparent_threshold - apparent_speed |
160 |
| - self.__trim_tab_angle = ( |
161 |
| - self.__trim_tab_angle * coef * speed_difference + SCALING_INTERCEPT |
162 |
| - ) |
| 157 | + |
| 158 | + # Gets scaling factor based on wind speed thresholds |
| 159 | + scaling_coef = 1 |
| 160 | + if apparent_speed > apparent_lower_threshold and apparent_speed < apparent_upper_threshold: |
| 161 | + difference = apparent_upper_threshold - apparent_lower_threshold |
| 162 | + scaling_coef = -1 * (apparent_speed - apparent_lower_threshold) / difference + 1 |
| 163 | + elif apparent_speed >= apparent_upper_threshold: |
| 164 | + scaling_coef = 0 |
| 165 | + |
| 166 | + self.__trim_tab_angle = scaling_coef * self.__trim_tab_angle |
163 | 167 |
|
164 | 168 | msg.trim_tab_angle_degrees = self.__trim_tab_angle
|
165 | 169 |
|
|
0 commit comments