Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this only exists to see the diff between our forks ben #2

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35,485 changes: 35,485 additions & 0 deletions candump-2024-01-30_012633.log

Large diffs are not rendered by default.

1,230 changes: 1,230 additions & 0 deletions ksu-dbc.dbc

Large diffs are not rendered by default.

837 changes: 837 additions & 0 deletions ksu.bin

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions nix_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#! /bin/bash
nix develop --extra-experimental-features nix-command --extra-experimental-features flakes
26 changes: 16 additions & 10 deletions py_data_acq/broadcast-test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import socket
import time
import math
import can
from can.interfaces.udp_multicast import UdpMulticastBus
import cantools
Expand All @@ -11,32 +12,37 @@

# Define the IP and port for the UDP socket
# bus1 = can.interface.Bus('can0', bustype='virtual')
def generate_sine_wave(amplitude, frequency, phase_shift, time_variable):
return amplitude * math.sin(2 * math.pi * frequency * time_variable + phase_shift)

bus1 = can.Bus(channel=UdpMulticastBus.DEFAULT_GROUP_IPv6, interface='udp_multicast')
def main():
path_to_dbc = os.environ.get('DBC_PATH')
full_path = os.path.join(path_to_dbc, "hytech.dbc")
# Serialize the message to bytes
db = cantools.database.load_file(full_path)

msg = db.get_message_by_name("ID_MC1_TORQUE_COMMAND")
rpm = db.get_message_by_name("ID_MC4_SETPOINTS_COMMAND")
data = msg.encode({'torque_command': 100})

msg = can.Message(arbitration_id=msg.frame_id, is_extended_id=False, data=data)
# msg = db.get_message_by_name("M166_Current_Info")
rpm = db.get_message_by_name("M165_Motor_Position_Info")
value=100
# data = msg.encode({"D4_DC_Bus_Current": 100,"D1_Phase_A_Current":int(value),"D2_Phase_B_Current":int(value),"D3_Phase_C_Current":int(value)})

# msg = can.Message(arbitration_id=msg.frame_id, is_extended_id=False, data=data)
# print(msg)
rpm_set = 100
while(1):
try:
rpm_set= rpm_set+1
bus1.send(msg)
rpm_data = rpm.encode({'negative_torque_limit': 1, 'positive_torque_limit': 1, 'speed_setpoint_rpm': rpm_set, 'remove_error': 1, 'driver_enable': 1, 'hv_enable': 1, 'inverter_enable': 1})
# rpm_set= rpm_set+1
# bus1.send(msg)
rpm_set = generate_sine_wave(3000,1,90,time.time()) + 3000
rpm_data = rpm.encode({'D4_Delta_Resolver_Filtered': int(1), 'D3_Electrical_Output_Frequency': int(1), 'D2_Motor_Speed': rpm_set, 'D1_Motor_Angle_Electrical': int(1)})
rpm_msg = can.Message(arbitration_id=rpm.frame_id, is_extended_id=False, data=rpm_data)
bus1.send(rpm_msg)

print("Message sent on {}".format(bus1.channel_info))
# print("Message sent on {}".format(bus1.channel_info))
except can.CanError:
print("Message NOT sent! Please verify can0 is working first")
time.sleep(0.05)
time.sleep(0.01)

if __name__ == "__main__":
main()
70 changes: 70 additions & 0 deletions py_data_acq/daqdiff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
diff --git a/py_data_acq/broadcast-test.py b/py_data_acq/broadcast-test.py
index cb6a6d1..0d2e043 100644
--- a/py_data_acq/broadcast-test.py
+++ b/py_data_acq/broadcast-test.py
@@ -39,7 +39,7 @@ def main():
rpm_msg = can.Message(arbitration_id=rpm.frame_id, is_extended_id=False, data=rpm_data)
bus1.send(rpm_msg)

- print("Message sent on {}".format(bus1.channel_info))
+ # print("Message sent on {}".format(bus1.channel_info))
except can.CanError:
print("Message NOT sent! Please verify can0 is working first")
time.sleep(0.01)
diff --git a/py_data_acq/runner.py b/py_data_acq/runner.py
index 03e5309..06b030e 100644
--- a/py_data_acq/runner.py
+++ b/py_data_acq/runner.py
@@ -26,7 +26,7 @@ import logging

