Skip to content

Commit

Permalink
modules
Browse files Browse the repository at this point in the history
  • Loading branch information
IhorNehrutsa authored and IhorNehrutsa committed Dec 14, 2023
1 parent aa5a8f0 commit a0e48ad
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 25 deletions.
11 changes: 9 additions & 2 deletions ports/esp32/modules/WiFi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from _thread import start_new_thread
from machine import Timer
import network
import webrepl

PRINT = False # True #

Expand Down Expand Up @@ -202,8 +203,14 @@ def WiFi_connect(prn=False):
net_state = NET_AP_INIT
PRINT and print('NET_AP_INIT: STAT_NO_AP_FOUND')
elif wlan_status == network.STAT_GOT_IP:
net_state == NET_STA_GOT_IP
# PRINT and print('NET_STA_GOT_IP')
if net_state != NET_STA_GOT_IP:
# try:
# webrepl.stop()
# except:
# pass
webrepl.start(password='')
net_state = NET_STA_GOT_IP
PRINT and print('NET_STA_GOT_IP')

return WiFi_info()

Expand Down
4 changes: 2 additions & 2 deletions ports/esp32/modules/microPyServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ def accept(self):

def receive(self):
try:
received = self._skt.recv(1024)
received, from_addr = self._skt.recvfrom(1024)
if received == b'':
print("{}:{} MicroPyServer connection {} error: received == b''".format(self._host, self.port, self._skt.fileno()), self._skt.fileno())
print("{}:{} MicroPyServer connection {} error: received == b'' from {from_addr}".format(self._host, self.port, self._skt.fileno()), from_addr)
self.connect_close()
return False
self._success_time = time()
Expand Down
7 changes: 4 additions & 3 deletions ports/esp32/modules/saves.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def save_config_offset(owl):
f.write("AZIM_OFFSET = {}\n".format(dumps(owl.azim.mover.offset)))
# f.write("AZIM_OFFSET = 0.0\n")
f.write("ELEV_OFFSET = {}\n".format(dumps(owl.elev.mover.offset)))
f.write("ROLL_OFFSET = {}\n".format(dumps(owl.sensors.offset_roll)))
f.close()
except Exception as e:
print('Error writing config_offset.py:', e)
Expand All @@ -41,12 +42,12 @@ def save_config_speed(owl):
try:
with open("./config_speed.py", "w") as f:
f.write("AZIM_angle_accel_decel = {}\n".format(dumps(owl.azim.mover.accel.angle_accel_decel)))
f.write("AZIM_rpm_high = {}\n".format(dumps(owl.azim.mover.rpm_high)))
f.write("AZIM_rpm_low = {}\n".format(dumps(owl.azim.mover.rpm_low)))
f.write("AZIM_rpm_high = {}\n\n".format(dumps(owl.azim.mover.rpm_high)))

f.write("\n")
f.write("ELEV_angle_accel_decel = {}\n".format(dumps(owl.elev.mover.accel.angle_accel_decel)))
f.write("ELEV_rpm_low = {}\n".format(dumps(owl.elev.mover.rpm_low)))
f.write("ELEV_rpm_high = {}\n".format(dumps(owl.elev.mover.rpm_high)))
f.write("ELEV_rpm_low = {}\n".format(dumps(owl.elev.mover.rpm_low)))
f.close()
except Exception as e:
print('Error writing config_speed.py:', e)
30 changes: 19 additions & 11 deletions ports/esp32/modules/sector.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
rpm_high_save = 0
rpm_low_save = 0

#motor_state = -1
motor_state = -1

def handle_sector(owl, motor, ros_params):
global rpm_high_save, rpm_low_save
Expand All @@ -18,7 +18,7 @@ def handle_sector(owl, motor, ros_params):
# if motor_state != motor.state:
# print('motor_state <- motor.state', motor_state, motor.state)
# motor_state = motor.state

# Поиск глобального максимального уровня в секторе.
handle_ros_command(owl)
if owl.value_now is None:
Expand All @@ -34,7 +34,7 @@ def handle_sector(owl, motor, ros_params):
if len(motor.value_start) == 0:
motor.value_start = v # обнаружен сигнал
motor.angle_start = a # в этой позиции

if motor.state == 0: # очищаем исходные
owl.sector_time = time()
#owl.ros_command2 = ["/interface/wireless/set", "=.id=wlan1", "=tx-chains=0,1", "=rx-chains=0,1"]
Expand Down Expand Up @@ -62,7 +62,7 @@ def handle_sector(owl, motor, ros_params):
else:
motor.angle_begin = None # сигнала нет в начале поиска (не будет перезаписан)
if owl.mode == owl.MD_SECTOR_A:
owl.elev.angle_target = 0 # перейти в горизонт
owl.elev.angle_target = 0 # перейти в горизонт

