Repository for:
Gian Maria Marconi*, Raffaello Camoriano*, Lorenzo Rosasco, and Carlo Ciliberto, "Structured Prediction for CRiSP Inverse Kinematics Learning with Misspecified Robot Models", IEEE Robotics and Automation Letters (RA-L) and IEEE International Conference on Robotics and Automation (ICRA) 2021 (to appear); Pre-print: https://arxiv.org/abs/2102.12942
Abstract
With the recent advances in machine learning, problems that traditionally would require accurate modeling to be solved analytically can now be successfully approached with data-driven strategies. Among these, computing the inverse kinematics of a redundant robot arm poses a significant challenge due to the non-linear structure of the robot, the hard joint constraints and the non-invertible kinematics map. Moreover, most learning algorithms consider a completely data-driven approach, while often useful information on the structure of the robot is available and should be positively exploited. In this work, we present a simple, yet effective, approach for learning the inverse kinematics. We introduce a structured prediction algorithm that combines a data-driven strategy with the model provided by a forward kinematics function -- even when this function is inaccurate -- to efficiently tackle the problem. The proposed approach ensures that predicted joint configurations are well within the robot's constraints. We also provide statistical guarantees on the generalization properties of our estimator as well as an empirical evaluation of its performance on trajectory reconstruction tasks.
Tested on Ubuntu 18.04 and 20.04
We recommend using Anaconda for managing your environments
$ wget https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh
$ chmod +x Anaconda3-2020.07-Linux-x86_64.sh
$ ./Anaconda3-2020.07-Linux-x86_64.sh
Note: Specify a custom directory for Anaconda with enough disk space.
To install the Anaconda environment for this project, run in the shell
$ conda env create -f environment.yml
activate it with
$ conda activate CRiSP-ik
and verify it is correctly installed
$ conda env list
Included in this repo there are two sample scripts for experiments on the PANDA robot or on the planar manipulator. Both scripts read a configuration file (two samples of which are in the corresponding folder) and perform the experiment accordingly.
To launch the script, change directory to experiments_scripts
and use:
- Planar maniputator:
$ python planar_manipulator_demo.py -config path/to/config.ini
- Panda maniputator:
$ python panda_demo.py -config path/to/config.ini
Where config.ini
is a configuration file defining the experiment details.
Reproducing the Panda arm experiments requires 9.8GB of RAM for storing the full kernel matrix.
For convenience, we also provide a CRiSP-precomputed predicted trajectory in experiments_scripts/outputs/panda_medium_cube/results_CRiSP.npz
and a script for rendering the result in PyBullet
in experiments_scripts/render_panda_results.py
.
To render the predicted trajectory, change directory to experiments_scripts
and run:
$ python render_panda_results.py
The configuration file is in plaintext and has 4 sections:
- [Experiment] Contains some generic infors on the experiment
- [Trajectory] Specifies information on the trajectory parameters
- [Data] Paths to datasets, pre-trained models, outputs etc.
- [Alg Params] Parameters of the chosen algorithm/model
Boolean entries can be defined with either 0/no/false
or 1/yes/true
.
Parameters
reps
: The number of repetitions for the base experiment. This parameters is overwritten by the number of hyperparameters in grid_search modeseed
: The random seed for the experimentgpu
: The numerical Id of the GPU for deep learning based algorithms. If not present, defaults to CPUalgorithm
: Selected algorithm:- CRiSP (structured approach)
- OCSSVM (One class SVM)
- NN (Neural Network)
biad_cm
: The amount of bias in cm in every link of the robot (random sign)bias_deg
: The amount of bias in degrees in every joint of the robot (random sign)train
: if absent, the user must specify a pre-trained model in[Data]
.reconstruct_trajectory
: test on trajectory reconstruction (otherwise the mnodel is just trained)
log_filename
: Path to a log file where the scripts outputs informationsoutput_folder
: folder where the scripts saves the results of the experiments
plot_dataset
: ifyes
, plots the generated dataset inoutput_folder
make_gif
: makes a gif of the reconstructed trajectory
type
: Type: eithereight
orcircle
center_x
: x coordinate of the center of the trajectory in the workspacecenter_y
: y coordinate of the center of the trajectory in the workspacepoints
: number of points in the trajectoryscale
: a scale factor for the trajetory size. 1 is unscaled.
generate_dataset
: isno
, the script expects the path indataset
dataset
: path to.pickle
datasetsmodel
: model to load, ignored ittrain
isyes
compute_distance_statistics
: ifyes
, the script computes some statistics on the training data inter-distances; can be slow for larger datasetslocal
: ifyes
, the dataset is generated locally to the test Trajectorymax_dist
: how far from the trajectory is the neighbourhood of the dataset whenlocal
istrue
preprocess
: ifyes
applies a preprocessing function to the training set
loss_structure
: Type of loss:- Forward: cartesian loss using the forward Kinematics
- Radians: angular loss on the joints
name
: name with which the model will be saved inoutput_folder
s
: sigma of the Gaussian kernelv
: regularization parameters_search
: a list of sigma values to evaluate the CRiSP on all combinations of s and vv_search
: a list of lambda values to evaluate the CRiSP on all combinations of s and v
s
: sigma of the Gaussian kernelv
: regularization parameters_search
: a list of sigma values to evaluate the CRiSP on all combinations of s and vv_search
: a list of lambda values to evaluate the CRiSP on all combinations of s and v
max_epochs
: number of epochs for training the NNlr
: learning rate of Adam optimizer