Last August I started working on a new version of my old control repo with a resolve to make something less hacky, as part of the work for Applied Brain Research, Inc, a startup that I co-founded with others from my lab after most of my cohort graduated. Together with Pawel Jaworski, who comprises other half of ABR’s motor team, we’ve been building up a library of useful functions for modeling, simulating, interfacing, and controlling robot arms.
Today we’re making the repository public, under the same free for non-commercial use that we’ve released our Nengo neural modelling software on. You can find it here: ABR_Control
It’s all Python 3, and here’s an overview of some of the features:
- Automates generation of functions for computing the Jacobians, joint space and task space inertia matrices, centrifugal and Coriolis effects, and Jacobian derivative, provided each link’s inertia matrix and the transformation matrices
- Option to compile these functions to speedy Cython implementations
- Operational space, joint space, floating, and sliding controllers provided with PyGame and VREP example scripts
- Obstacle avoidance and dynamics adaptation add-ons with PyGame example scripts
- Interfaces with VREP
- Configuration files for one, two, and three link arms, as well as the UR5 and Jaco2 arms in VREP
- Provides Python simulations of two and three link arms, with PyGame visualization
- Path planning using first and second order filtering of the target and example scripts.
The ABR Control library is divided into three sections:
- Arm descriptions (and simulations)
- Robotic system interfaces
The big goal was to make all of these interchangeable, so that to run any permutation of them you just have to change which arm / interface / controller you’re importing.
To support a new arm, the user only needs to create a configuration file specifying the transforms and inertia matrices. Code for calculating the necessary functions of the arm will be symbolically derived using SymPy, and compiled to C using Cython for efficient run-time execution.
send_target_angles functions, to apply torques and put the arm in a target state, as well as a
get_feedback function, which returns a dictionary of information about the current state of the arm (joint angles and velocities at a minimum).
Controllers provide a
generate function, which take in current system state information and a target, and return a set of joint torques to apply to the robot arm.
The easiest way to show it is with some code examples. So, once you’ve cloned and installed the repo, you can open up VREP and the jaco2.ttt model in the
abr_control/arms/jaco2 folder, and to control it using an operational space controller you would run the following:
import numpy as np from abr_control.arms import jaco2 as arm from abr_control.controllers import OSC from abr_control.interfaces import VREP # initialize our robot config for the ur5 robot_config = arm.Config(use_cython=True, hand_attached=True) # instantiate controller ctrlr = OSC(robot_config, kp=200, vmax=0.5) # create our VREP interface interface = VREP(robot_config, dt=.001) interface.connect() target_xyz = np.array([0.2, 0.2, 0.2]) # set the target object's position in VREP interface.set_xyz(name='target', xyz=target_xyz) count = 0.0 while count < 1500: # run for 1.5 simulated seconds # get joint angle and velocity feedback feedback = interface.get_feedback() # calculate the control signal u = ctrlr.generate( q=feedback['q'], dq=feedback['dq'], target_pos=target_xyz) # send forces into VREP, step the sim forward interface.send_forces(u) count += 1 interface.disconnect()
This is a minimal example of the
examples/VREP/reaching.py code. To run it with a different arm, you can just change the
from abr_control.arms import as line. The repo comes with the configuration files for the
UR5 and a
onelink VREP arm model as well.
I’ve also found the PyGame simulations of the 2 and 3 link arms very helpful for quickly testing new controllers and code, as an easy low overhead proof of concept sandbox. To run the
threelink arm (which runs in Linux and Windows fine but I’ve heard has issues in Mac OS), with the operational space controller, you can run this script:
import numpy as np from abr_control.arms import threelink as arm from abr_control.interfaces import PyGame from abr_control.controllers import OSC # initialize our robot config robot_config = arm.Config(use_cython=True) # create our arm simulation arm_sim = arm.ArmSim(robot_config) # create an operational space controller ctrlr = OSC(robot_config, kp=300, vmax=100, use_dJ=False, use_C=True) def on_click(self, mouse_x, mouse_y): self.target = self.mouse_x self.target = self.mouse_y # create our interface interface = PyGame(robot_config, arm_sim, dt=.001, on_click=on_click) interface.connect() # create a target feedback = interface.get_feedback() target_xyz = robot_config.Tx('EE', feedback['q']) interface.set_target(target_xyz) try: while 1: # get arm feedback feedback = interface.get_feedback() hand_xyz = robot_config.Tx('EE', feedback['q']) # generate an operational space control signal u = ctrlr.generate( q=feedback['q'], dq=feedback['dq'], target_pos=target_xyz) new_target = interface.get_mousexy() if new_target is not None: target_xyz[0:2] = new_target interface.set_target(target_xyz) # apply the control signal, step the sim forward interface.send_forces(u) finally: # stop and reset the simulation interface.disconnect()
The extra bits of code just set up a hook so that when you click on the PyGame display somewhere the target moves to that point.
So! Hopefully some people find this useful for their research! It should be as easy to set up as cloning the repo, installing the requirements and running the setup file, and then trying out the examples.
If you find a bug please file an issue! If you find a way to improve it please do so and make a PR! And if you’d like to use anything in the repo commercially, please contact me.