motor.angle_start = a # если сигнал отсутствует, то стартовая позиция будет переписана при обнаружении сигнала
motor.value_start = v
Expand Down Expand Up @@ -94,19 +94,19 @@ def handle_sector(owl, motor, ros_params):
owl.elev.angle_target = - owl.ANTENNA_ANGLE
else:
owl.elev.angle_target = 0

if owl.sector_counter == 2:
owl.azim.mover.rpm_high = owl.azim.mover.rpm_high / 5
owl.azim.mover.rpm_low = owl.azim.mover.rpm_low / 5
else:
owl.azim.mover.rpm_high = rpm_high_save
owl.azim.mover.rpm_low = rpm_low_save

# print('owl.azim.mover.rpm_high, owl.azim.mover.rpm_low', owl.azim.mover.rpm_high, owl.azim.mover.rpm_low, motor.mover.rpm)
# print('Поиск по азимуту owl.azim.angle_target=', owl.azim.angle_target, ', owl.elev.angle_target=', owl.elev.angle_target, ', owl.sector_counter = ', owl.sector_counter)
# print()
owl.sector_counter += 1

owl.sector_counter += 1
motor.state = 3

elif motor.state == 3:
Expand All @@ -121,17 +121,25 @@ def handle_sector(owl, motor, ros_params):

if motor.angle_best is not None:
motor.angle_target = motor.angle_best # идем в лучшее
motor.state = 5

owl.azim.mover.rpm_high = rpm_high_save
owl.azim.mover.rpm_low = rpm_low_save

#print("owl.sector_counter", owl.sector_counter)
if owl.sector_counter >= 2:
motor.state = 5
else:
motor.search_dir = -motor.search_dir
motor.state = 2
else:
#if owl.sector_counter < 2:
motor.search_dir = -motor.search_dir
motor.state = 2 # повторный поиска в противоположном направлении, нужно пройти полный сектор поиска

# elif motor.state == 35:
# if motor.mover.is_ready():
# motor.mover.stop()
# motor.state = 4
#
#
# elif motor.state == 4:
# if owl.state == owl.CM_NO:
# motor.mover.stop()
Expand Down
16 changes: 9 additions & 7 deletions ports/esp32/modules/web_srv.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ def show_index_page(server, arg, owl):
s1 = ""
if owl.autorefresh:
s1 = '<meta http-equiv="Refresh" content="2" />'
s2 = "СРШ: " + dumps(owl.value_now)
s3 = "Азимут,°: " + str(owl.azim.mover.angle_now) + " → " + str(owl.azim.angle_target) + " (" + str(owl.azim.min_search) + ", " + str(owl.azim.max_search) + ") " + str(owl.azim.angle_best)
s4 = "Кут місця,°: " + str(owl.elev.mover.angle_now) + " → " + str(owl.elev.angle_target) + " (" + str(owl.elev.min_search) + ", " + str(owl.elev.max_search) + ") " + str(owl.elev.angle_best)
_bst = str(owl.ros_best.values())
bst = _bst[_bst.find('['):_bst.find(']') + 1]
s2 = f"СРШ: {owl.value_now} {bst}"
s3 = f"Азимут,°: {owl.azim.mover.angle_now}{owl.azim.angle_target} ({owl.azim.min_search}, {owl.azim.max_search}) [{owl.azim.angle_best}]"
s4 = f"Кут місця,°: {owl.elev.mover.angle_now}{owl.elev.angle_target} ({owl.elev.min_search}, {owl.elev.max_search}) [{owl.elev.angle_best}]"

input_a = str(owl.input_azim)
input_e = str(owl.input_elev)
Expand Down Expand Up @@ -161,11 +163,11 @@ def show_config_speed_page(server, arg, owl):
collect()
s = html_config_speed.format(
str(owl.azim.mover.accel.angle_accel_decel), #
str(owl.azim.mover.rpm_low), #
str(owl.azim.mover.rpm_high), #
str(round(owl.azim.mover.rpm_high, 2)), #
str(round(owl.azim.mover.rpm_low, 2)), #
str(owl.elev.mover.accel.angle_accel_decel), #
str(owl.elev.mover.rpm_low), #
str(owl.elev.mover.rpm_high)
str(round(owl.elev.mover.rpm_high, 2)), #
str(round(owl.elev.mover.rpm_low, 2))
)
collect()
server.out(s)
Expand Down

0 comments on commit a0e48ad

Please sign in to comment.