FCI activation and Brake release - Programaitcally
Opened this issue ยท 8 comments
Hi,
I am working on a Franka Emika Panda robot. The robot is mounted on a Clearpath Ridgeback. My first experience with robot is successful as I am able to run the robot with franka_ros
package i.e.
roslaunch franka_control franka_control.launch robot_ip:=192.168.1.2 load_gripper:=true
For this above command to run without errors I have to first release the brakes of the arm and activate FCI, ofcourse both from Desk. Now what I want to do is to launch the arm control software at the startup of the robot using robot_upstart package.
So my question is there any way to release the brakes and actiavte FCI without accessing the desk so that the robot control nodes can run at startup of the robot?
What we and a few other projects have been doing is to run a small python script that sends the unlock command to the franka webserver.
My version is this
import httpx
import json
import sys
import rospy
USERNAME = "your-username"
ENCODED_PASSWORD = "your_encoded_password"
rospy.init_node("unlock_arm")
ip = rospy.get_param("~robot_ip", "192.168.10.10")
client = httpx.Client(verify=False, base_url=f"https://{ip}")
client.headers.update({
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-language": "en-US,en;q=0.9",
"sec-ch-ua": "\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Linux\"",
"upgrade-insecure-requests": "1"
})
res = client.get(url="/admin/login")
res = client.get(url="/admin/api/first-start", headers={"content-type": "application/json"})
res = client.get(url="/admin/api/startup-phase", headers={"content-type": "application/json"})
login_body = {"login": USERNAME,
"password": ENCODED_PASSWORD}
res = client.post(url="/admin/api/login", headers={"content-type": "application/json"}, content=json.dumps(login_body), )
if res.status_code == 200:
print("Successfully logged in to robot")
else:
print("Logging in to robot hand failed. Exiting.")
sys.exit(1)
auth_cookie = res.text
client.headers.update({'Authorization': auth_cookie})
res = client.get(url="/admin/api/safety", headers={"content-type": "application/json"})
res = client.post(url="/admin/api/control-token/request", headers={"content-type": "application/json"}, json={"requestedBy": USERNAME})
auth_token = res.json()['token']
client.headers.update({'X-Control-Token': auth_token})
res = client.get(url="/admin/api/robot/shutdown-position-error")
res = client.post(url="/desk/api/robot/open-brakes", data={"force": "false"}, timeout=20)
if res.status_code == 200:
print("Successfully deactivated robot hand lock")
else:
print("Failed to deactivate robot hand lock")
sys.exit(2)
res = client.post(url="/admin/api/control-token/fci", json={'token': auth_token})
if res.status_code == 200:
print("Successfully activated fci")
else:
print("Failed to activate fci")
sys.exit(3)
the encoded password looks something like MTY5LDE2MSwyMiw0MiwxODIsMTE2LD
but longer. just use the network tab to get it. I also saw one project to do the sha256 encrypting in the python script, just like the franka frontend, but I didn't bother.
Hopefully this workaround wont be needed in the future.
@KingBoomie I used the above script, I am able to log in and close brakes but had a problem acquiring X-control-token to open brakes and activate FCI. with the script, The X-control token I get is not allowing to open brakes and activate FCI
I manually copied the x-control-token from the web interface network option it works. but when the system restarts this does not work anymore. I need to copy the token manually again.
Have you tried recently with system version 4.2.1?
Thanks
@rajDFL Yes, we too updated to 4.2.1 a few months ago and it seems to be working still.
Oh, it seems I forgot to change one part of the script above when making it generic for all usernames. I updated it now.
(the line res = client.post(url="/admin/api/control-token/request", headers={"content-type": "application/json"}, json={"requestedBy": USERNAME})
still had our robot username)
@KingBoomie I'm currently running 4.2.1 and am unable to find the encoded password. Do you have any advice to locate it or implement the sha256 encryption?
Thanks.
Thanks to the script shared by @KingBoomie, my colleague Bruno Lima and I developed a new script (franka_activate.py) that delivers the following enhancements:
- A deactivation procedure (via HTTP requests) is added, which deactivates FCI, activates the brakes and logs out from Desk, so that a new session can be started cleanly;
- The script captures termination signals. When the ROS node is shut down, or the process is killed by a termination signal, the script calls the deactivation routine described at point 1;
- For security reasons, the script decrypts the encoded password; this assumes that the password is encrypted in an external file. If you find it more comfortable, you can hard-code the password in the script, without calling the
gpg -d
command to decrypt it. Please be aware that hard-coding the password in the script allows any user reading the script to take control of Franka via Desk or HTTP requests.
Lastly, we created a similar script (franka_shutdown.py) to shut down the robot (i.e. removes the currents at the motors).
@jackmcnamarauq We followed these steps:
- Open Desk with your web browser;
- Open the developer tools;
- Select the
Network
tab; - Click the "settings" button (top-right of the opened
Network
tab) and selectPersist Logs
- Log in using your credentials
- Check out the latest
POST
HTTP request. You should find the encoded password in the request's body itself.
Feel free to check out https://github.com/jk-ethz/franka-lock-unlock for a package that solves this issue.