Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement joint torque control device and friction estimation through PINN #866

Merged
merged 17 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ All notable changes to this project are documented in this file.
- Add launch parameter to `blf-logger-with-audio.sh` script to set logger launch file (https://github.com/ami-iit/bipedal-locomotion-framework/pull/867)
- Add `getJointLimits` function to set get actuated joints position limits (https://github.com/ami-iit/bipedal-locomotion-framework/pull/868)
- Add the possibility to disable streaming of joint encoder acceleration measurements (https://github.com/ami-iit/bipedal-locomotion-framework/pull/876)
- Implement joint torque control device and friction estimation through PINN (https://github.com/ami-iit/bipedal-locomotion-framework/pull/866)

### Changed
- 🤖 [ergoCubSN001] Add logging of the wrist and fix the name of the waist imu (https://github.com/ami-iit/bipedal-locomotion-framework/pull/810)
Expand All @@ -42,6 +43,7 @@ All notable changes to this project are documented in this file.
- Fix `YARPRobotLoggerDevice` excessively long time horizon for signals logged with `YARP_CLOCK` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/839)
- Fix crash in `robot_control.set_references()` if the passed vector is not the correct size (https://github.com/ami-iit/bipedal-locomotion-framework/pull/852)
- Fix `VectorsCollectionClient.read_data(False)` to provide `collection` as output and avoid segmentation fault (https://github.com/ami-iit/bipedal-locomotion-framework/pull/850)
- Fix `YARPRobotLoggerDevice` logging of vectors and text (https://github.com/ami-iit/bipedal-locomotion-framework/pull/869)

### Removed

Expand Down
1 change: 1 addition & 0 deletions cmake/AddBipedalLocomotionYARPDevice.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ function(add_bipedal_yarp_device)
endif()

endfunction()

1 change: 1 addition & 0 deletions cmake/BipedalLocomotionDependencyClassifier.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ function(dependency_classifier package)
endif()

endfunction()

4 changes: 4 additions & 0 deletions cmake/BipedalLocomotionFrameworkDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ framework_dependent_option(FRAMEWORK_COMPILE_YarpRobotLoggerDevice
"Do you want to generate and compile the YarpRobotLoggerDevice?" ON
"FRAMEWORK_COMPILE_RobotInterface;FRAMEWORK_COMPILE_YarpImplementation;FRAMEWORK_COMPILE_Perception;FRAMEWORK_COMPILE_YarpUtilities;FRAMEWORK_USE_robometry" OFF)

framework_dependent_option(FRAMEWORK_COMPILE_JointTorqueControlDevice
"Do you want to generate and compile the YarpRobotLoggerDevice?" ON
"FRAMEWORK_COMPILE_YarpImplementation;FRAMEWORK_COMPILE_YarpUtilities;FRAMEWORK_USE_onnxruntime" OFF)

framework_dependent_option(FRAMEWORK_COMPILE_VectorsCollectionWrapper
"Do you want to generate and compile the VectorsCollectionWrapper?" ON
"FRAMEWORK_COMPILE_YarpImplementation;FRAMEWORK_COMPILE_YarpUtilities" OFF)
Expand Down
1 change: 1 addition & 0 deletions cmake/BipedalLocomotionFrameworkFindDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ macro(FRAMEWORK_DEPENDENT_OPTION _option _doc _default _deps _force)
endif()

endmacro()

1 change: 1 addition & 0 deletions devices/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# BSD-3-Clause license.

add_subdirectory(FloatingBaseEstimatorDevice)
add_subdirectory(JointTorqueControlDevice)
add_subdirectory(RobotDynamicsEstimatorDevice)
add_subdirectory(YarpRobotLoggerDevice)
add_subdirectory(VectorsCollectionWrapper)
Expand Down
34 changes: 34 additions & 0 deletions devices/JointTorqueControlDevice/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved.
# This software may be modified and distributed under the terms of the
# BSD-3-Clause license.

if(FRAMEWORK_COMPILE_JointTorqueControlDevice)
add_bipedal_locomotion_yarp_thrift(
NAME JointTorqueControlCommands
THRIFT thrifts/JointTorqueControlCommands.thrift
INSTALLATION_FOLDER JointTorqueControlDevice)

add_bipedal_yarp_device(
NAME JointTorqueControlDevice
TYPE BipedalLocomotion::JointTorqueControlDevice
SOURCES src/JointTorqueControlDevice.cpp
src/PassThroughControlBoard.cpp
src/PINNFrictionEstimator.cpp
PUBLIC_HEADERS include/BipedalLocomotion/JointTorqueControlDevice.h
include/BipedalLocomotion/PassThroughControlBoard.h
include/BipedalLocomotion/PINNFrictionEstimator.h
PRIVATE_LINK_LIBRARIES
BipedalLocomotion::YarpUtilities
BipedalLocomotion::SystemYarpImplementation
BipedalLocomotion::RobotInterfaceYarpImplementation
BipedalLocomotion::ParametersHandlerYarpImplementation
BipedalLocomotion::VectorsCollection
BipedalLocomotion::JointTorqueControlCommands
PUBLIC_LINK_LIBRARIES
onnxruntime::onnxruntime
Eigen3::Eigen
${YARP_LIBRARIES}
${iDynTree_LIBRARIES}
CONFIGURE_PACKAGE_NAME joint_torque_control_device)
endif()

46 changes: 46 additions & 0 deletions devices/JointTorqueControlDevice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# JointTorqueControlDevice

The **JointTorqueControlDevice** is a YARP device to run joint torque control and generate motor current set-points.

## :running: How to use the device

### Run the device on a fake robot

The `example` folder contains a simple example on how to run the `JointTorqueControlDevice` to hijack an existing control board device.
The `jtcvcExample.xml` launches four devices:
* `original_controlboard` of type `fakeMotionControlboard`, the original controlboard
* `original_nws_yarp` of type `controlBoard_nws_yarp`, the network wrapper server to expose `original_controlboard` on YARP ports (for example to access it via yarpmotorgui)
* `hijacked_controlboard` of type `JointTorqueControlDevice`, the controlboard wrapped by `JointTorqueControlDevice` to implement the `ITorqueControl` methods on the top of `ICurrentControl`
* `hijacked_nws_yarp` of type `controlBoard_nws_yarp`, the network wrapper server to expose `hijacked_controlboard` on YARP ports (for example to access it via yarpmotorgui)

This permit to show how the hijacking works. First of all, open three terminals in the `example` directory.

In one, launch the `jtcvcExample.xml` :
~~~
yarprobotinterface --config ./jtcvcExample.xml
~~~

In another, launch the `yarpmotorgui` to monitor the state of `original_controlboard` :
~~~
yarpmotorgui --from ./yarpmotorgui.ini
~~~

In the third, launch the `yarpmotorgui` to monitor the state of `hijacked_controlboard` :
~~~
yarpmotorgui --from ./yarpmotorgui_hijacked.ini
~~~

If everything started correctly, if on the `hijacked_controlboard` `yarpmotorgui` you change a joint controlmode to torque, you should see that on `original_controlboard`'s `yarpmotorgui` the same joint will switch to current control mode. If you change the desired torque, you should see also the measured current change.

### Run the device on the real robot

To run the device on a robot make sure to define the configuration files for the robot in the `app/robots` folder.

- **ergoCubSN001**

- Launch `yarprobotinterface` on the robot.
- launch `JointTorqueControlDevice`
```
YARP_ROBOT_NAME=ergoCubSN001 yarprobotinterface --config launch-joint-torque-control.xml
```

11 changes: 11 additions & 0 deletions devices/JointTorqueControlDevice/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved.
# This software may be modified and distributed under the terms of the
# BSD-3-Clause license.

# Get list of models
subdirlist(subdirs ${CMAKE_CURRENT_SOURCE_DIR}/robots/)
# Install each model
foreach (dir ${subdirs})
yarp_install(DIRECTORY robots/${dir} DESTINATION ${YARP_ROBOTS_INSTALL_DIR})
endforeach ()

77 changes: 77 additions & 0 deletions devices/JointTorqueControlDevice/example/jtcvcExample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!-- Copyright (C) 2019-2021 Istituto Italiano di Tecnologia (IIT). All rights reserved.
This software may be modified and distributed under the terms of the
BSD-3-Clause license. -->

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE robot PUBLIC "-//YARP//DTD yarprobotinterface 3.0//EN" "http://www.yarp.it/DTD/yarprobotinterfaceV3.0.dtd">

<robot name="jtcvc_example">

<!-- Simulated controlboard -->
<!-- On a real robot, it should be something like embObjMotionControl -->
<device name="original_controlboard" type="fakeMotionControl">
<group name="GENERAL">
<param name="Joints">3</param>
<param name="AxisName">"joint0" "joint1" "joint2"</param>
</group>
</device>

<!-- Expose original controlboard on YARP network under the name /jtcvc_example/original -->
<device xmlns:xi="http://www.w3.org/2001/XInclude" name="original_nws_yarp" type="controlBoard_nws_yarp">
<param name="period"> 0.002 </param>
<param name="name"> /jtcvc_example/original </param>
<action phase="startup" level="10" type="attach">
<param name="device"> original_controlboard </param>
</action>
<action phase="shutdown" level="15" type="detach" />
</device>

<!-- Controlboard hijacked by JointTorqueControlDevice -->
<!---->
<device name="hijacked_controlboard" type="JointTorqueControlDevice">
<group name="TORQUE_CURRENT_PARAMS">
<param name="kt">( 0.142674 -0.158045 0.132443 )</param>
<param name="kfc">( 0.5 0.5 0.5 )</param>
<param name="kp">( 0.0 0.0 0.0 )</param>
<param name="max_curr">( 2.0 2.0 2.0 )</param>
<param name="friction_model"> ("FRICTION_COULOMB_VISCOUS", "FRICTION_COULOMB_VISCOUS". "FRICTION_COULOMB_VISCOUS") </param>
</group>

<group name="FRICTION_COULOMB_VISCOUS">
<param name="kv">( 0.000457 0.000458 0.000980 )</param>
<param name="kc">( 0.0 0.0 0.0 )</param>
<param name="ka">( 0.0 0.0 0.0 )</param>
</group>

<group name="FRICTION_COULOMB_VISCOUS_STRIBECK">
<param name="kv">( 0.000457 0.000458 0.000980 )</param>
<param name="kc">( 0.0 0.0 0.0 )</param>
<param name="ks">( 0.000457 0.000458 0.000980 )</param>
<param name="ka">( 0.0 0.0 0.0 )</param>
<param name="vs">( 0.000457 0.000458 0.000980 )</param>
</group>

<!-- Warning, still in milliseconds -->
<param name="period"> 2 </param>

<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<elem name="original_controlboard"> original_controlboard </elem>
</paramlist>
</action>

<action phase="shutdown" level="20" type="detach" />
</device>

<!-- Expose the controlboard hijacked by jointTorqueCurrentControlViaCurrent on YARP network under the name /jtcvc_example/hijacked -->
<device xmlns:xi="http://www.w3.org/2001/XInclude" name="hijacked_nws_yarp" type="controlBoard_nws_yarp">
<param name="period"> 0.002 </param>
<param name="name"> /jtcvc_example/hijacked </param>
<action phase="startup" level="10" type="attach">
<param name="device"> hijacked_controlboard </param>
</action>
<action phase="shutdown" level="15" type="detach" />
</device>

</robot>

2 changes: 2 additions & 0 deletions devices/JointTorqueControlDevice/example/yarpmotorgui.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
names ("/jtcvc_example/original")

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
names ("/jtcvc_example/hijacked")

Loading
Loading