Package: darli
DARLi: Differentiable Articulated Robotics LibraryThe DARLi (Differentiable Articulated Robotics Library) is a wrapper around the CasADi kinematics/dynamics and Pinocchio libraries. Its primary goal is to facilitate the creation of differentiable models for robotic systems, provided a URDF (Unified Robot Description Format) file.DARLi is not an implementation of mechanics-orientedalgorithms, such as Featherstone's Articulated Body or the Recursive Newton-Euler. Instead, we rely on the efficient implementations provided byPinocchioand offer a wrapper that grants easy access to a suite of features that we and our colleagues have found useful in practice of trajectory planning, feedback control, and system identification over poly-articulated robots.Features of DARLi:Different Backends: Currently, DARLi supports the numerical Pinocchio backend and its CasADi wrapper, based on amodified versionofcasadi_kin_dyn(will be replaced withPinocchio 3upon its release). We are also planning to support JAX or PyTorch in the near future.Fully Differentiable Model: DARLi provides a fully differentiable model from just the URDF file. The interface is user-friendly, offering access to different body parts, adding contacts friction cones, input mappings, etc. We also provide pre-built configurations for bipeds, manipulators, humanoids, quadrupeds, and more.Continues and Discrete State Space: DARLi allows for manifold-aware integration, moving beyond simple Euler methods, and access to differentiable simulations (rollouts) for continuous and discrete state spaces. These features address practical control system concerns such as different control and integration rates. Together wit Auto-differentiation capabilities enable accurate high-order linearizations with respect to state and control inputs and even parameters.Parametric Models: Most model components and their state spaces can be built dependent on a set of dynamic parameters, accompanied by their linear parametrization (i.e., regressors). In DARLi, combined with the State Space capabilities, this opens the door for non-trivial robustness and sensitivity analysis and greatly facilitates system identification.Functional Wrapper: DARLi may provide access to various aspects of your model (mentioned above) as standalone CasADi functions. These functions can be called separately (or even code-generated) without the need to re-evaluate the entire model.InstallationTo install into existing environment run:pip3installdarliFor now the library is actively changing, so if you are one of contributors or want to keep track of recent changes without reinstalling use the develope mode:pip3install-e.In order to adddarlidependency to yourconda envlook intoexampleTroubleshooting:It may be the case that running the examples fails on the step of solvingcasadiproblem. In this case you have to extendLD_LIBRARY_PATHof your current environment.For conda users you can patch your environment by running the following command:wget-O-https://raw.githubusercontent.com/lvjonok/cmeel-conda-patch/master/patch.sh|bash-s<condaenvname>For pip users you have to manually extendLD_LIBRARY_PATHby running the following command:exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(python3-mcmeellib)Note, that in both cases you have to restart your kernel/session/vscode or whatever you use to run python code.Installation from sourceClone the repositorygitclonehttps://github.com/simeon-ned/darliInstall using pippip3install-e.You may install with [dev] option to installpre-commit. This library will ensure that your code is formatted the same way among all other developers:pip3install-e.[dev]pre-commitinstallUsageThe typical workflow as follows:Build the urdf of your robot and createRobotModelinstanceAdd additional bodies and possibly contactsCalculate the all necessary functions with~.update_model()methodAccess to casadi functions that are stored within RobotModel and use them either numerically or symbolically in other CasAdi empowered projects.There are also banch of modules that facilitates work with given type of robots, i.e. manipulators, quadrupeds and bipeds.The minimal example of using library:fromdarli.backendimportCasadiBackendfromdarli.modelingimportRobotimportnumpyasnpimportcasadiascsfromrobot_descriptionsimportz1_description# Initializing the RobotModel classmodel=Robot(CasadiBackend(z1_description.URDF_PATH))model.add_body({"end_effector":"link06"})# Dynamics calculationsinertia=model.inertiagravity_vector=model.gravitycoriolis=model.coriolis# calling with CasAdi argumentsgravity_vector(cs.SX.sym("q",model.nq))# calling with numpy argumentsgravity_vector(np.random.randn(model.nq))nq=model.nq# Body kinematicsmodel.body("end_effector").position# Differential kinematicsmodel.body("end_effector").angular_velocity.local# Adding contactsmodel.body("end_effector").add_contact("wrench")One may also use the prebuilded templates for some common robotics structures, i.e:fromdarli.robotsimportbiped# Example for the bipedal robot# foots are subject to wrench contactfromrobot_descriptionsimportatlas_v4_descriptionbiped_model=biped(Functional,CasadiBackend,atlas_v4_description.URDF_PATH,torso={"torso":"pelvis"},foots={"left_foot":"l_foot","right_foot":"r_foot",},)biped_model.forward_dynamicsbiped_model.body('torso').positionbiped_model.body('torso').linear_velocity.world_alignedbiped_model.body('left_foot').contactPlease refer to dedicated example in~/examples/01_models_and_robotsto learn other capabilities of the library