Basic Initialization
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 Basic Initialization. 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 basic_initialization_example |
Python | link | run in the Jupyter Notebook |
Javascript | link | yarn build , yarn dev |
- Live
- Javascript
- Python
- Rust
Loading Example...
import { panda } from "./urdfs.js";
import { Solver } from "@people_and_robots/lively";
const newSolver = new Solver(panda, {
smoothness: {
// An example objective (smoothness macro)
name: "MySmoothnessObjective",
type: "SmoothnessMacro",
weight: 5,
},
});
const newState = newSolver.solve({}, {}, 0.0);
document.querySelector("#app").innerHTML = `
<div>
${JSON.stringify(newState)}
</div>`;
console.log(newState);
from lively import Solver, SmoothnessMacroObjective
from lxml import etree
# Read the xml file into a string
xml_file = '../../tests/basic.xml'
tree = etree.parse(xml_file)
xml_string = etree.tostring(tree).decode()
#print(xml_string)
# Instantiate a new solver
solver = Solver(
urdf=xml_string, # Full urdf as a string
objectives={
# An example objective (smoothness macro)
"smoothness":SmoothnessMacroObjective(name="MySmoothnessObjective",weight=5,joints=True,origin=False,links=True)
}
)
# Run solve to get a solved state
state = solver.solve(goals = {}, weights = {}, time=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
}