Skip to content

Commit 0a1c92d

Browse files
committed
Add README
Signed-off-by: methylDragon <[email protected]>
1 parent 63315d7 commit 0a1c92d

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

moveit_ros/trajectory_cache/README.md

+130
Original file line numberDiff line numberDiff line change
@@ -1 +1,131 @@
11
# Trajectory Cache
2+
3+
```
4+
* This cache does NOT support collision detection!
5+
* Plans will be put into and fetched from the cache IGNORING collision.
6+
* If your planning scene is expected to change between cache lookups, do NOT
7+
* use this cache, fetched plans are likely to result in collision then.
8+
*
9+
* To handle collisions this class will need to hash the planning scene world
10+
* msg (after zeroing out std_msgs/Header timestamps and sequences) and do an
11+
* appropriate lookup, or otherwise find a way to determine that a planning scene
12+
* is "less than" or "in range of" another (e.g. checking that every obstacle/mesh
13+
* exists within the other scene's). (very out of scope)
14+
```
15+
16+
A trajectory cache based on [`warehouse_ros`](https://github.com/moveit/warehouse_ros) for the move_group planning interface that supports fuzzy lookup for `MotionPlanRequest` and `GetCartesianPath` requests and trajectories.
17+
18+
The cache allows you to insert trajectories and fetch keyed fuzzily on the following:
19+
20+
- Starting robot (joint) state
21+
- Planning request constraints
22+
- This includes ALL joint, position, and orientation constraints!
23+
- And also workspace parameters, and some others.
24+
- Planning request goal parameters
25+
26+
It works generically for an arbitrary number of joints, across any number of move_groups.
27+
28+
Furthermore, the strictness of the fuzzy lookup can be configured for start and goal conditions.
29+
30+
## Citations
31+
32+
If you use this package in your work, please cite it using the following:
33+
34+
```
35+
@software{ong_2024_11215428,
36+
author = {Ong, Brandon},
37+
title = {A Fuzzy-Matching Trajectory Cache for MoveIt 2},
38+
month = may,
39+
year = 2024,
40+
publisher = {GitHub},
41+
version = {0.1.0},
42+
doi = {10.5281/zenodo.11215428},
43+
url = {https://doi.org/10.5281/zenodo.11215428}
44+
}
45+
```
46+
47+
## Example usage
48+
49+
```cpp
50+
// Be sure to set some relevant ROS parameters:
51+
// Relevant ROS Parameters:
52+
// - `warehouse_plugin`: What database to use
53+
// - `warehouse_host`: Where the database should be created
54+
// - `warehouse_port`: The port used for the database
55+
auto traj_cache = std::make_shared<TrajectoryCache>(node);
56+
57+
auto fetched_trajectory = traj_cache->fetch_best_matching_trajectory(
58+
*move_group_interface, robot_name, motion_plan_req_msg,
59+
_cache_start_match_tolerance, _cache_goal_match_tolerance, /*sort_by=*/"execution_time_s");
60+
61+
if (fetched_trajectory) {
62+
// Great! We got a cache hit
63+
// Do something with the plan.
64+
} else {
65+
// Plan... And put it for posterity!
66+
traj_cache->put_trajectory(
67+
*interface, robot_name, std::move(plan_req_msg), std::move(res->result.trajectory),
68+
rclcpp::Duration(
69+
res->result.trajectory.joint_trajectory.points.back().time_from_start
70+
).seconds(),
71+
res->result.planning_time, /*overwrite=*/true)
72+
}
73+
```
74+
75+
It also has the following optimizations:
76+
- Separate caches for separate move groups
77+
- The cache does "canonicalization" of the poses to be relative to the planning frame to increase the chances of cache hits.
78+
- Configurable fuzzy lookup for the keys above.
79+
- It supports "overwriting" of worse trajectories with better trajectories
80+
- If a trajectory with keys extremely close to a pre-existing cache entry is inserted with a better planned execution time, the cache can delete all "worse" trajectories.
81+
- #IsThisMachineLearning
82+
- It also prunes the database and mitigates a lot of query slow-down as the cache grows
83+
84+
## Working Principle
85+
86+
If a plan request has start, goal, and constraint conditions that are "close enough" (configurable per request) to an entry in the cache, then the cached trajectory should be suitable (as long as obstacles have not changed).
87+
88+
Goal fuzziness is a lot less lenient than start fuzziness by default.
89+
90+
Finally, the databases are sharded by move group, and the constraints are added as columns in a name agnostic fashion (they are even somewhat robust to ordering, because they're sorted!)
91+
92+
## Benefits
93+
94+
A trajectory cache helps:
95+
- Cut down on planning time (especially for known moves)
96+
- Allows for consistent predictable behavior of used together with a stochastic planner
97+
- It effectively allows you to "freeze" a move
98+
99+
A user may also choose when to leverage the cache (e.g. when planning moves from a static "home" position, or repetitive/cartesian moves) to get these benefits.
100+
101+
Additionally, because the cache class has the ability to sort by planned execution time, over sufficient runs, the stochastic plans eventually converge to better and better plans (execution time wise).
102+
103+
You may build abstractions on top of the class, for example, to expose the following behaviors:
104+
- `TrainingOverwrite`: Always plan, and write to cache, deleting all worse trajectories for "matching" cache keys
105+
- `TrainingAppendOnly`: Always plan, and always add to the cache.
106+
- `ExecuteBestEffort`: Rely on cache wherever possible, but plan otherwise.
107+
- `ExecuteReadOnly`: Only execute if cache hit occurred.
108+
109+
You can see how such behaviors effectively model the "dev" and "deploy" phases of a robot deployment, and how they could be useful.
110+
111+
## Best Practices
112+
113+
- Since this cache does not yet support collisions, ensure the planning scene and obstacles remain static
114+
- Have looser start fuzziness, and stricter goal fuzziness
115+
- Move the robot to static known poses where possible before planning to increase the chances of a cache hit
116+
- Use the cache where repetitive, non-dynamic motion is likely to occur (e.g. known plans, short planned moves, etc.)
117+
118+
## WARNING: The following are unsupported / RFE
119+
120+
Since this is an initial release, the following features are unsupported because they were a little too difficult for the time I had to implement this. So I am leaving it to the community to help!
121+
122+
- **!!! This cache does NOT support collision detection!**
123+
- Trajectories will be put into and fetched from the cache IGNORING collision.
124+
- If your planning scene is expected to change between cache lookups, do NOT use this cache, fetched trajectories are likely to result in collision then.
125+
- To handle collisions this class will need to hash the planning scene world msg (after zeroing out std_msgs/Header timestamps and sequences) and do an appropriate lookup, or do more complicated checks to see if the scene world is "close enough" or is a less obstructed version of the scene in the cache entry.
126+
- !!! This cache does NOT support keying on joint velocities and efforts.
127+
- The cache only keys on joint positions.
128+
- !!! This cache does NOT support multi-DOF joints.
129+
- !!! This cache does NOT support certain constraints
130+
- Including: path, constraint regions, everything related to collision.
131+
- The fuzzy lookup can't be configured on a per-joint basis.

0 commit comments

Comments
 (0)