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

Refactor to use fr3 and panda #2

Draft
wants to merge 63 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
088e59a
wip implement read
Sep 9, 2022
cbe0618
proof of concept. Can use either FR3 or Panda with generate_cartesian…
Sep 9, 2022
9008233
make network generic over robot data
Nov 11, 2022
3cffb5f
gneric robot implementation
Nov 11, 2022
adecd1c
make model library generic
Dec 2, 2022
997c782
implement requestwithheaders for panda and fr3
Dec 21, 2022
6debb6f
fixup! implement requestwithheaders for panda and fr3
Dec 21, 2022
76c67da
rename state3 generic to state
Dec 21, 2022
024c4d4
finalize generic logger
Dec 21, 2022
fbcc69f
rename PandaState to RobotState and fix tcp_receive_response
Dec 22, 2022
a83cb4e
abstract over robots in generate_cartesian_pose_motion example
Apr 6, 2023
bb884bb
use robot wrapper to hide implementation details in Robot trait
Apr 6, 2023
0e5b830
make RobotModel trait usable and increase buffer size to download mod…
Apr 6, 2023
90623e1
make load_model work with RobotWrapper trait
Apr 21, 2023
ec9c6ec
remove unnecessary braces in rate_limiting.rs
Apr 21, 2023
e5ebea4
minor improvements
Apr 21, 2023
2450772
make all examples work again
Apr 21, 2023
fef13bb
make clippy happy
Apr 21, 2023
de81aec
delete some commented out code
Apr 21, 2023
1cb87b1
delete some commented out code
Apr 21, 2023
c959a1e
fix ConvertMotion, MotionFinished and spin_control
Apr 21, 2023
e9fe50a
fix ordering for implementations of RobotData
Apr 21, 2023
034daf9
delete commented out code and fix implementation order
Apr 21, 2023
f85f7e8
update badges
Apr 21, 2023
8d4df67
rename FR3 to Fr3
Apr 21, 2023
9decd36
move robot types to separtate files
Apr 21, 2023
59f6920
let clippy fix imports after refactoring
Apr 21, 2023
ad26582
extract device_data.rs and robot_data.rs
Apr 21, 2023
90b00f1
move robot_data.rs to robot folder
Apr 21, 2023
0817f78
rename robot.rs to robot_trait.rs to fix clippy warning
Apr 21, 2023
746f958
fix gripper tests
Apr 28, 2023
715d515
update documentation of model Module and avoid copy pasting code for …
May 5, 2023
d9b74fc
wip introduce PrivateRobotData trait
May 5, 2023
aca989c
remove Robot trait
May 5, 2023
8147d53
get rid of RobotData casts in control_loop.rs
May 5, 2023
3c4391a
remove GripperData type
May 5, 2023
2579680
make more traits and structs private
May 5, 2023
8087954
rename RobotWrapper trait to Robot
May 19, 2023
35bac93
rename robot_trait.rs to private_robot.rs
May 19, 2023
e05d4e9
fix intradoc links
May 19, 2023
47cf74e
disable rate-limiter by default for FR3
May 19, 2023
08d3fa8
support to models for different architectures on linux
May 19, 2023
95b9f29
fix commandline options for panda
Jul 14, 2023
9863d0c
make rate limiting generic
Oct 17, 2023
444b6b7
implement rate limiter directly in Fr3 and Panda struct
Oct 17, 2023
b020bcb
improve docs and rearrange method order
Oct 17, 2023
58c3256
update to nalgebra 0.32
Oct 17, 2023
5b9cf0e
update to clap 4
Oct 17, 2023
f0ddcb0
set version to 0.10.0 and update README.md
Oct 17, 2023
03af643
add code coverage
Oct 18, 2023
6155872
add code coverage badge to README.md
Oct 19, 2023
7c1d5ce
Add CHANGELOG.md
Oct 19, 2023
0a37e85
fix echo_robot_state example
Oct 20, 2023
a8aff53
Add function to get model file path and use it in the download_model …
Oct 20, 2023
23b114c
explicitly set codecov token in ci config
Oct 20, 2023
52f83c6
Improved error handling for grasp_object example
Oct 20, 2023
708b065
minor improvements to documentation
Oct 20, 2023
0c8b06b
add copyright to files
Oct 30, 2023
6f73d27
add more documentation and improve some module exports
Oct 30, 2023
c93aba8
Refactor `RobotModel` trait for unified modeling
Oct 30, 2023
e3f97f9
fix test
Oct 30, 2023
55eabc9
improve gripper imports
Oct 30, 2023
367c69d
fix formatting in lib.rs
Oct 30, 2023
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
8 changes: 8 additions & 0 deletions .github/actions-rs/grcov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/
source-dir: .
binary-path: ./target/debug/
output-type: lcov
branch: true
ignore-not-existing: true
llvm: true
output-path: ./lcov.info
34 changes: 32 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,35 @@ jobs:
run: cargo fmt -- --check
- name: Clippy
run: cargo clippy --all-features -- -D warnings
- name: Run tests
run: cargo test --all-features --verbose -- --test-threads=1
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- uses: actions-rs/cargo@v1
with:
command: clean
- uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --no-fail-fast --verbose -- --test-threads=1
env:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests -Cinstrument-coverage -Copt-level=0'
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests -Cinstrument-coverage -Copt-level=0'
- uses: actions-rs/grcov@0.2-proto
with:
args: >
-t lcov
--llvm
--ignore-not-existing
--ignore "/*"
-o ./target/lcov.info
./target/debug/
- name: Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
verbose: true
fail_ci_if_error: true
files: lcov.info
53 changes: 53 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Changelog

