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