urcontrol/urosc/oscsend.py

42 lines
1.3 KiB
Python
Raw Normal View History

2024-05-10 08:33:02 +00:00
from helpfunctions import *
class OSCSend:
from pythonosc import udp_client
def __init__(self,_frequency_oscsend=50):
self.oscreceivers = []
self.frequency_oscsend=_frequency_oscsend
self.last_sendosc=0
def setupReceivers(self,serverips,port):
self.oscreceivers = []
# Set up OSC client
for cip in serverips:
print("connecting to "+str(cip))
connection = self.udp_client.SimpleUDPClient(cip, port)
self.oscreceivers.append(connection)
2024-05-10 15:18:08 +00:00
def sendMessage(self,address,value):
for c in self.oscreceivers:
c.send_message(address,value)
2024-05-10 08:33:02 +00:00
2024-05-10 15:18:08 +00:00
def send(self,looptime,q,tcp):
2024-05-10 08:33:02 +00:00
2024-05-10 15:18:08 +00:00
if looptime-self.last_sendosc<1.0/self.frequency_oscsend:
2024-05-10 08:33:02 +00:00
return
self.last_sendosc=looptime
2024-05-10 15:18:08 +00:00
2024-05-10 08:33:02 +00:00
for c in self.oscreceivers:
2024-05-10 15:18:08 +00:00
joint_deg=[toDeg(x) for x in q]
c.send_message("/j",joint_deg)
rx,ry,rz=RPYtoVec(tcp[3],tcp[4],tcp[5])
tcp_deg=[tcp[0],tcp[1],tcp[2],toDeg(rx),toDeg(ry),toDeg(rz)]
#tcp_deg=[tcp[0],tcp[1],tcp[2],toDeg(tcp[3]),toDeg(tcp[4]),toDeg(tcp[5])]
c.send_message("/tcp", tcp_deg)