## [0.10.0] - Unreleased

This version supports Panda and Franka Research 3 robots.

Requires Franka Research 3 system version >= 5.2.0

Requires Panda system version >= 4.2.1

### Added

- Support for FR3 was added
- Most methods are now generic over the robot type, so they can work with FR3 and Panda robots
- Downloading of the robot model for other architectures
- New `RateLimiter` trait that is implemented by the `Panda` and `Fr3` structs
- The rate limiter for FR3 is using position based velocity limits
- Code coverage reports

### Changed

- The Robot struct became a trait that is implemented by the `Panda` and `Fr3` structs
- The Model struct became a trait that is implemented by the `RobotModel` struct
- Examples now default to FR3 unless `--panda` is passed as argument
- Rate limiter is disabled by default for FR3
- FR3 does not have get_virtual_wall and set_filters methods
- Updated `nalgebra` to version 0.32
- Updated `clap` to version 4

### Fixed

- Badges in README

## [0.9.0] - 2022-04-01

Requires Panda system version >= 4.2.1

### Added

- Add `O_ddP_O` base acceleration to robot state, hardcoded to `{0, 0, -9.81}`
- New `BaseAccelerationInitializationTimeout`, `BaseAccelerationInvalidReading`
`CartesianSplineViolation` and
`JointViaPlanLimitViolation` reflexes

### Changed

- `Model::gravity_from_state` uses `O_ddP_O` from the robot state

## [0.8.2-alpha-2] - 2021-06-18

Requires Panda system version >= 4.0.0

Initial release
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libfranka-rs"
version = "0.9.0"
version = "0.10.0"
authors = ["Marco Boneberger <m.boneberger@tu-bs.de>"]
edition = "2018"
license = "EUPL-1.2"
Expand Down Expand Up @@ -79,11 +79,11 @@ nix = "0.20.0"
mio = { version = "0.7", features = ["os-poll", "tcp", "udp"] }
num-derive = "0.3"
num-traits = "0.2"
nalgebra = "0.23"
nalgebra = "0.32"
thiserror = "1.0"
libloading = "0.7.0"

