Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ The script uses input JSON files that define what robot to load and what templat
Cricket uses [inja](https://github.com/pantor/inja) to template code generation.
The configuration file specifies:
- The name of the robot
- Path of the URDF and SRDF relative (or absolute) to the configuration file. Note that this robot must only have spheres for collision geometry.
- Path of the URDF and SRDF relative (or absolute) to the configuration file. Note that this robot's collision geometry must be spheres, or spheres and boxes (see [Cuboids](#cuboids)).
- The end-effector to use for attachments
- Collision checking resolution
- Output template and sub-templates to use
Expand Down Expand Up @@ -195,6 +195,10 @@ In addition to the specified input fields from the configuration file, the scrip
- `joint_names`: name of joint corresponding to each DoF.
- `link_names`: name of frame corresponding to index.
- `per_link_spheres`: for each frame, the indices of the spheres associated with that frame.
- `n_cuboids`: number of collision cuboids (boxes); 0 for a sphere-only robot.
- `per_link_cuboids`: for each frame, the indices of the cuboids associated with that frame.
- `n_bounding_spheres`, `cuboid_buffer_offset`: number of per-link bounding spheres, and the offset of the first cuboid in the traced buffer (see [Cuboids](#cuboids)).
- `cuboidfk_code`, `cuboidfk_code_vars`, `cuboidfk_code_output`: as `spherefk_code`, for the cuboids only. Only present when `n_cuboids > 0`.
- `links_with_geometry`: indices of the frames that have collision geometry.
- `bounding_sphere_index`: mapping between frame index to bounding sphere index (where bounding spheres are at the end of the sphere buffer, after `n_spheres`).
- `end_effector_collisions`: for each end-effector, which frames it can collide with.
Expand All @@ -206,3 +210,13 @@ In addition to the specified input fields from the configuration file, the scrip
- `spherefk_code`, `spherefk_code_vars`, `spherefk_code_output`: C-style code for computing position of all spheres, the number of intermediate variables used, and the number of output variables.
- `ccfk_code`, `ccfk_code_vars`, `ccfk_code_output`: C-style code for computing position of all spheres and bounding spheres for collision checking, the number of intermediate variables used, and the number of output variables.
- `ccfkee_code`, `ccfkee_code_vars`, `ccfkee_code_output`: C-style code for computing position of all spheres and bounding spheres for collision checking as well as the position and quaternion for the end-effector, the number of intermediate variables used, and the number of output variables.

## Cuboids

In addition to spheres, a robot's collision geometry may include boxes (`<box size="..."/>` in the URDF's `<collision>` elements), so a link can be a cuboid instead of being covered by many spheres. Other shapes are still an error, and a robot needs at least one sphere.

- **Bounding spheres** still gate every link. A link's bounding sphere is the smallest sphere containing its spheres *and* the circumscribed spheres of its boxes, so it stays conservative.
- **Traced buffer layout** is `[spheres | bounding spheres | cuboids | end-effector pose]`. Spheres and bounding spheres use 4 floats each, and cuboids use 15 (center, three unit axes, half-lengths), in the argument order of `vamp::collision::OrientedBox`. Cuboids come after the bounding spheres so a robot without cuboids has exactly the layout (and generated code) it had before.
- **Generated code** uses `cuboid_environment_in_collision` (environment), `sphere_cuboid_self_collision` and `cuboid_cuboid_self_collision` (self-collision), and `attachment_cuboid_collision` (attached objects), all from VAMP. Robots expose `n_cuboids`, and when it is nonzero, `Cuboids<rake>` and `cuboid_fk`. In `fkcc_debug`, the per-geometry results list the spheres, then the cuboids, and indices in colliding pairs that are `>= n_spheres` refer to cuboid `index - n_spheres`.
- **Limitations:** cuboids are only generated for C++ (not Rust), and VAMP does not support them against pointcloud (CAPT) environments.

17 changes: 16 additions & 1 deletion include/cricket/codegen.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,26 @@ namespace cricket
std::size_t outputs;
};

/// Number of floats traced per cuboid: center (3), three axes (9), half-lengths (3), in the argument
/// order of vamp::collision::OrientedBox.
inline constexpr std::size_t cuboid_stride = 15;

/// Traces the world-frame poses of the collision geometry.
///
/// The output buffer is laid out as [spheres | bounding spheres | cuboids | end-effector pose],
/// omitting any section whose flag is false (sections after an omitted one shift down). Spheres and
/// bounding spheres take 4 floats each (x, y, z, r), cuboids `cuboid_stride`, and the end-effector
/// pose 12 (translation, then the rotation matrix in column-major order).
///
/// Putting cuboids after the bounding spheres means offsets of everything before them are the same
/// as for a robot without cuboids.
auto trace_sphere_cc_fk(
const RobotInfo &info,
const std::string &language,
bool spheres = true,
bool bounding_spheres = true,
bool fk = true) -> Traced;
bool fk = true,
bool cuboids = false) -> Traced;

/// Traces the end-effector pose together with its Jacobian.
///
Expand Down Expand Up @@ -174,6 +188,7 @@ namespace cricket
std::string robot_name;
std::size_t dimension = 0;
std::size_t n_spheres = 0;
std::size_t n_cuboids = 0;
};