async def continuous_can_receiver(can_msg_decoder: cantools.db.Database, message_classes, queue, q2):
with can.Bus(
- channel=UdpMulticastBus.DEFAULT_GROUP_IPv6, interface='udp_multicast'
+ interface='socketcan', channel='can0', bitrate=500000
) as bus:
reader = can.AsyncBufferedReader()
listeners: List[MessageRecipient] = [
@@ -36,14 +36,16 @@ async def continuous_can_receiver(can_msg_decoder: cantools.db.Database, message
notifier = can.Notifier(bus, listeners, loop=loop)
while True:
msg = await reader.get_message()
- decoded_msg = can_msg_decoder.decode_message(msg.arbitration_id, msg.data, decode_containers=True)
- msg = can_msg_decoder.get_message_by_frame_id(msg.arbitration_id)
- msg = pb_helpers.pack_protobuf_msg(decoded_msg, msg.name.lower(), message_classes)
-
- data = QueueData(msg.DESCRIPTOR.name, msg)
- await queue.put(data)
- await q2.put(data)
-
+ try:
+ decoded_msg = can_msg_decoder.decode_message(msg.arbitration_id, msg.data, decode_containers=True)
+ msg = can_msg_decoder.get_message_by_frame_id(msg.arbitration_id)
+ msg = pb_helpers.pack_protobuf_msg(decoded_msg, msg.name.lower(), message_classes)
+ data = QueueData(msg.DESCRIPTOR.name, msg)
+ await queue.put(data)
+ await q2.put(data)
+ except:
+ logger.error("Error on message decode")
+ continue
async def write_data_to_mcap(queue, mcap_writer):
async with mcap_writer as mcw:
while True:
@@ -97,4 +99,4 @@ if __name__ == "__main__":
logging.basicConfig()
logger = logging.getLogger('data_writer_service')
logger.setLevel(logging.INFO)
- asyncio.run(run(logger))
\ No newline at end of file
+ asyncio.run(run(logger))
diff --git a/run_server.sh b/run_server.sh
index a12624a..0d54236 100755
--- a/run_server.sh
+++ b/run_server.sh
@@ -1,4 +1,4 @@
#! /bin/bash
# nix develop --extra-experimental-features nix-command --extra-experimental-features flakes
-sh -c 'python3 ./py_data_acq/broadcast-test.py' &
-python3 ./py_data_acq/runner.py
\ No newline at end of file
+# sh -c 'python3 ./py_data_acq/broadcast-test.py' &
+python3 ./py_data_acq/runner.py
14 changes: 13 additions & 1 deletion py_data_acq/py_data_acq/common/protobuf_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,17 @@ def pack_protobuf_msg(cantools_dict: dict, msg_name: str, message_classes):
if msg_name in message_classes:
pb_msg = message_classes[msg_name]()
for key in cantools_dict.keys():
setattr(pb_msg, key, cantools_dict[key])
try:
setattr(pb_msg, key, cantools_dict[key])
except TypeError as e:
print(f"Caught TypeError: {e}")
expected_type = type(getattr(pb_msg, key))

try:
converted_value = expected_type(cantools_dict[key])
setattr(pb_msg, key, converted_value)
print(f"Successfully set {key} to {converted_value}")
except ValueError:
print(f"Unable to convert {cantools_dict[key]} to {expected_type.__name__}")

return pb_msg
28 changes: 16 additions & 12 deletions py_data_acq/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

async def continuous_can_receiver(can_msg_decoder: cantools.db.Database, message_classes, queue, q2):
with can.Bus(
channel=UdpMulticastBus.DEFAULT_GROUP_IPv6, interface='udp_multicast'
interface='socketcan', channel='can0', bitrate=500000
) as bus:
reader = can.AsyncBufferedReader()
listeners: List[MessageRecipient] = [
Expand All @@ -36,14 +36,16 @@ async def continuous_can_receiver(can_msg_decoder: cantools.db.Database, message
notifier = can.Notifier(bus, listeners, loop=loop)
while True:
msg = await reader.get_message()
decoded_msg = can_msg_decoder.decode_message(msg.arbitration_id, msg.data, decode_containers=True)
msg = can_msg_decoder.get_message_by_frame_id(msg.arbitration_id)
msg = pb_helpers.pack_protobuf_msg(decoded_msg, msg.name.lower(), message_classes)

data = QueueData(msg.DESCRIPTOR.name, msg)
await queue.put(data)
await q2.put(data)

try:
decoded_msg = can_msg_decoder.decode_message(msg.arbitration_id, msg.data, decode_containers=True)
msg = can_msg_decoder.get_message_by_frame_id(msg.arbitration_id)
msg = pb_helpers.pack_protobuf_msg(decoded_msg, msg.name.lower(), message_classes)
data = QueueData(msg.DESCRIPTOR.name, msg)
await queue.put(data)
await q2.put(data)
except:
logger.error("Error on message decode")
continue
async def write_data_to_mcap(queue, mcap_writer):
async with mcap_writer as mcw:
while True:
Expand All @@ -53,7 +55,7 @@ async def fxglv_websocket_consume_data(queue, foxglove_server):
async with foxglove_server as fz:
while True:
await fz.send_msgs_from_queue(queue)

PORT = 8770
async def run(logger):

# for example, we will have CAN as our only input as of right now but we may need to add in
Expand All @@ -76,7 +78,9 @@ async def run(logger):


list_of_msg_names, msg_pb_classes = pb_helpers.get_msg_names_and_classes()
fx_s = HTProtobufFoxgloveServer("0.0.0.0", 8765, "asdf", full_path, list_of_msg_names)

logger.info(f"Start server with port {PORT}")
fx_s = HTProtobufFoxgloveServer("0.0.0.0", PORT, "asdf", full_path, list_of_msg_names)

mcap_writer = HTPBMcapWriter(".", list_of_msg_names, True)

Expand All @@ -95,4 +99,4 @@ async def run(logger):
logging.basicConfig()
logger = logging.getLogger('data_writer_service')
logger.setLevel(logging.INFO)
asyncio.run(run(logger))
asyncio.run(run(logger))
Loading