Adding Liveliness
note
Since Lively is still in beta, the design is subject to change and should not be considered final!
We have also created examples in Javascript, Python, and Rust for liveliness. You can find the file by clicking the links in the table down below.
Language | Path | Command to run the example |
---|---|---|
Rust | link | cargo run --package lively --example liveliness_example |
Python | link | run in the Jupyter Notebook |
Javascript | link | yarn build , yarn dev |
- Live
- Javascript
- Python
- Rust
Loading Example...
import init, { Solver } from "lively";
async function start() {
// Initialize the lively package (WASM)
await init();
// Instantiate a new solver
let solver = new Solver(
"<?xml version='1.0' ?><robot name='panda'>...</robot>", // Full urdf as a string
{
smoothness: {
// An example objective (smoothness macro)
name: "MySmoothnessObjective",
type: "SmoothnessMacro",
weight: 5,
},
position: {
name: "MyPositionObjective",
type: "PositionMatch",
weight: 15,
link: 'panda_hand'
},
positionLively: {
name: "MyLivelinessObjective",
type: "PositionLiveliness",
weight: 15,
link: "panda_hand",
frequency: 7,
},
orientationLively: {
name: "MyOrientationObjective",
type: "OrientationLiveliness",
weight: 15,
link: "panda_link2",
frequency: 7,
},
}
);
// Run solve to get a solved state
let state = solver.solve({}, {}, 0.0);
// Log the initial state
console.log(state);
}
// Could be executed from anywhere that supports async actions
start();
from lively import Solver, SmoothnessMacroObjective
# Instantiate a new solver
solver = Solver(
urdf='<?xml version="1.0" ?><robot name="panda">...</robot>', # Full urdf as a string
objectives={
# An example smoothness macro objective
"smoothness":SmoothnessMacroObjective(name="MySmoothnessObjective",weight=5),
# An example position liveliness objective
"positionLiveliness": PositionLiveliness(name="MyLivelinessObjective",link="panda_hand",frequency=7,weight=25),
# An example orientation liveliness objective
"orientationLiveliness": OrientationLiveliness(name="myOrientationLiveliness",link="panda_link2",frequency=7,weight=15)
}
)
# Run solve to get a solved state
state = solver.solve({},{},0.0)
# Log the initial state
print(state)
use lively::lively::Solver;
use lively::objectives::core::base::SmoothnessMacroObjective;
use lively::objectives::objective::Objective;
use std::collections::HashMap;
// Create a map of objectives
let mut objectives: HashMap<String,Objective> = HashMap::new();
// Add a Smoothness Macro Objective
objectives.insert("smoothness".into(),Objective::SmoothnessMacro(SmoothnessMacroObjective::new("MySmoothnessObjective",5.0)));
// Add a positionLiveliness Objective
objectives.insert(("positionLiveliness".into(),Objective::PositionLiveliness(PositionLiveliness::new("MyLivelinessObjective",25,"panda_hand",7))));
// Add a orientationLiveliness Objective
objectives.insert(("orientationLiveliness".into(),Objective::OrientationLiveliness(OrientationLiveliness::new("MyOrientationlinessObjective",15,"panda_link2",7))));
// Instantiate a new solver struct
let mut solver = Solver::new(
urdf:'<?xml version="1.0" ?><robot name="panda">...</robot>', // Full urdf as a string
objectives
);
// Run solve to get a solved state
let state = solver.solve(
HashMap::new(),
HashMap::new(),
0.0,
None
);
// Log the initial state
println!("{:?}",state);