Skip to content

Commit

Permalink
Course view debug, message error handlings, auto subscribe, intParamView
Browse files Browse the repository at this point in the history
  • Loading branch information
izsoandras committed Jan 14, 2022
1 parent c805dee commit 5fbf95b
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 59 deletions.
5 changes: 3 additions & 2 deletions RKIgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __init__(self, test_source_en=False):
self.robotPinger.start_reqing()

self.tabs = None
self.init_tabs(tel_dh_by_name, param_dh_by_type, plots_rec)
self.init_tabs(tel_dh_by_name, tel_dh_by_type, plots_rec)
self.statusbar = my_gui.custom_elements.RKIstatusbar(self.root, self.param_listener, self.dbproxy, self.robotPinger)
# self.start_stop_frame =my_gui.custom_elements.RKIStartStopFrame(self.root, self.param_listener, 0x20, 0x21) # TODO: outsource
self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
Expand Down Expand Up @@ -187,13 +187,14 @@ def init_tabs(self, dh_by_name, dh_by_type, plot_rec):
# Tabs
self.tabs = ttk.Notebook(self.root)

course_tab = CourseMap(self.tabs, self.param_listener, 0x22, dh_by_type[0x22])
course_tab = CourseMap(self.tabs, self.param_listener, 0x22, dh_by_type[0x09])
telemetry_tab = my_gui.plotting.TelemeteryFrame.TelemetryFrame(self.tabs, self.tel_listener, dh_by_name,
plot_rec)
db_tab = my_gui.db_frames.DbExportFrame.DBExportFrame(self.tabs, self.dbproxy)
self.tabs.add(course_tab, text='Course')
self.tabs.add(telemetry_tab, text='Graphs')
self.tabs.add(db_tab, text='Database')
telemetry_tab.fr_startstop.on_btn_open()

def on_closing(self):
self.logger.info('Start closing sequence')
Expand Down
6 changes: 3 additions & 3 deletions assets/map/course.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coords":[[ 1029 , 207 ] , [ 93, 658],[ 90,182],[229,483],[281,281],[342,481],[452,483],[415,147],[484,257],[578,324],[709,109],[718,560],[768,433],[735,275],[1001,530],[901,311],[58,423],[113,486],[319,660],[480,655],[516,487],[796,120],[59,580],[176,392],[282,148],[283,578],[400,389],[399,689],[515,413],[512,578],[668,315],[772,212],[882,66],[876,560],[1034,417],[519,145],[61,320]],
"dirs":[[0,1],[1,-1],[-1,-1],[1,-1],[-1,0],[-1,-1],[-1,1],[-1,0],[-1,0],[1,1],[-1,-1],[1,0],[0,-1],[-1,-1],[1,1],[-1,0],[0,-1],[-1,-1],[1,-1],[1,1],[0,-1],[-1,-1],[0,-1],[0,-1],[-1,0],[0,-1],[0,1],[1,0],[0,-1],[0,-1],[-1,0],[0,-1],[-1,0],[1,0],[0,1],[-1,0],[0,-1]],
"name": ["S","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","","","","","","","","","","","","","","","","","","","","","X"]
"coords":[[ 1029 , 217 ] , [ 93, 668],[ 90,192],[229,493],[281,291],[342,491],[452,493],[415,157],[484,267],[578,334],[709,119],[718,570],[768,443],[735,285],[1001,540],[901,321],[58,433],[113,496],[319,670],[480,665],[516,497],[796,130],[59,590],[176,402],[282,158],[283,588],[400,399],[399,699],[515,423],[512,588],[668,325],[772,222],[882,76],[876,570],[1034,427],[519,155],[61,330],[172,63]],
"dirs":[[0,1],[1,-1],[-1,-1],[1,-1],[-1,0],[-1,-1],[-1,1],[-1,0],[-1,0],[1,1],[-1,-1],[1,0],[0,-1],[-1,-1],[1,1],[-1,0],[0,-1],[-1,-1],[1,-1],[1,1],[0,-1],[-1,-1],[0,-1],[0,-1],[-1,0],[0,-1],[0,1],[1,0],[0,-1],[0,-1],[-1,0],[0,-1],[-1,0],[1,0],[0,1],[-1,0],[0,-1],[1,0]],
"name": ["S","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","","","","","","","","","","","","","","","","","","","","","","X"]
}
Binary file modified assets/map/course.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion clients/mqtt/listeners/MyMQTTllistener.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
import threading
import random
import struct


