Hello every one,
I have a sensor like (microswitch) and I want to read its status, if active or not through python program.
I connected this Sensor to the Digitaal input DI0 to the robot’s microcontroller.
I have wroted a python program, but when I run this program I get only one status, that the sensor inactive even when i click on it. it shows that it’s active on the touch pendant but in the Output of the python program I get only inactive status.
Can you help me please?
here is the microswitch
And here is my program:
####### Library importation:
from distutils.cmd import Command
from itertools import count
import socket
import time
robot_ip= “169.254.46.85”
robot_port= 30002
def check_sensor_status():
s= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((robot_ip, robot_port))
print("Connected to the robot controller")
while True:
command = b"get_digital_in(0)\n"
s.sendall(command)
response = s.recv(1024)
print("Received:", response)
if b"True" in response:
print("Sensor is active")
else:
print("Sensor is inactive.")
time.sleep(1)
except Exception as e:
print("Error:", e)
finally:
s.close()
if name ==“main”:
check_sensor_status()
data = s.recv(1024)
What Robot series and Polyscope version are you running on?
What is the received data? can you print out what data its receiving for debugging purposes? I feel like the socket connection is not established properly. How are is the microcontroller is connected to the robot for exchanging data? ethernet cable?
Port 30002 does not respond to a query. It reports a fixed message that includes many things including the status of the inputs. However, you would need to write a program to decipher the message.
I recommend you read an article Remote Operation Guide attached to this website Remote operation of robots
RTDE might be a better interface for what you are trying to achieve.