auto generate_robot_source(const GenOptions &opts) -> GenResult;
Expand Down
21 changes: 21 additions & 0 deletions include/cricket/robot_info.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,30 @@ namespace cricket
{
struct SphereInfo
{
// Slot of this sphere in the traced sphere buffer. Spheres are numbered contiguously in the
// order they appear in the collision model, independent of any cuboids interleaved with them.
std::size_t geom_index;
float radius;
std::size_t parent_joint;
std::size_t parent_frame;
pinocchio::SE3 relative;
};

// A box-shaped collision geometry, posed relative to its parent joint. The box is centered at the
// origin of `relative` with half-lengths `half_extents` along the axes of `relative`'s rotation.
struct CuboidInfo
{
// Slot of this cuboid in the traced cuboid buffer (contiguous, in collision-model order)
std::size_t index;
std::array<float, 3> half_extents;
std::size_t parent_joint;
std::size_t parent_frame;
pinocchio::SE3 relative;

// Radius of the smallest sphere, centered at the box center, that contains the box
auto bounding_radius() const -> float;
};

auto min_sphere_of_spheres(const std::vector<SphereInfo> &info) -> std::array<float, 4>;

// Optional explicit Cartesian bounds for FreeFlyer / Planar joints
Expand Down Expand Up @@ -78,6 +95,8 @@ namespace cricket

auto dof_to_joint_names() -> std::vector<std::string>;
auto get_frames_colliding_end_effector(std::size_t frame_index) -> std::vector<std::size_t>;
// Extracts the collision geometry. Spheres and boxes are supported; anything else is an error.
// (The name predates box support.)
auto extract_spheres() -> void;
auto collision_pair_to_frame_pair(const pinocchio::CollisionPair &cp)
-> std::pair<std::size_t, std::size_t>;
Expand Down Expand Up @@ -106,9 +125,11 @@ namespace cricket
float max_bounding_radius_mobile{std::numeric_limits<float>::min()};
std::array<float, 3> base_position{0.0F, 0.0F, 0.0F};
std::vector<SphereInfo> spheres;
std::vector<CuboidInfo> cuboids;
std::map<std::size_t, SphereInfo> bounding_spheres;
std::vector<std::size_t> links_with_geometry;
std::vector<std::vector<std::size_t>> per_link_spheres;
std::vector<std::vector<std::size_t>> per_link_cuboids;
std::set<std::pair<std::size_t, std::size_t>> allowed_link_pairs;
std::vector<std::size_t> bounding_sphere_index;
};
Expand Down
12 changes: 12 additions & 0 deletions resources/kmriiwa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Files downloaded from [stoic-roboticist/kmriiwa_ros_stack](https://github.com/stoic-roboticist/kmriiwa_ros_stack).

Various modifications were used to convert from the raw xacros to a model usable in drake, including:

- Disinfecting the files of as much ROS and Gazebo influence as possible.
- Cleaned up and simplified file paths.
- Compiling the `xacro` files to `urdf`.
- Converting meshes to `gltf` and `obj`.
- See `meshes/dae_to_gltf.sh`, `meshes/dae_to_obj.sh`, and `meshes/recursive_to_obj.sh`.
- The orientation of the `obj` files is incorrect, so we use `meshes/fix_orientation.py` to correct this.
- The material properties for meshes/kmp200.
- Removed unnecessary collision geometries (and simplified the base collision geometry).
30 changes: 30 additions & 0 deletions resources/kmriiwa/external/kmriiwa.srdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<!-- kmriiwa: link pairs (both with collision geometry) whose collisions
Drake filters: adjacent and welded bodies plus the models' and
directives' collision filter groups. Every other pair is checked.
tests/test_external_models.py checks it against the Drake model. -->
<robot name="kmriiwa">
<disable_collisions link1="kmr_base/kmriiwa_base_link" link2="iiwa/iiwa_link_0" reason="filtered" />
<disable_collisions link1="kmr_base/kmriiwa_base_link" link2="iiwa/iiwa_link_1" reason="sphere_overlap" />
<disable_collisions link1="iiwa/iiwa_link_0" link2="iiwa/iiwa_link_1" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_0" link2="iiwa/iiwa_link_2" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_0" link2="iiwa/iiwa_link_3" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_1" link2="iiwa/iiwa_link_2" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_1" link2="iiwa/iiwa_link_3" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_2" link2="iiwa/iiwa_link_3" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_3" link2="iiwa/iiwa_link_4" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_3" link2="iiwa/iiwa_link_5" reason="sphere_overlap" />
<disable_collisions link1="iiwa/iiwa_link_4" link2="iiwa/iiwa_link_5" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_5" link2="wsg/body" reason="sphere_overlap" />
<disable_collisions link1="iiwa/iiwa_link_4" link2="iiwa/iiwa_link_6" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_4" link2="iiwa/iiwa_link_7" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_5" link2="iiwa/iiwa_link_6" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_5" link2="iiwa/iiwa_link_7" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_6" link2="iiwa/iiwa_link_7" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_7" link2="wsg/body" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_7" link2="wsg/left_finger" reason="filtered" />
<disable_collisions link1="iiwa/iiwa_link_7" link2="wsg/right_finger" reason="filtered" />
<disable_collisions link1="wsg/body" link2="wsg/left_finger" reason="filtered" />
<disable_collisions link1="wsg/body" link2="wsg/right_finger" reason="filtered" />
<disable_collisions link1="wsg/left_finger" link2="wsg/right_finger" reason="filtered" />
</robot>
Loading
Loading