Skip to content

Commit

Permalink
Added alarm group query and the ability to remotely restart the beagl…
Browse files Browse the repository at this point in the history
…ebone processes
  • Loading branch information
Bryce Bixler committed Aug 27, 2024
1 parent 6f357f2 commit 43ac5f1
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 7 deletions.
52 changes: 52 additions & 0 deletions socs/agents/hwp_gripper/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,36 @@ def alarm(self, session, params=None):
session.data['response'] = return_dict
return return_dict['result'], f"Success: {return_dict['result']}"

def alarm_group(self, session, params=None):
"""alarm_group()
**Task** - Queries the actuator controller alarm group
Notes:
Return one of five values depending on the controller alarm state
False: No alarm was detected
'B': Controller saved parameter issue
'C': Issue with position calibration
'D': Could not reach position within time limit
'E': General controller error
The most recent data collected is stored in session data in the
structure:
>>> response.session['response']
{'result': 'B',
'log': ["ALARM GROUP B detected"]}
"""
return_dict = self._run_client_func(
self.client.alarm_group, job='alarm_group', check_shutdown=False)

if return_dict['result'] is None:
return_dict['result'] = False

session.data['response'] = return_dict
return return_dict['result'], f"Success: {return_dict['result']}"


def reset(self, session, params=None):
"""reset()
**Task** - Resets the current active controller alarm
Expand Down Expand Up @@ -633,6 +663,26 @@ def cancel_shutdown(self, session, params=None):
self.shutdown_mode = False
return True, 'Cancelled shutdown mode'

def restart(self, session, params=None):
"""restart()
**Task** - Restarts the beaglebone processes and the socket connection
Notes:
The most recent data collected is stored in session data in the
structure:
>>> response.session['response']
{'result': True,
'log': ["Previous connection closed",
"Restart command response: Success",
"Control socket reconnected"]}
"""
return_dict = self._run_client_func(
self.client.restart, job='restart', check_shutdown=False)
session.data['response'] = return_dict
return return_dict['result'], f"Success: {return_dict['result']}"

def monitor_state(self, session, params=None):
"""monitor_state()
Expand Down Expand Up @@ -851,6 +901,7 @@ def main(args=None):
agent.register_task('home', gripper_agent.home)
agent.register_task('inp', gripper_agent.inp)
agent.register_task('alarm', gripper_agent.alarm)
agent.register_task('alarm_group', gripper_agent.alarm_group)
agent.register_task('reset', gripper_agent.reset)
agent.register_task('act', gripper_agent.act)
agent.register_task('is_cold', gripper_agent.is_cold)
Expand All @@ -859,6 +910,7 @@ def main(args=None):
agent.register_task('grip', gripper_agent.grip)
agent.register_task('ungrip', gripper_agent.ungrip)
agent.register_task('cancel_shutdown', gripper_agent.cancel_shutdown)
agent.register_task('restart', gripper_agent.restart)

runner.run(agent, auto_reconnect=True)

Expand Down
43 changes: 36 additions & 7 deletions socs/agents/hwp_gripper/drivers/gripper_client.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import pickle as pkl
import socket
import time


class GripperClient(object):
def __init__(self, ip, port):
self.ip = ip
self.port = port
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.connect((self.ip, self.port))

self.control_socket = self._init_connection(self.ip, self.port)
self.data = b''

def _init_connection(self, ip, port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, port))
return s

def power(self, state):
if not isinstance(state, bool):
return False
Expand Down Expand Up @@ -76,6 +80,9 @@ def emg(self, state, actuator=0):
def alarm(self):
return self.send_command('ALARM')

def alarm_group(self):
return self.send_command('ALARM_GROUP')

def reset(self):
return self.send_command('RESET')

Expand Down Expand Up @@ -105,12 +112,34 @@ def get_state(self):

def send_command(self, command):
if isinstance(command, str):
self.s.sendall(bytes(command, 'utf-8'))
self.control_socket.sendall(bytes(command, 'utf-8'))
elif isinstance(command, bytes):
self.s.sendall(command)
self.control_socket.sendall(command)

return pkl.loads(self.control_socket.recv(4096))

def restart(self):
log = []
try:
self.close()
log.append('Previous connection closed')
except:
log.append('Previous connection already closed')

_restart_socket = self._init_connection(self.ip, 5656)
_restart_socket.sendall(('reset\n').encode())
time.sleep(0.5)

resp = _restart_socket.recv(4096).decode().strip()
log.append(f'Restart command response: {resp}')
result = True if resp == 'Success' else False
_restart_socket.close()
time.sleep(10)

return pkl.loads(self.s.recv(4096))
self.control_socket = self._init_connection(self.ip, self.port)
log.append('Control socket reconnected')
return {'result': result, 'log': log}

def close(self):
"""Close socket connection"""
self.s.close()
self.control_socket.close()

0 comments on commit 43ac5f1

Please sign in to comment.