Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if mode is JUST_STARTED:
- mode = STAB_TO_SEARCH_FOR_THE_SUN
- elif mode is STAB_TO_SEARCH_FOR_THE_SUN:
- if speed < -4:
- speed_goal = -4
- elif -4 < speed < 4:
- if abs(speed - -4) < abs(speed - 4):
- speed_goal = -4
- else:
- speed_goal = 4
- else: #speed > 4
- speed_goal = 4
- if abs(speed - speed_goal) < 0.5:
- mode = SEARCH_FOR_THE_SUN
- elif mode is SEARCH_FOR_THE_SUN:
- '''
- s_sun[][] - Массив данных с солнечных датчиков.
- s_sun[номер_датчика][ячейка данных].
- Ячейки данных:
- 0 - 1й поддатчик
- 1 - 2й поддатчик
- 2 - среднеквадратичное двух поддатчиков
- '''
- max_sensor_n = find_max_sensor_n(s_sun[0][2],
- s_sun[1][2],
- s_sun[2][2],
- s_sun[3][2])
- if s_sun[max_sensor_n][2] < SUN_TRESHOLD:
- return
- sun_diff = abs(s_sun[max_sensor_n][0] - s_sun[max_sensor_n][1])
- if sun_diff < SUN_DIFF_TRESHOLD and sun_diff < best_sun_diff:
- azimuth_to_sun = (s_azimuth + max_sensor_n * 90) % 360 # s_azimuth - азимут с датчика
- best_sun_diff = sun_diff
- else:
- mode = TURN_TO_GOAL_ANGLE
- elif mode == TURN_TO_GOAL_ANGLE:
- ...
- def find_max_sensor_n(v0, v1, v2, v3):
- max_v = v0
- max_v_n = 0
- if v1 > max_v:
- max_v = v1
- max_v_n = 1
- if v2 > max_v:
- max_v = v2
- max_v_n = 2
- if v3 > max_v:
- max_v = v3
- max_v_n = 3
- return max_v_n
Add Comment
Please, Sign In to add comment