Solving
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 solving. 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 solving_example |
Python | link | run in the Jupyter Notebook |
Javascript | link | yarn build , yarn dev |
- Live
- Javascript
- Python
- Rust
Loading Example...
import { panda, ur3e } from './urdfs.js';
import { Solver } from '@people_and_robots/lively';
const initialRootBounds = [
// An exmaple of root bounds
{ value: 0.0, delta: 0.0 },
{ value: 0.25, delta: 0.0 },
{ value: 0.5, delta: 0.0 },
{ value: 0.0, delta: 0.0 },
{ value: 0.0, delta: 0.0 },
{ value: 0.0, delta: 0.0 },
];
const initialObjectives = {
// some objective examples. Notice for JavaScript, you do not need to import anything for objective. Simply construct an object
smoothness: {
name: 'MySmoothnessObjective',
type: 'SmoothnessMacro',
weight: 20,
joints: true,
origin: false,
links: true,
},
position: {
name: 'MyPositionMatchObjective',
type: 'PositionMatch',
link: 'panda_hand',
weight: 15,
},
orientation: {
name: 'MyOrientationMatchObjective',
type: 'OrientationMatch',
link: 'panda_hand',
weight: 10,
},
collision: {
name: 'MyCollisionDetection',
type: 'CollisionAvoidance',
weight: 3,
},
jointLimit: {
name: 'MyJointLimit',
type: 'JointLimits',
weight: 5,
},
jointMatch: {
name: 'MyJointMatchFinger1',
type: 'JointMatch',
weight: 5,
joint: 'panda_finger_joint1',
},
};
const initialEnvShapes = [
{
type: 'Cylinder', // The Cylinder here is an example of static environmental shape. This shape will be not able to be moved or deleted.
name: 'pill',
frame: 'world',
physical: true,
length: 0.3,
radius: 0.2,
localTransform: {
translation: [-0.8, 0.0, 0.1],
rotation: [1.0, 0.0, 0.0, 0.0],
}, // [x, y, z, w] ordering for quaternion
},
];
const collision_settings = {
// This is an example of customized collision_settings
dMax: 0.1,
r: 0.0,
aMax: 2.0,
timeBudget: 100,
timed: false,
};
const newSolver = new Solver(
panda,
initialObjectives,
initialRootBounds,
initialEnvShapes,
null,
null,
null,
collision_settings
);
newSolver.computeAverageDistanceTable();
const d = new Date();
let time = d.getTime(); // Get the time used in Math.sin
let goal = {
// An goal example with defined Translation and Rotation
position: {
Translation: [
0.0,
0.5,
Math.sin(time / 1000) / 5 + 0.5, // The sin function alternating between -1 and 1 to have the robot to swing back and forth along the z-axis
],
},
orientation: {
Rotation: [0.0, 0.707, 0.0, 0.0], // A defined Rotation to make the gripper facing downward
},
jointMatch: {
Scalar: 0.02,
},
};
const newState = newSolver.solve(goal, {}, time / 1000);
document.querySelector('#app').innerHTML = `
<div>
${JSON.stringify(newState)}
</div>`;
console.log(newState);
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 objective (smoothness macro)
"smoothness":SmoothnessMacroObjective(name="MySmoothnessObjective",weight=5)
}
)
# 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;
use std::fs;
fn main() {
let mut objectives: HashMap<String, Objective> = HashMap::new();
// Add a Smoothness Macro Objective
objectives.insert(
"smoothness".into(),
// An example objective (smoothness macro)
Objective::SmoothnessMacro(SmoothnessMacroObjective::new("MySmoothnessObjective".to_string(), 5.0, true,false,false))
);
let data = fs::read_to_string("./tests/basic.xml").expect("Something went wrong reading the file");
let mut solver = Solver::new(
data.clone(), // Full urdf as a string
objectives, //objectives
None, //root_bounds
None, //shapes
None, //initial_state
None, //max_retries
None, //max_iterations
None); //collision_settings
// Run solve to get a solved state
let state = solver.solve(
HashMap::new(), // empty goals hashmap
HashMap::new(), // empty weights hashmap
0.0, // time
None //shape_update
);
// Log the initial state
println!("{:?}",state);
}