This commit is contained in:
remilia 2025-04-10 23:15:05 +08:00
parent 4a30b59616
commit 339b38cf87
4 changed files with 46 additions and 10 deletions

View File

@ -67,7 +67,7 @@ class Joystick(Node):
def joystick_event_loop(self):
def key_received(key: pyjoystick.interface.Key):
msg = JoystickMsg(str(key).replace('-', ''), key.value)
# print(msg)
print(msg)
match msg.key:
case 'Axis 0':
self.d['x'] = -msg.value

View File

@ -33,7 +33,7 @@ if __name__ == '__main__':
Loader(),
Muxer(level=logging.DEBUG),
# Midi(),
# Joystick(),
Joystick(),
Robot(),
Recorder(),
# Monitor(),

44
test/realtimeplot.py Normal file
View File

@ -0,0 +1,44 @@
import struct
from pathlib import Path
import numpy as np
import zmq
import time
import sys
from matplotlib import pyplot as plt
def test():
ctx = zmq.Context()
sock = ctx.socket(zmq.PULL)
sock.bind('tcp://0.0.0.0:5555')
li = []
cnt = 0
while True:
s = sock.recv_pyobj()
cnt += 1
if cnt == 1:
cnt = 0
li.append(s)
if li.__len__() > 100:
li = li[1:]
# print(li.__len__())
aa = np.array(li)
plt.cla()
# plt.plot(aa[:,0])
# plt.plot(aa[:,1])
plt.plot(aa[:,2]*1000)
plt.plot(aa[:,3])
plt.pause(0.0001)
# plt.axis([0, 10, 0, 1])
# for i in range(10):
# y = np.random.random()
# plt.scatter(i, y)
# plt.pause(0.05)
if __name__ == '__main__':
test()

View File

@ -1,20 +1,12 @@
import socket
from time import sleep
def send_message(message: str, host='11.6.1.53', port=29999):
# Create a TCP/IP socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect to the server
client_socket.connect((host, port))
try:
# Send the message
client_socket.sendall(message.encode())
print(f"Sent: {message}")
finally:
# Close the socket
client_socket.close()