Solving
The Solver class has a solve method that represents the core functionality of the Lively interface. At a high level, it returns a fully-filled state object and accepts the following fields:
The optional field can be left empty if the no specification is needed. The Solver will just use the default values for the optional parameters.
| Field | Type | Optional | Description | 
|---|---|---|---|
goals | look-up table of goal indexed by a string key | no | The key of the look-up table should match with that of the objectives to which the goals are corresponded. | 
weights | look-up table of float value indexed by a string key | no | The key of the look-up table should match with that of the objectives to which the weights are corresponded. | 
time | float | no | The current time stamp. It is advised to always pass in a increasing time stamp for the solver to have a more consistent behavior. | 
shape_update | list of ShapeUpdate objects | yes | see below | 
Shape Update
The shape_update parameter in solve takes in a list of ShapeUpdate objects specifying the environmental shapes to be introduced, modified, and removed.
The ShapeUpdate object allows for three functionalities or types: Add, Move, and Delete each corresponding to the tasks mentioned above. For more information please see the example below.
The shape objects passed in the shapes parameter in solver initialization are static and can not be moved or deleted later. Only the shapes that are introduced (Add) to the environment in ShapeUpdate can be moved or deleted by Move and delete.
Example for adding a new environmental shape
When a new shape is introduced to the environment, the id associated with the new shape needs to be unique.
The id will be used to identify the shape when a Move or Delete is performed on the same shape.
If another shape is added to the environment with the same id, the new shape will replace the old shape with the same id.
- Javascript
 - Python
 - Rust
 
const addCube = [
  Add: {
    // This is an Add ShapeUpdate functionality or type. This introduce a new Cube with "env-box" as the id to the environment.
    id: "env-box", // must be an unique id
    shape: {
      type: "Box", //can be 'Cylinder', 'Capsule', or 'Sphere'
      name: "box", // name can be arbitrary
      frame: "world", // frame name
      physical: true, // physical collision
      x: 0.25,
      y: 0.25,
      z: 0.25, // dimension of the box
      localTransform: {
        translation: [0.6, 0.05, 0.15],
        rotation: [0.0, 0.0, 0.0, 1.0],
      },
    },
  },
];
const d = new Date();
let time = d.getTime(); // Get the time in milliseconds
currentSolver.solve({}, {}, time / 1000, addCube);
add_box = BoxShape(name="Table",frame="world",physical=True,x=2,y=1,z=1.2,local_transform=Transform.isometry())
# This is an Add ShapeUpdate functionality or type. This introduce a new Cube with "box_1" as the id to the environment.
shape_update = [pyShapeUpdate.Add(id = "box_1", shape = add_box)]
# pass the shape_update to shape_update parameter
currentSolver.solve(shape_update = shape_update)
  let iso = Isometry3::from_parts( //declaring transform consisted of translation and rotation
      Translation3::new(
          0.6, 0.05, 0.15
      ),
      UnitQuaternion::from_quaternion(Quaternion::new(
          0.0, 0.0, 0.0, 1.0
      )),
  );
  let add_box = Shape::Box(BoxShape::new(//can be 'Cylinder', 'Capsule', or 'Sphere'
      "conveyorCollisionShapeBase".to_string(),// name can be arbitrary
      "world".to_string(),// frame name
      true, // physical collision
      1.0,
      1.1,
      1.7,
      iso, // transform
  ));
  let shape_update: Vec<ShapeUpdate> = vec![
      // This is an Add ShapeUpdate functionality or type. This introduce a new Cube with "box_1" as the id to the environment.
      ShapeUpdate::Add {
          id: box_1.to_string(),// must be an unique id
          shape: add_box.clone(),
      }
  ];
  solver.solve(
      goals.clone(),
      weights.clone(),
      0.0,
      Some(shape_update.clone()), //shape update
      None,
    );
Example for moving an existing environmental shape
If a wrong id is used, the solver will not change the transformation of any shape.
- Javascript
 - Python
 - Rust
 
const moveCube = [
  Move: {
    // This is a Move ShapeUpdate functionality or type. This modifies the transform of the Cube introduced by Add in the environment
    id: "env-box", // must be identical to the id created in the shape is added
    transform: {// the shape will be moved to this transformation
      translation: [1.6, 1.05, 1.15],
      rotation: [0.0, 1.0, 0.0, 1.0],
    },
  },
];
const d = new Date();
let time = d.getTime(); // Get the time in milliseconds
currentSolver.solve({}, {}, time / 1000, moveCube);
# This is a Move ShapeUpdate functionality or type. This move the Cube with "box_1" as the id in the environment.
shape_update = [pyShapeUpdate.Move(id =  "box_1", pose = local_transform(translation = [1.6, 1.05, 1.15],
rotation = [0.0, 1.0, 0.0, 1.0]))]
# pass the shape_update to shape_update parameter
currentSolver.solve(shape_update = shape_update)
let move_iso = Isometry3::from_parts( //declaring transform consisted of translation and rotation
    Translation3::new(
        1.6, 1.05, 1.15
    ),
    UnitQuaternion::from_quaternion(Quaternion::new(
        0.0, 1.0, 0.0, 1.0
    )),
);
let shape_update: Vec<ShapeUpdate> = vec![
    // This is an move ShapeUpdate functionality or type. This moves the Cube with "box_1" as the id to the environment.
    ShapeUpdate::Move {
        id: box_1.to_string(),// must be an unique id
        pose: move_iso.to_string()
    }
];
solver.solve(
    goals.clone(),
    weights.clone(),
    0.0,
    Some(shape_update.clone()), //shape update
    None,
  );
Example for deleting an existing environmental shape
If a wrong id is used, the solver will not delete any shape.
- Javascript
 - Python
 - Rust
 
const deleteCube = [Delete: "env-box"];// This is a delete ShapeUpdate functionality or type. This deletes the Cube introduced by Add in the environment.
const d = new Date();
let time = d.getTime(); // Get the time in milliseconds
currentSolver.solve({}, {}, time / 1000, deleteCube);
# This is a Delete ShapeUpdate functionality or type. This delete the Cube with "box_1" as the id from the environment.
shape_update = [pyShapeUpdate.Delete(id =  "box_1", pose = local_transform(translation = [1.6, 1.05, 1.15],
rotation = [0.0, 1.0, 0.0, 1.0]))]
# pass the shape_update to shape_update parameter
currentSolver.solve(shape_update = shape_update)
let shape_update: Vec<ShapeUpdate> = vec![
ShapeUpdate::Delete{// This is an delete ShapeUpdate functionality or type. This deletes the Cube with "box_1" as the id from the environment.
 id : "box_1".to_string(),
}];
solver.solve(
  goals.clone(),
  weights.clone(),
  0.0,
  Some(shape_update.clone()), //shape update
  None,
);