[dev-dependencies]
clap = { version = "3.1.7", features = ["derive"] }
clap = { version = "4", features = ["derive"] }
mockall = "0.9.1"
float_extras = "0.1.6"
96 changes: 64 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[![crates.io](https://img.shields.io/crates/v/libfranka-rs.svg)](https://crates.io/crates/libfranka-rs)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/marcbone/libfranka-rs/Rust)
[![crates.io](https://img.shields.io/crates/l/libfranka-rs.svg)](https://crates.io/crates/libfranka-rs)
[![crates.io](https://img.shields.io/crates/d/libfranka-rs.svg)](https://crates.io/crates/libfranka-rs)
[![docs.rs](https://docs.rs/libfranka-rs/badge.svg)](https://docs.rs/libfranka-rs)
[![Crates.io](https://img.shields.io/crates/v/libfranka-rs?style=flat-square)](https://crates.io/crates/libfranka-rs)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/marcbone/libfranka-rs/rust.yml?style=flat-square)](https://github.com/marcbone/libfranka-rs/actions)
[![Crates.io](https://img.shields.io/crates/l/libfranka-rs?style=flat-square)](https://github.com/marcbone/libfranka-rs/blob/master/LICENSE)
[![Crates.io](https://img.shields.io/crates/d/libfranka-rs?style=flat-square)](https://crates.io/crates/libfranka-rs)
[![docs.rs](https://img.shields.io/docsrs/libfranka-rs?style=flat-square)](https://docs.rs/libfranka-rs)
[![Codecov](https://img.shields.io/codecov/c/github/marcbone/libfranka-rs?style=flat-square)](https://codecov.io/gh/marcbone/libfranka-rs)

# libfranka-rs
libfranka-rs is an **unofficial** port of [libfranka](https://github.com/frankaemika/libfranka) written in Rust.
This library can interact with research versions of Franka Emika Robots.
This library can interact with research versions of Franka Emika Robots (Panda and FR3).
The library aims to provide researchers the possibility to experiment with Rust within a real-time robotics
application.

Expand All @@ -15,6 +17,7 @@ THE ROBOT!**
## Features
* Real-time control of the robot
* A libfranka-like API
* Generic over Panda and FR3
* Usage with Preempt_RT or stock Linux kernel
* Usage of the gripper
* Usage of the robot model
Expand All @@ -24,28 +27,54 @@ THE ROBOT!**
* Direct Conversions from [nalgebra](https://nalgebra.org/) (Eigen3 equivalent) types into libfranka control types (JointPositions, CartesianPose, ...)
* Proper error handling with Result types

TODO:
* Usage of the Model for anything else but Linux x86_64

Not supported:
* Windows (macOS could maybe work, but I have not tested it)
* Vacuum Grippers (we do not have those, so I cannot test them)

## Example
A small example for controlling joint positions. You can find more in the examples folder.
```rust
use franka::{FrankaResult, JointPositions, MotionFinished, Robot, RobotState};
```rust
use std::time::Duration;
use std::f64::consts::PI;
use franka::{JointPositions, MotionFinished, Robot, RobotState, Fr3, FrankaResult};
fn main() -> FrankaResult<()> {
let mut robot = Fr3::new("robotik-bs.de", None, None)?;
robot.set_default_behavior()?;
robot.set_collision_behavior([20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0], [20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0],
[20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0], [20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0],
[20.0, 20.0, 20.0, 25.0, 25.0, 25.0], [20.0, 20.0, 20.0, 25.0, 25.0, 25.0],
[20.0, 20.0, 20.0, 25.0, 25.0, 25.0], [20.0, 20.0, 20.0, 25.0, 25.0, 25.0])?;
let q_goal = [0., -PI / 4., 0., -3. * PI / 4., 0., PI / 2., PI / 4.];
robot.joint_motion(0.5, &q_goal)?;
let mut initial_position = JointPositions::new([0.0; 7]);
let mut time = 0.;
let callback = |state: &RobotState, time_step: &Duration| -> JointPositions {
time += time_step.as_secs_f64();
if time == 0. {
initial_position.q = state.q_d;
}
let mut out = JointPositions::new(initial_position.q);
let delta_angle = PI / 8. * (1. - f64::cos(PI / 2.5 * time));
out.q[3] += delta_angle;
out.q[4] += delta_angle;
out.q[6] += delta_angle;
if time >= 5.0 {
return out.motion_finished();
}
out
};
robot.control_joint_positions(callback, None, None, None)
}
```

It is also possible to write the example above in a generic way, so it can be used for FR3 or Panda:
```rust
use franka::{Fr3, FrankaResult, JointPositions, MotionFinished, Panda, Robot, RobotState};
use std::f64::consts::PI;
use std::time::Duration;
fn main() -> FrankaResult<()> {
let mut robot = Robot::new("robotik-bs.de", None, None)?;
robot.set_default_behavior()?;
println!("WARNING: This example will move the robot! Please make sure to have the user stop button at hand!");
println!("Press Enter to continue...");
std::io::stdin().read_line(&mut String::new()).unwrap();

// Set additional parameters always before the control loop, NEVER in the control loop!
// Set collision behavior.
fn generate_motion<R: Robot>(robot: &mut R) -> FrankaResult<()> {
robot.set_default_behavior()?;
robot.set_collision_behavior(
[20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0],
[20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0],
Expand All @@ -56,11 +85,9 @@ fn main() -> FrankaResult<()> {
[20.0, 20.0, 20.0, 25.0, 25.0, 25.0],
[20.0, 20.0, 20.0, 25.0, 25.0, 25.0],
)?;

let q_goal = [0., -PI / 4., 0., -3. * PI / 4., 0., PI / 2., PI / 4.];
robot.joint_motion(0.5, &q_goal)?;
println!("Finished moving to initial joint configuration.");
let mut initial_position = JointPositions::new([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
let mut initial_position = JointPositions::new([0.0; 7]);
let mut time = 0.;
let callback = |state: &RobotState, time_step: &Duration| -> JointPositions {
time += time_step.as_secs_f64();
Expand All @@ -73,25 +100,33 @@ fn main() -> FrankaResult<()> {
out.q[4] += delta_angle;
out.q[6] += delta_angle;
if time >= 5.0 {
println!("Finished motion, shutting down example");
return out.motion_finished();
}
out
};
robot.control_joint_positions(callback, None, None, None)
}
```
fn main() -> FrankaResult<()> {
let mut fr3 = Fr3::new("robotik-bs.de", None, None)?;
let mut panda = Panda::new("robotik-bs.de", None, None)?;
generate_motion(&mut fr3)?;
generate_motion(&mut panda)
}
```



## How to get started
As it is a straight port, you may find the

Since libfranka-rs is a port of libfranka, you may find the
[Franka Control Interface Documentation](https://frankaemika.github.io/docs/index.html) helpful.

### With zero Rust knowledge
If this is your first time using Rust, I recommend reading the [Rust Book](https://doc.rust-lang.org/stable/book/).

If you have Rust installed and just want to play with the examples, you can also run:
```bash
cargo install libfranka-rs --examples --version 0.9.0
cargo install libfranka-rs --examples --version 0.10.0
generate_joint_position_motion <ip_of_your_robot>
```

Expand All @@ -104,18 +139,15 @@ hoping that it makes your introduction into the Rust world as smooth as possible
### With zero libfranka knowledge
The [Franka Control Interface Documentation](https://frankaemika.github.io/docs/index.html) also includes a setup guide.
You can skip the installation of libfranka as you will be using libfranka-rs.
Take a look at the [Documentation](https://docs.rs/libfranka-rs) and the examples folder. You should run the
communication_test example to verify that your setup is correct.
Take a look at the [Documentation](https://docs.rs/libfranka-rs) and the [examples](examples) folder. You should run the
[communication_test](examples/communication_test.rs) example to verify that your setup is correct.

### How to use libfranka-rs
If you want to use libfranka-rs in your project, you have to add
```text
libfranka-rs = "0.9.0"
libfranka-rs = "0.10.0"
```
to your Cargo.toml file.
libfranka-rs version numbers are structured as MAJOR.MINOR.PATCH. The Major and Minor versions match the original libfranka
version numbers. That means for 0.8, your robot has to be at least on Firmware 4.0.0. Older firmware versions are not supported by
libfranka-rs. You can find more information about system updates [here](https://frankaemika.github.io).

## Licence
This library is copyrighted © 2021 Marco Boneberger
Expand Down
Loading
Loading