Skip to content

Commit

Permalink
Removed debug messages and updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
gabryelreyes committed Nov 21, 2023
1 parent f92bea9 commit 0e40cbd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 81 deletions.
3 changes: 0 additions & 3 deletions python/SerialMuxProt.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ def __cmd_sync_rsp(self, payload: bytearray) -> None:
if self.__sync_data.last_sync_command == rcvd_timestamp:
self.__sync_data.last_sync_response = self.__sync_data.last_sync_command
self.__sync_data.is_synced = True
print("Synced!")

# Process pending Subscriptions
self.__process_subscriptions()
Expand Down Expand Up @@ -597,8 +596,6 @@ def __cmd_scrb_rsp(self, payload: bytearray) -> None:
# Parse payload
channel_number = payload[4]
channel_name = str(payload[5:], "ascii").strip('\x00')
print(channel_number)
print(channel_name)

if (self.__max_configured_channels >= channel_number) and \
(0 < self.__channels.number_of_pending_channels):
Expand Down
79 changes: 2 additions & 77 deletions python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@

import sys
import time
from struct import Struct
import keyboard # pylint: disable=import-error
import numpy as np
from SerialMuxProt import SerialMuxProt
# from socket_client import SocketClient
from serial_client import SerialClient
from SerialMuxProt import SerialMuxProt

################################################################################
# Variables
Expand Down Expand Up @@ -65,61 +61,11 @@ def millis() -> int:
return current_time - START_TIME


def callback_line_sensors(payload: bytearray) -> None:
""" Callback of LINE_SENS Channel """
unpacker = Struct(">HHHHH")
data = unpacker.unpack_from(payload)
print(np.array(data, dtype=np.int16))


def callback_timestamp(payload: bytearray) -> None:
""" Callback of TIMESTAMP Channel """

print(payload.hex())

# unpacker = Struct(">HH")
# data = unpacker.unpack_from(payload)
# print(np.array(data, dtype=np.int16))


def callback_remote_response(payload: bytearray) -> None:
""" Callback of REMOTE_CMD Channel """
if payload == b'\x00':
print("Command OK")
elif payload == b'\x01':
print("Command Pending")
elif payload == b'\x02':
print("Command Error")


def send_motor_setpoints(set_point_left: int, set_point_right: int):
"""
Send Motor Setpoints
"""
payload = bytearray()
payload.append(0x01)
payload.append(0x00)
payload.append(0x00)
payload.append(0x00)

if len(payload) == 4:
smp_server.send_data("COUNTER", payload)


def send_command(command: str) -> None:
"""Send command to RadonUlzer"""

payload = bytearray()

if command == "line_calib":
payload.append(0x01)
elif command == "motor_calib":
payload.append(0x02)
elif command == "enable_drive":
payload.append(0x03)

smp_server.send_data("REMOTE_CMD", payload)


def main():
"""The program entry point function.adadadadada
Expand All @@ -135,28 +81,7 @@ def main():
print(err)
return

# smp_server.create_channel("MOT_SPEEDS", 4)
# smp_server.create_channel("REMOTE_CMD", 1)
# smp_server.subscribe_to_channel("REMOTE_RSP", callback_remote_response)
# smp_server.subscribe_to_channel("LINE_SENS", callback_line_sensors)
smp_server.subscribe_to_channel("TIMESTAMP", callback_timestamp)
smp_server.create_channel("COUNTER", 4)

keyboard.on_press_key("w", lambda e: send_motor_setpoints(0x8000, 0x8000))
# keyboard.on_press_key("s", lambda e: send_motor_setpoints(0x7FFF, 0x7FFF))
# keyboard.on_press_key("a", lambda e: send_motor_setpoints(0x7FFF, 0x8000))
# keyboard.on_press_key("d", lambda e: send_motor_setpoints(0x8000, 0x7FFF))
# keyboard.on_release_key(
# "w", lambda e: send_motor_setpoints(0x0000, 0x0000))
# keyboard.on_release_key(
# "a", lambda e: send_motor_setpoints(0x0000, 0x0000))
# keyboard.on_release_key(
# "s", lambda e: send_motor_setpoints(0x0000, 0x0000))
# keyboard.on_release_key(
# "d", lambda e: send_motor_setpoints(0x0000, 0x0000))
# keyboard.on_press_key("l", lambda e: send_command("line_calib"))
# keyboard.on_press_key("m", lambda e: send_command("motor_calib"))
# keyboard.on_press_key("e", lambda e: send_command("enable_drive"))
smp_server.subscribe_to_channel("LED", callback_timestamp)

while True:
if (millis() - last_time) >= 5:
Expand Down
2 changes: 1 addition & 1 deletion python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pyserial == 3.5
pyserial==3.5

0 comments on commit 0e40cbd

Please sign in to comment.