Last active
February 19, 2025 18:56
-
-
Save lizTheDeveloper/cbbf18ceab47cca5c7a0c9126bcdb4b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VAR socketdev server_socket; | |
VAR socketdev client_socket; | |
VAR jointtarget joint_data; | |
VAR string joint_data_str; | |
VAR num send_status; | |
PROC main() | |
! Create and bind server socket | |
SocketCreate server_socket; | |
SocketBind server_socket, "127.0.0.1", 5000; | |
SocketListen server_socket; | |
WHILE TRUE DO | |
! Accept a connection (store accepted socket in client_socket) | |
SocketAccept server_socket, client_socket; | |
WHILE TRUE DO | |
! Read current robot joint positions | |
joint_data := CJointT(); ! Correct function | |
! Format joint data as CSV string | |
joint_data_str := | |
NumToStr(joint_data.robax.rax_1, 3) + "," + | |
NumToStr(joint_data.robax.rax_2, 3) + "," + | |
NumToStr(joint_data.robax.rax_3, 3) + "," + | |
NumToStr(joint_data.robax.rax_4, 3) + "," + | |
NumToStr(joint_data.robax.rax_5, 3) + "," + | |
NumToStr(joint_data.robax.rax_6, 3); | |
! Send joint data over socket | |
send_status := SocketSend(client_socket, joint_data_str); | |
! Check if send failed (client disconnected) | |
IF send_status <> 1 THEN | |
EXIT; ! Break out of loop if sending failed | |
ENDIF | |
! Wait before sending next update | |
WaitTime 0.1; ! Adjust logging frequency (10Hz) | |
ENDFOR | |
! Close the client socket when disconnected | |
SocketClose client_socket; | |
ENDWHILE | |
ENDPROC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment