Currently I’m working on the project, where robot always works remotely. If there is an error case (for example when robot bumps into something), I’ll need to set robot in freedrive mode. Which is available only in local control. Is there possibility to switch local and remote control modes without touching teaching pendant? For example if I add a switch button, if I write a command for it, etc.
Hope description is enough.
Thanks in advance.
Giorgi
Enabling freedrive with digital input should be possible, but robot must still be in local control. So, I want to make a environment, where switching between local and remote control will be possible without touching teaching pendant.
Hello Giorgi, As efn mentioned, be aware of the safety related risks! That being said, hope the below guide will be an answer to what you want to achieve.
You must establish connections to two separate interfaces simultaneously. Firstly, connect to the Dashboard to assess the ‘safetymode’. If it’s in a protective stop, you will need to issue ‘unlock protective stop’ command followed by a ‘play’ command to resume the .urp program.
For enabling the freedrive mode, you could use something like ‘set_configurable_digital_input_action(0, ‘freedrive’)’. This will set the digital input DI[0] to trigger freedrive mode when it receives a high signal.
On the hardware side, you can use an interlock to connect the digital output DO[0] with the digital input DI[0]. This setup ensures that DI[0] receives a high signal whenever DO[0] is high.
On the program side, when the Dashboard’s safetymode indicates ‘PROTECTIVE_STOP’, send a ‘set_digital_out(0, True)’ command.
The below script does what you want. Just tailor the main function logic to your needs.
Connect the DI with the interlock like https://www.fukaden.co.jp/car/interrock/#INT-BS-DC-M1 to get high when you send DO high command thus enabling the freedrive. Just the below script itself clears the protective stop when the robot enters it and turns off the DO[0]. Just make sure you start the python after setting the robot to remote control. beck.urp (1.3 KB)
#!/usr/bin/env python
# myDashClient.py
# Description: This script is a simple example of how to use the Real Time Client iand Dashboard nterface to send commands to the robot.
"""
# Author: i-beck
"""
__all__ = ['RemoteControl']
tcp_port = 30003
BUFFER_SIZE = 1108
tcp_ip = '10.2.4.109'
import socket
import time
import sys
class RemoteControl:
def __init__(self, host=tcp_ip, port=29999):
self.host = host
self.port = port
self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._connect()
def _connect(self):
attempts = 0
while attempts < 5:
try:
self.conn.connect((self.host, self.port))
sys.stdout.write('Socket opened...\n')
data = self.conn.recv(1024).decode('utf8')
break
except socket.error as e:
sys.stdout.write("Error connecting to {0}:{1}: {2}\n".format(self.host, self.port, e))
time.sleep(5)
attempts += 1
if attempts == 5:
sys.stdout.write("Failed to connect to {0}:{1}\n".format(self.host, self.port))
sys.exit(1)
def close(self):
self.conn.close()
def dashboard_command(self, cmd='is in remote control'):
try:
self.conn.send("{}\n".format(cmd).encode('utf-8'))
data = self.conn.recv(1024)
if data == b'Safetymode: PROTECTIVE_STOP\n':
return True
elif data != b'Safetymode: NORMAL\n':
return False
except socket.error as e:
sys.stdout.write("Error communicating with {0}:{1}: {2}\n".format(self.host, self.port, e))
time.sleep(5)
self._connect()
#return self.command(cmd) # retry if you want to make sure the last command was executed
class RealTimeClient:
def __init__(self, host=tcp_ip, port=30003):
self.host = host
self.port = port
self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._connect()
def _connect(self):
try:
self.conn.connect((self.host, self.port))
sys.stdout.write("Connected to Real Time Client on {0}:{1}\n".format(self.host, self.port))
except socket.error as e:
sys.stdout.write("Failed to connect to Real Time Client on {0}:{1}: {2}\n".format(self.host, self.port, e))
time.sleep(5)
self._connect() # Try to reconnect if connection failed
def matlab_command(self, matlab_cmd='set_digital_out(0,True)'):
try:
self.conn.send(("{}\n").format(matlab_cmd).encode('utf-8'))
except socket.error as e:
sys.stdout.write("Failed to send command to Real Time Client on {0}:{1}: {2}\n".format(self.host, self.port, e))
self._connect() # Try to reconnect and resend the command if it failed
def close(self):
self.conn.close()
def main(rc, rtc):
attempts = 0
while True:
try:
time.sleep(1)
if rc.dashboard_command("safetymode"):
# Set signal to visualize that the robot is in normal safety mode
rtc.matlab_command('sec beck():')
rtc.matlab_command('set_digital_out(0,False)') # You may want top use set_configurable_digital_input_action(0, "freedrive")
rtc.matlab_command('end')
time.sleep(0.008)
rc.dashboard_command("unlock protective stop")
time.sleep(2)
rc.dashboard_command("play")
else:
# Set signal to visualize that the robot is in protective stop
rtc.matlab_command('sec beck():')
rtc.matlab_command('set_digital_out(0,True)')
rtc.matlab_command('end')
sys.stdout.write("Robot is in normal safety mode")
if attempts == 0:
rc.dashboard_command("play")
time.sleep(1)
attempts += 1
except KeyboardInterrupt:
print("KeyboardInterrupt")
rc.close()
rtc.close() # Don't forget to close this connection too
sys.exit(0)
except socket.error as e:
print("Error communicating with {0}:{1}: {2}\n".format(rc.host, rc.port, e))
time.sleep(5)
rc._connect()
if __name__ == '__main__':
rc = RemoteControl()
rtc = RealTimeClient()
main(rc, rtc) # Pass the rtc instance to the main function