mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
cliff improvements
This commit is contained in:
@@ -142,18 +142,26 @@ function buildRoverCtxSnapshot(roverId) {
|
||||
(sensors?.bumpsAndWheelDrops?.bumpLeft ? 0.5 : 0) +
|
||||
(sensors?.bumpsAndWheelDrops?.bumpRight ? 0.5 : 0);
|
||||
const light = sensors?.lightBumper || {};
|
||||
const contactState =
|
||||
latestBumps >= 0.5
|
||||
const contactState = docked
|
||||
? 'clear'
|
||||
: latestBumps >= 0.5
|
||||
? 'bumps_recent'
|
||||
: sensors?.wall || light.left || light.frontLeft || light.centerLeft || light.centerRight || light.frontRight || light.right
|
||||
? 'wall_brush'
|
||||
: 'clear';
|
||||
const hazardState =
|
||||
sensors?.virtualWall
|
||||
: sensors?.wall ||
|
||||
light.left ||
|
||||
light.frontLeft ||
|
||||
light.centerLeft ||
|
||||
light.centerRight ||
|
||||
light.frontRight ||
|
||||
light.right
|
||||
? 'wall_brush'
|
||||
: 'clear';
|
||||
const hazardState = docked
|
||||
? 'normal'
|
||||
: sensors?.virtualWall
|
||||
? 'virtual_wall_seen'
|
||||
: sensors?.cliffLeft || sensors?.cliffFrontLeft || sensors?.cliffFrontRight || sensors?.cliffRight
|
||||
? 'cliff_alert'
|
||||
: 'normal';
|
||||
? 'cliff_alert'
|
||||
: 'normal';
|
||||
const mobilityState = wheelsOffGround ? 'wheels_off_ground' : 'normal';
|
||||
const baseScore = Math.min(100, Math.round(Math.min(45, latestDistanceM * 25) + Math.min(30, latestTurnDeg / 12) + Math.min(25, latestBumps * 12)));
|
||||
const activityScore = Math.max(
|
||||
|
||||
@@ -279,6 +279,7 @@ function upsertActivityState(roverId) {
|
||||
function onSensorEvent({ roverId, sensors, batteryState } = {}) {
|
||||
if (!roverId || !sensors) return;
|
||||
const nowMs = Date.now();
|
||||
const dockedNow = Boolean(sensors?.chargingSources?.homeBase);
|
||||
const bucketTs = Math.floor(nowMs / ACTIVITY_BUCKET_MS) * ACTIVITY_BUCKET_MS;
|
||||
const state = upsertActivityState(String(roverId));
|
||||
pruneActivityBuckets(state, nowMs);
|
||||
@@ -290,11 +291,13 @@ function onSensorEvent({ roverId, sensors, batteryState } = {}) {
|
||||
bucket.turnDeg += Math.abs(Number(sensors.angleDeg) || 0);
|
||||
const bumpLeftNow = Boolean(sensors?.bumpsAndWheelDrops?.bumpLeft);
|
||||
const bumpRightNow = Boolean(sensors?.bumpsAndWheelDrops?.bumpRight);
|
||||
if (bumpLeftNow && !state.bumpLeftActive) {
|
||||
bucket.bumps += 0.5;
|
||||
}
|
||||
if (bumpRightNow && !state.bumpRightActive) {
|
||||
bucket.bumps += 0.5;
|
||||
if (!dockedNow) {
|
||||
if (bumpLeftNow && !state.bumpLeftActive) {
|
||||
bucket.bumps += 0.5;
|
||||
}
|
||||
if (bumpRightNow && !state.bumpRightActive) {
|
||||
bucket.bumps += 0.5;
|
||||
}
|
||||
}
|
||||
state.bumpLeftActive = bumpLeftNow;
|
||||
state.bumpRightActive = bumpRightNow;
|
||||
@@ -303,7 +306,7 @@ function onSensorEvent({ roverId, sensors, batteryState } = {}) {
|
||||
const activeDrivers = getActiveDrivers();
|
||||
const driverSocketId = activeDrivers[roverKey] || null;
|
||||
const driverNickname = driverSocketId ? resolveDriverNickname(driverSocketId) : null;
|
||||
const docked = Boolean(sensors?.chargingSources?.homeBase);
|
||||
const docked = dockedNow;
|
||||
const charging = isChargingFromSensors(sensors);
|
||||
const wheelsOffGround = Boolean(
|
||||
sensors?.bumpsAndWheelDrops?.wheelDropLeft && sensors?.bumpsAndWheelDrops?.wheelDropRight,
|
||||
@@ -578,7 +581,8 @@ function compactRoverForContext(rover) {
|
||||
};
|
||||
}
|
||||
|
||||
function deriveContactState(sensors = {}, activity30s = {}) {
|
||||
function deriveContactState(sensors = {}, activity30s = {}, docked = false) {
|
||||
if (docked) return 'clear';
|
||||
const bumps = Number(activity30s?.bumps) || 0;
|
||||
const hasBump = bumps >= 0.5 || sensors?.bumpsAndWheelDrops?.bumpLeft || sensors?.bumpsAndWheelDrops?.bumpRight;
|
||||
if (hasBump) return 'bumps_recent';
|
||||
@@ -590,7 +594,8 @@ function deriveContactState(sensors = {}, activity30s = {}) {
|
||||
return 'clear';
|
||||
}
|
||||
|
||||
function deriveHazardState(sensors = {}) {
|
||||
function deriveHazardState(sensors = {}, docked = false) {
|
||||
if (docked) return 'normal';
|
||||
if (Boolean(sensors?.virtualWall)) return 'virtual_wall_seen';
|
||||
if (
|
||||
Boolean(sensors?.cliffLeft) ||
|
||||
@@ -651,8 +656,8 @@ function buildRoversNow(nowMs = Date.now()) {
|
||||
battery_low: Boolean(batteryState?.warnActive || batteryState?.urgentActive),
|
||||
activity_30s: activity30s,
|
||||
status_tag: statusTag,
|
||||
contact_state: deriveContactState(sensors, activity30s),
|
||||
hazard_state: deriveHazardState(sensors),
|
||||
contact_state: deriveContactState(sensors, activity30s, docked),
|
||||
hazard_state: deriveHazardState(sensors, docked),
|
||||
mobility_state: deriveMobilityState(sensors, wheelsOffGround),
|
||||
};
|
||||
const currentBaseScore = computeBaseActivityScore(activity30s);
|
||||
|
||||
Reference in New Issue
Block a user