Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put the current mode of the plane into a string #50

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions services/common/messages/telemetry.proto
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ message Overview {
Velocity vel = 5;
Speed speed = 6;
Battery battery = 7;
string mode = 8;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I wonder if we should enumerate the mode. This works for now though, and enumerating has complications because the custom mode differs based on the firmware.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can add an endpoint for returning the available modes for the autopilot in strings for the future?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the file mode on this file changed in the commit

}

// WGS84 in degrees
Expand Down
37 changes: 35 additions & 2 deletions services/telemetry/src/plane.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ const ConnectionState = Object.freeze({
WRITING: Symbol('writing')
});

let mode_mapping_apm = {
0 : 'MANUAL',
1 : 'CIRCLE',
2 : 'STABILIZE',
3 : 'TRAINING',
4 : 'ACRO',
5 : 'FBWA',
6 : 'FBWB',
7 : 'CRUISE',
8 : 'AUTOTUNE',
10 : 'AUTO',
11 : 'RTL',
12 : 'LOITER',
14 : 'LAND',
15 : 'GUIDED',
16 : 'INITIALISING',
17 : 'QSTABILIZE',
18 : 'QHOVER',
19 : 'QLOITER',
20 : 'QLAND',
21 : 'QRTL',
22 : 'QAUTOTUNE'
};

/** Holds the state of a plane over a MAVLink UDP connection. */
export default class Plane {
/**
Expand All @@ -39,7 +63,8 @@ export default class Plane {
alt: {},
vel: {},
speed: {},
battery: {}
battery: {},
mode: ''
});

// Will be assigned on each GLOBAL_POSITION_INT message.
Expand Down Expand Up @@ -245,7 +270,8 @@ export default class Plane {
'MISSION_CURRENT': this._onMissionCurrent.bind(this),
'MISSION_ITEM': this._onMissionItem.bind(this),
'VFR_HUD': this._onVfrHud.bind(this),
'SYS_STATUS': this._onSysStatus.bind(this)
'SYS_STATUS': this._onSysStatus.bind(this),
'HEARTBEAT': this._onHeartbeat.bind(this)
};

// Make every message definition .on
Expand Down Expand Up @@ -338,4 +364,11 @@ export default class Plane {
ov.battery.current = fields.current_battery / 100;
ov.battery.percentage = fields.battery_remaining;
}

async _onHeartbeat(fields) {
let ov = this._overview;

ov.time = Date.now() / 1000;
ov.mode = mode_mapping_apm[fields.custom_mode];
}
}
1 change: 1 addition & 0 deletions services/telemetry/test/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ beforeAll(async () => {
await planeSitl.start();

planeIp = (await planeSitl.inspect()).NetworkSettings.IPAddress;

}, 10000);

// Stop the plane-sitl container.
Expand Down