MOSS: a small, mostly 3D-printed litter-picking rover. Cleaner streets, one maker at a time.
Python
IMU contacts on by default: colour, depth and IMU seen alive together on the robot at a stationary launch (199 Hz, gravity on -y); MOSS_IMU=0 goes back to the camera without IMU
metrox9f36224f57ec
diff --git a/benches/bench_moss_blueprints_cold.py b/benches/bench_moss_blueprints_cold.pyindex e09e4b4..ca4be40 100644--- a/benches/bench_moss_blueprints_cold.py+++ b/benches/bench_moss_blueprints_cold.py@@ -444,7 +444,7 @@ check("MOSS_MPS_AT_LIMIT=0.30 read when the blueprint is built -> 0.30 m/s, rimnav = mb.build_moss_nav()n = names(nav)want = {"MossControlCoordinator", "GamepadTeleop", "RPLidarC1", "LidarOdometry",- "MossCostMap", "RealSenseCamera", "MossRecorder"}+ "MossCostMap", "MossRealSense", "BumpImu", "MossRecorder"} # the camera carries the IMU by defaultcheck("moss-nav modules", want <= n, f"{sorted(n)}")check("moss-nav has no planner, no explorer, no MovementManager, no viewer",not ({"RecoveringPlanner", "Explorer2", "MovementManager", "WebsocketVisModule"} & n))@@ -464,10 +464,10 @@ check("base: adapter 'moss' on the QT Py by-id", hw.adapter_type == "moss" and hcheck("pad: the same MOSS envelope as moss-gamepad", atom(nav, "GamepadTeleop").kwargs.get("envelope") == teleop_envelope(g))check("odometry without the gyro prior (MOSS_GYRO unset = off)", atom(nav, "LidarOdometry").kwargs.get("use_gyro_prior") is False)check("odometry without deskew (MOSS_DESKEW unset = off: on the rover the deskew thread fails)", atom(nav, "LidarOdometry").kwargs.get("deskew") is False)-cam = atom(nav, "RealSenseCamera").kwargs-check("RealSense 640x480 @ 5 fps, colour + depth (aligned), no point cloud, no IMU (MOSS_GYRO off by default)",+cam = atom(nav, "MossRealSense").kwargs+check("RealSense 640x480 @ 5 fps, colour + depth (aligned), no point cloud, the IMU in the camera's own process (MOSS_IMU on by default)",(cam.get("width"), cam.get("height"), cam.get("fps"), cam.get("enable_depth"),- cam.get("enable_pointcloud"), cam.get("enable_imu")) == (640, 480, 5, True, False, False))+ cam.get("enable_pointcloud"), cam.get("enable_imu")) == (640, 480, 5, True, False, True))t = cam["base_transform"]check("camera mount from the profile: (0.156, 0, 0.075) m",close(t.translation.x, 0.156) and close(t.translation.z, 0.075))@@ -489,8 +489,8 @@ check("wrist outputs remapped: color_image -> wrist_image, camera_info -> wrist_wspec = nav.transport_map.get(("wrist_image", Image))check("wrist_image crosses the bus as JPEG on /wrist_image",isinstance(wspec, TransportSpec) and wspec.cls is JpegLcmTransport and wspec.args[0] == "/wrist_image")-check("the RealSense keeps its own names (no remap on RealSenseCamera)",- not any(k[0] == "RealSenseCamera" for k in nav.remapping_map))+check("the RealSense keeps its own names (no remap on the camera module)",+ not any(k[0] in ("RealSenseCamera", "MossRealSense") for k in nav.remapping_map))exp = mb.build_moss_explore()e = names(exp)@@ -533,33 +533,33 @@ def blueprint_text(bp):return [(b.module.__name__, repr(sorted(b.kwargs.items()))) for b in bp.blueprints]-cam_default = atom(nav, "RealSenseCamera")-check("MOSS_IMU unset: the camera atom is dimOS's own RealSenseCamera, enable_imu False, no imu_hz kwarg",- cam_default.module is RealSenseCamera and cam_default.kwargs.get("enable_imu") is False- and "imu_hz" not in cam_default.kwargs)-check("MOSS_IMU unset: no BumpImu, no MossRealSense in moss-nav or moss-explore",- not ({"BumpImu", "MossRealSense"} & (names(nav) | names(exp))), f"{sorted(names(exp))}")+from moss_dimos.bump_imu import BumpImu # noqa: E402+from moss_dimos.realsense_imu import MossRealSense # noqa: E402+# the default (MOSS_IMU unset) is the IMU ON: colour, depth and IMU were seen alive together on the robot+check("MOSS_IMU unset (the default): moss-nav has MossRealSense and BumpImu, and no stock RealSenseCamera",+ {"MossRealSense", "BumpImu"} <= names(nav) and "RealSenseCamera" not in names(nav), f"{sorted(names(nav))}")+check("MOSS_IMU unset: moss-explore too, with the planner and the explorer still there",+ {"MossRealSense", "BumpImu", "RecoveringPlanner", "Explorer2"} <= names(exp) and "RealSenseCamera" not in names(exp))for spelled_off in ("0", "off"):os.environ["MOSS_IMU"] = spelled_off- same_nav, same_exp = mb.build_moss_nav(), mb.build_moss_explore()- check(f"MOSS_IMU={spelled_off}: moss-nav and moss-explore are the blueprints of the unset switch, kwarg for kwarg",- blueprint_text(same_nav) == blueprint_text(nav) and blueprint_text(same_exp) == blueprint_text(exp))+ off_nav, off_exp = mb.build_moss_nav(), mb.build_moss_explore()+ cam_off = atom(off_nav, "RealSenseCamera")+ check(f"MOSS_IMU={spelled_off}: the camera atom is dimOS's own RealSenseCamera, enable_imu False, no imu_hz kwarg, no BumpImu, no MossRealSense",+ cam_off is not None and cam_off.module is RealSenseCamera and cam_off.kwargs.get("enable_imu") is False+ and "imu_hz" not in cam_off.kwargs and not ({"BumpImu", "MossRealSense"} & (names(off_nav) | names(off_exp))),+ f"{sorted(names(off_exp))}")os.environ["MOSS_IMU"] = "1"imu_nav, imu_exp = mb.build_moss_nav(), mb.build_moss_explore()-from moss_dimos.bump_imu import BumpImu # noqa: E402-from moss_dimos.realsense_imu import MossRealSense # noqa: E402-check("MOSS_IMU=1: moss-nav has MossRealSense and BumpImu, and no stock RealSenseCamera",- {"MossRealSense", "BumpImu"} <= names(imu_nav) and "RealSenseCamera" not in names(imu_nav), f"{sorted(names(imu_nav))}")-check("MOSS_IMU=1: moss-explore too, with the planner and the explorer still there",- {"MossRealSense", "BumpImu", "RecoveringPlanner", "Explorer2"} <= names(imu_exp) and "RealSenseCamera" not in names(imu_exp))+check("MOSS_IMU=1: the same blueprints as the unset switch, kwarg for kwarg",+ blueprint_text(imu_nav) == blueprint_text(nav) and blueprint_text(imu_exp) == blueprint_text(exp))cam_imu = atom(imu_nav, "MossRealSense")check("the camera atom is moss_dimos.realsense_imu.MossRealSense, a RealSenseCamera subclass",cam_imu.module is MossRealSense and issubclass(MossRealSense, RealSenseCamera))check("... enable_imu True, imu_hz 200", cam_imu.kwargs.get("enable_imu") is True and cam_imu.kwargs.get("imu_hz") == 200,f"{cam_imu.kwargs.get('enable_imu')} {cam_imu.kwargs.get('imu_hz')}")strip = lambda kw: repr(sorted((k, v) for k, v in kw.items() if k not in ("enable_imu", "imu_hz"))) # noqa: E731-check("... every other camera kwarg as without the switch (640x480 @ 5 fps, depth, no cloud, the mount)",- strip(cam_imu.kwargs) == strip(cam_default.kwargs), f"{strip(cam_imu.kwargs)}")+check("... every other camera kwarg as with the IMU off (640x480 @ 5 fps, depth, no cloud, the mount)",+ strip(cam_imu.kwargs) == strip(cam_off.kwargs), f"{strip(cam_imu.kwargs)}")bk = atom(imu_nav, "BumpImu").kwargscheck("BumpImu atom: forward axis +z, 4.0 m/s^2, debounce 0.7 s, no CSV (the defaults, read at build time)",bk == {"axis": "+z", "threshold": 4.0, "debounce_s": 0.7, "log_path": None}, f"{bk}")@@ -636,7 +636,7 @@ os.environ["MOSS_CAMERA"] = "0"os.environ["MOSS_RECORD"] = "0"bare = mb.build_moss_nav()check("MOSS_CAMERA=0 MOSS_RECORD=0 -> no RealSense, no recorder, no JPEG transport",- not ({"RealSenseCamera", "MossRecorder"} & names(bare)) and ("color_image", Image) not in bare.transport_map)+ not ({"RealSenseCamera", "MossRealSense", "BumpImu", "MossRecorder"} & names(bare)) and ("color_image", Image) not in bare.transport_map)os.environ["MOSS_WRIST"] = "0"bare2 = mb.build_moss_nav()check("MOSS_WRIST=0 -> no WristCamera, no wrist remap, no wrist transport",@@ -647,7 +647,7 @@ os.environ.update(MOSS_CAMERA="OFF", MOSS_RECORD=" no ", MOSS_WRIST="False")spelled = mb.build_moss_nav()check("MOSS_CAMERA=OFF, MOSS_RECORD=' no ', MOSS_WRIST=False -> the same bare build ""(robot_profile.env_on, the one switch parser)",- not ({"RealSenseCamera", "MossRecorder", "WristCamera"} & names(spelled))+ not ({"RealSenseCamera", "MossRealSense", "BumpImu", "MossRecorder", "WristCamera"} & names(spelled))and ("color_image", Image) not in spelled.transport_map and ("wrist_image", Image) not in spelled.transport_map)check("the blueprint has no switch parser of its own", not hasattr(mb, "_env_on"))os.environ.update(MOSS_CAMERA="0", MOSS_RECORD="0")diff --git a/docs/imu.md b/docs/imu.mdindex 4ad6100..8ed8e22 100644--- a/docs/imu.md+++ b/docs/imu.md@@ -129,7 +129,7 @@ are what the signature must look at, with the gyro columns of the CSV next to| Variable | Default | What ||---|---|---|-| `MOSS_IMU` | off | `1`: MossRealSense with the IMU at 200 Hz and the BumpImu module. Needs the camera (`MOSS_CAMERA=0` refuses it with a warning). |+| `MOSS_IMU` | on | MossRealSense with the IMU at 200 Hz and the BumpImu module; `0` goes back to dimOS's camera without IMU. Needs the camera (`MOSS_CAMERA=0` refuses it with a warning). || `MOSS_BUMP_ACCEL` | 4.0 | threshold in m/s^2 on the high-passed forward accel, above 0 and up to 100 || `MOSS_BUMP_AXIS` | `+z` | the forward axis of the camera's frame, x, y or z with a sign || `MOSS_BUMP_DEBOUNCE_S` | 0.7 | seconds of silence after a contact, 0 to 10 |@@ -168,11 +168,12 @@ a value that does not parse is refused with a warning and the default stays.`--serial` (default `MOSS_RS_SERIAL`) change the run. Tilt the nose downby hand during a run to check the sign of z (above).-2. **A stationary launch.** `MOSS_IMU=1 tools/moss-fly.sh map`, the rover- still. `tools/moss-fly.sh log` must show `MOSS IMU: motion module open on- the camera's own device` and `MOSS IMU: first sample`, and the cockpit must- show colour and the depth obstacles as before. Until that launch has been- seen, `MOSS_IMU` stays off by default.+2. **A stationary launch.** `tools/moss-fly.sh map`, the rover still.+ `tools/moss-fly.sh log` must show `MOSS IMU: motion module open on the+ camera's own device` and `MOSS IMU: first sample`, and the cockpit must show+ colour and the depth obstacles as before. This launch was seen on the robot+ (colour and depth at their usual rate, the IMU at 199 Hz, gravity on -y),+ which is why the IMU is on by default; `MOSS_IMU=0` turns it off.3. **A signature before tightening the threshold.** Record what real contacts,real stops and the real floor look like:diff --git a/moss_dimos/blueprints.py b/moss_dimos/blueprints.pyindex 8b8d1ca..ddc9a36 100644--- a/moss_dimos/blueprints.py+++ b/moss_dimos/blueprints.py@@ -37,15 +37,11 @@ parses them: 0, false, no or off = off, any other value = on, unset = the defaulMOSS_GYRO=1 gyro prior for the lidar odometry from the RealSense's IMU (default OFF: alone, it usesdimOS's second IMU pipeline, which fails to open on the rover and takes the camera downwith it; an experiment. With MOSS_IMU=1 the gyro comes from the in-process motion module)- MOSS_IMU=1 contacts from the RealSense's IMU (default OFF: opt-in until a stationary launch on the- robot shows colour, depth and IMU alive together). The camera becomes MossRealSense- (moss_dimos/realsense_imu.py: the motion module opened in the camera's process on the- device its pipeline holds, accel + gyro at 200 Hz on `imu`) and BumpImu- (moss_dimos/bump_imu.py) publishes `bump` - the stream of the stall guard: the planner's- escape, the costmap's contact memory, the sounds - on a hard deceleration against the- track command. MOSS_BUMP_ACCEL (m/s^2, default 4.0), MOSS_BUMP_AXIS (default +z),+ MOSS_IMU=0 no IMU contacts (default ON: the RealSense's IMU is read inside the camera's own+ process, colour, depth and IMU proven alive together on the robot; a deceleration against+ the commanded direction publishes bump). Knobs: MOSS_BUMP_ACCEL (default 4.0 m/s^2),MOSS_BUMP_DEBOUNCE_S (default 0.7), MOSS_IMU_LOG=<csv> (every sample); docs/imu.md.- Needs the camera: with MOSS_CAMERA=0 it is refused with a warning+ Needs the camera: with MOSS_CAMERA=0 there are no IMU contacts (said in the log)MOSS_DESKEW=1 kiss-icp straightens each lidar revolution by the motion prior (default OFF: on therover its first thread fails and the odometry stops; an experiment)MOSS_SOUNDS=0 no sound module (default on when pw-play or paplay is on the PATH: the sound pack@@ -461,7 +457,7 @@ def _common_parts(ports: dict, profile: RobotProfile) -> list:]# MOSS_IMU=1: the IMU is opened inside the camera's own process (MossRealSense) and BumpImu turns# its decelerations into contacts on `bump`; the IMU lives on the RealSense, so no camera, no IMU- imu = robot_profile.env_on("MOSS_IMU", False)+ imu = robot_profile.env_on("MOSS_IMU", True)if imu and not robot_profile.env_on("MOSS_CAMERA", True):_logger.warning("MOSS blueprint: MOSS_IMU needs the RealSense and MOSS_CAMERA is off: no IMU contacts")imu = False