class MyMQTTlistener(AbstractClient):
Expand Down Expand Up @@ -55,7 +56,11 @@ def build_coders(self, msg_recipes):

def on_message(self, client, userdata, message):
msg_type, payload = self.msg_coder.deconstruct_message(message.payload)
data = self.payload_coders[msg_type].decode(payload)
try:
data = self.payload_coders[msg_type].decode(payload)
except struct.error as se:
self.logger.error(str(se) +f', received: {payload.hex()}')
return

self.logger.debug(f'Message received in {client} on topic {message.topic}: {str(message.payload)}')

Expand Down
1 change: 1 addition & 0 deletions dataholders/DataHolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def refreshData(self):
pass

def getData(self, key=None):

if self.hasNew:
self.hasNew = False # TODO: check thread safety
self.refreshData()
Expand Down
5 changes: 4 additions & 1 deletion msg_codecs/payload_codecs/LogCoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def encode(self, data: dict):

def decode(self, payload):
level = payload[0]
message = str(payload[1:], 'utf-8')
try:
message = str(payload[1:], 'utf-8')
except UnicodeDecodeError as ude:
message = str(ude) + f'message: {payload[1:].hex()}'

return {
'name': self.name,
Expand Down
65 changes: 35 additions & 30 deletions my_gui/custom_elements/course_view/CourseMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@
MANEUVER_FOLLOW_LEFT = 0
MANEUVER_FOLLOW_MIDDLE = 1
MANEUVER_FOLLOW_RIGHT = 2
MANEUVER_TURN_FOLLOW_LEFT = 3
MANEUVER_TURN_FOLLOW_MIDDLE = 4
MANEUVER_TURN_FOLLOW_RIGHT = 5
MANEUVER_EXIT_THROUGH = 6
MANEUVER_LANE_SW_LEFT = 7
MANEUVER_LANE_SW_RIGHT = 8
MANEUVER_STOP = 9
MANEUVER_TURN = 3
MANEUVER_TURN_FOLLOW_LEFT = 4
MANEUVER_TURN_FOLLOW_MIDDLE = 5
MANEUVER_TURN_FOLLOW_RIGHT = 6
MANEUVER_EXIT_THROUGH = 7
MANEUVER_LANE_SW_LEFT = 8
MANEUVER_LANE_SW_RIGHT =9
MANEUVER_STOP = 10

NAVI_EVENT_CROSSING_FRONT = 0
NAVI_EVENT_CROSSING_REAR = 1
NAVI_EVENT_CROSSING_LEFT = 2
NAVI_EVENT_EXIT_LEFT = 3
NAVI_EVENT_START_ROUTE = 4
NAVI_EVENT_INVALID = 5
NAVI_EVENT_TURN_COMPLETE = 5
NAVI_EVENT_INVALID = 6


class CourseMap(tkinter.Frame):
Expand Down Expand Up @@ -197,10 +199,7 @@ def make_car(self, car_ori, car_dir, maneuver):
new_img = ImageOps.mirror(self.fig_imgs_resiz[LANE_RIGHT_IMG])
else:
if maneuver == MANEUVER_EXIT_THROUGH:
if car_ori * car_dir > 0:
new_img = ImageOps.mirror(self.fig_imgs_resiz[EXIT_IMG])
else:
new_img = self.fig_imgs_resiz[EXIT_IMG]
new_img = ImageOps.mirror(self.fig_imgs_resiz[EXIT_IMG])
elif maneuver == MANEUVER_FOLLOW_MIDDLE:
new_img = ImageOps.mirror(self.fig_imgs_resiz[MIDDLE_IMG])
elif maneuver == MANEUVER_FOLLOW_LEFT:
Expand All @@ -219,14 +218,17 @@ def make_car(self, car_ori, car_dir, maneuver):

img.paste(new_img, (0, 0), new_img)

if maneuver in [MANEUVER_TURN_FOLLOW_LEFT, MANEUVER_TURN_FOLLOW_MIDDLE, MANEUVER_TURN_FOLLOW_RIGHT]:
if maneuver in [ MANEUVER_TURN, MANEUVER_TURN_FOLLOW_LEFT, MANEUVER_TURN_FOLLOW_MIDDLE, MANEUVER_TURN_FOLLOW_RIGHT]:
new_img = self.fig_imgs_resiz[DIR_SW_IMG]

img.paste(new_img, (0, 0), new_img)

return img

def put_car(self, car_img, node_idx, node_dir):
if node_idx > len(self.node_info["name"]):
node_idx = -1

angle = math.atan2(self.node_info["dirs"][node_idx][1], self.node_info["dirs"][node_idx][0])
self.car_img = ImageTk.PhotoImage(car_img.rotate(math.degrees(angle), expand=True))
self.canvas.itemconfigure(self.car_img_id, image=self.car_img)
Expand All @@ -248,24 +250,27 @@ def update_car(self):

def update_view(self):
if self.dataholder.hasNew:
# self.car_state = self.dataholder.getData()[-1]
data = self.dataholder.getData()
for key in data.keys():
self.car_state[key] = data[key][-1]

self.invalidate()
# if self.car_state['event'] == NAVI_EVENT_CROSSING_FRONT:
# msg = 'NAVI_EVENT_CROSSING_FRONT'
# elif self.car_state['event'] == NAVI_EVENT_CROSSING_REAR:
# msg = 'NAVI_EVENT_CROSSING_REAR'
# elif self.car_state['event'] == NAVI_EVENT_CROSSING_LEFT:
# msg = 'NAVI_EVENT_CROSSING_LEFT'
# elif self.car_state['event'] == NAVI_EVENT_START_ROUTE:
# msg = 'NAVI_EVENT_START_ROUTE'
# elif self.car_state['event'] == NAVI_EVENT_EXIT_LEFT:
# msg = 'NAVI_EVENT_EXIT_LEFT'
# elif self.car_state['event'] == NAVI_EVENT_INVALID:
# msg = 'NAVI_EVENT_INVALID'
# else:
# msg = 'Unknown navigation event!'
#
# self.logger.info(msg)
if self.car_state['event'] == NAVI_EVENT_CROSSING_FRONT:
msg = 'NAVI_EVENT_CROSSING_FRONT'
elif self.car_state['event'] == NAVI_EVENT_CROSSING_REAR:
msg = 'NAVI_EVENT_CROSSING_REAR'
elif self.car_state['event'] == NAVI_EVENT_CROSSING_LEFT:
msg = 'NAVI_EVENT_CROSSING_LEFT'
elif self.car_state['event'] == NAVI_EVENT_START_ROUTE:
msg = 'NAVI_EVENT_START_ROUTE'
elif self.car_state['event'] == NAVI_EVENT_EXIT_LEFT:
msg = 'NAVI_EVENT_EXIT_LEFT'
elif self.car_state['event'] == NAVI_EVENT_INVALID:
msg = 'NAVI_EVENT_INVALID'
else:
msg = 'Unknown navigation event!'

self.logger.info(msg)

if self._invalid:
self.redraw()
Expand Down
5 changes: 4 additions & 1 deletion my_gui/paramsetter/ParamFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,7 @@ def update_view(self):
data.pop('idx')
if data is not None:
for key in data.keys():
self.param_views[key].set_view(data[key][-1])
try:
self.param_views[key].set_view(data[key][-1])
except KeyError as ke:
print(ke)
15 changes: 8 additions & 7 deletions my_gui/paramsetter/paramviews/IntParamView.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ class IntParamView(my_gui.paramsetter.paramviews.ParamView.ParamView):
def __init__(self, parent, name, bit_num=32, *args, **kwargs):
my_gui.paramsetter.paramviews.ParamView.ParamView.__init__(self, parent, name, *args, **kwargs)
self.bit_num = bit_num
self.tb_set_value.insert(0,'0')
self.tb_set_value.insert(0, '0')
self.stvar_current.set('0')

def validate_input(self, input_value: str):
if input_value.isdigit():
try:
num = int(input_value)
if 2**(self.bit_num - 1)-1 > num >= -2 ** (self.bit_num - 1):
if 2**(self.bit_num - 1)-1 > num >= -(2 ** (self.bit_num - 1)):
return True
else:
return False
except ValueError:
if input_value == '' or input_value == '-':
return True
else:
return False
elif input_value == '':
return True
else:
return False

def get_new_value(self):
try:
Expand Down
11 changes: 9 additions & 2 deletions my_gui/paramsetter/paramviews/paramview_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
def structString2paramView(parent, string: str, names):
ret_dict = {}
names_idx = 0

if string == 'string':
ret_dict = {
names[0]: ipv.IntParamView(parent, 'NOT IMPLEMENTED', 8)
}
return ret_dict

for c in string:
bigC = c.upper()
if c in 'x><=@!':
Expand All @@ -23,9 +30,9 @@ def structString2paramView(parent, string: str, names):
raise Exception(f'Character idx {names_idx} in {string} is in BHILQ but neither B,H,I,L or Q')

if c.isupper():
new_view = ipv.IntParamView(parent, names[names_idx], bit_num)
else:
new_view = uipv.UintParamView(parent, names[names_idx], bit_num)
else:
new_view = ipv.IntParamView(parent, names[names_idx], bit_num)

elif c in 'fd':
new_view = fpv.FloatParamView(parent, names[names_idx])
Expand Down
33 changes: 22 additions & 11 deletions settings/msgs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
fields: [level, msg]
# prefixes: [DEBUG, INFO, WARN, ERR, CRIT]


- name: tel
messages:
- name: LCD
Expand Down Expand Up @@ -58,7 +59,7 @@

- name: 'navigation telemetry'
type: 0x09
format: '<BBBBBBB'
format: '<BBbbbBB'
fields: ['current node', 'goal node', 'node_dir', 'orientation', 'direction', 'event', 'maneuver']

- name: comm
Expand Down Expand Up @@ -92,23 +93,33 @@
type: 0x24
format: '<B'
fields: ['event']


- name: nav data
type: 0x22
format: 'string'
fields: ['msg']

- name: nav state
type: 0x25
format: '<Bbb'
fields: ['node id','node dir','car dir']

- name: lab event
type: 0x26
format: '<B'
fields: ['event']

- name: start
type: 0x20
format: '<'
fields: []
fields: [ ]

- name: stop
type: 0x21
format: '<'
fields: []
fields: [ ]

- name: ping
type: 0x23
format: '<'
fields: []

- name: nav data
type: 0x22
format: 'string'
fields: ['msg']
fields: [ ]
3 changes: 2 additions & 1 deletion settings/proto.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
proto: 'mqtt'
#broker: '152.66.181.27'
#broker: localhost
broker: 192.168.4.1
#broker: 192.168.4.1
broker: 192.168.2.124
user: 'rekesz'
pwd: '12345678'
#client_unique: 'Tarsoly'
Expand Down

0 comments on commit 5fbf95b

Please sign in to comment.