Beispiel #1
0
 def set_target_deep(self, value):
     self._target_deep = limits(value, 0, 9000)
Beispiel #2
0
 def _set_speed(self, new_speed):
     self._speed = limits(new_speed, 0, self.MAX_SPEED)
Beispiel #3
0
    def turn(self, time_elapsed, messages):
        self.time_elapsed = time_elapsed

        # update timed values
        self._rudder.update(time_elapsed)
        self._turbine_level.update(time_elapsed)
        self.towed_array.update(time_elapsed)

        # ship_moviment_angle is the angle the ship is moving
        ship_moviment_angle = self._velocity.get_angle()

        # ship_rotation_angle is the angle the ship pointing
        ship_course_angle = self._ship_course

        # drifting_angle_diff is the difference between the angle the sub is moving and the angle of the ship is bearing
        # meaning the ship the turning left or right
        drifting_angle_diff = normalize_angle_2pi(ship_moviment_angle - ship_course_angle)

        self.turbine_acceleration = self.MAX_ACCELERATION * self.turbine_level / 100
        self.turbine_acceleration_x = math.cos(ship_course_angle) * self.turbine_acceleration
        self.turbine_acceleration_y = math.sin(ship_course_angle) * self.turbine_acceleration
        self.turbine_acceleration = Point(self.turbine_acceleration_x, self.turbine_acceleration_y)

        if self.rudder != 0:
            # rotate the ship
            # the ship rotates proportional to it's speed
            angle_to_rotate = (self.rudder * time_elapsed)  * (self.actual_speed / self.MAX_SPEED)
            new_angle = ship_course_angle + angle_to_rotate
            self._ship_course = normalize_angle_pi(new_angle)

        # correction if the drag factor since the sub is making a turn
        self.drag_factor = self.DRAG_FACTOR * (1 + abs(300 * math.sin(drifting_angle_diff)))

        # speed
        if self.speed_mode == self.SPEED_MODE_SPEED:
            if self.actual_speed !=  self.target_speed:
                self.acceleration_needed = self.drag_factor * (self.target_speed**2)
                self.turbine_level_needed = 100.0 * self.acceleration_needed / self.MAX_ACCELERATION

                # adjust turbines
                diff_speed = self.target_speed - self.actual_speed
                diff_turbine = self.turbine_level - self.turbine_level_needed
                # diff*10 gives more burst to make the change in speed faster
                self.turbine_level = self.turbine_level_needed + limits(diff_speed, -1, 1) * 10

        elif self.speed_mode == self.SPEED_MODE_TURBINE:
            # fixed turbine level
            self.acceleration_needed = 0
            self.turbine_level_needed = self._target_turbine
            self.turbine_level  = self._target_turbine


        # drag force
        self.total_drag_acceleration = -1.0 * self.drag_factor * ((self.actual_speed) ** 2)
        drag_x = math.cos(ship_moviment_angle) * self.total_drag_acceleration
        drag_y = math.sin(ship_moviment_angle) * self.total_drag_acceleration
        self.drag_acceleration = Point(drag_x, drag_y)

        self._acceleration = self.turbine_acceleration + self.drag_acceleration # convert seconds to hours
        self._velocity += self._acceleration * time_elapsed
        self._position += self._velocity * time_elapsed

        # deep
        deep_diff = self.target_deep - self.actual_deep
        if abs(deep_diff) > 0.1:
            dive_rate = min(deep_diff, self.MAX_DEEP_RATE_FEET)
            self.actual_deep += dive_rate * time_elapsed * 3600

        if self.nav_mode == self.NAV_MODE_DESTINATION:
            self.angle_to_destination = self.position.get_angle_to(self.destination)
            self.angle_difference = normalize_angle_pi(self.angle_to_destination - self.course)
            self.rudder = self.angle_difference * 500.0
Beispiel #4
0
 def set_turbine_level(self, new_level):
     self._turbine_level.target_value = limits(new_level, -100, 100)
Beispiel #5
0
 def set_rudder(self, angle):
     angle = limits(angle, -self.MAX_TURN_RATE_HOUR, self.MAX_TURN_RATE_HOUR)
     self._rudder.target_value = angle
Beispiel #6
0
 def _set_actual_speed(self, value):
     self._velocity.length = limits(value, 0, self.MAX_SPEED)
Beispiel #7
0
 def set_target_speed(self, value):
     self._target_speed = limits(value, 0, self.MAX_SPEED)
Beispiel #8
0
 def set_turbine_level(self, new_level):
     self._turbine_level = limits(new_level, -100, 100)
Beispiel #9
0
 def set_rudder(self, angle):
     angle = limits(angle, -self.max_turn_per_hour, self.max_turn_per_hour)
     self._rudder = angle