Skip to content

Commit 60c2d23

Browse files
committed
Mission Control tab -> "Load Mission from FC" blue widget can now get mission from drone , save it to ./gotmission1.js AND draw normal WP's on-screen.
button next to it writes from .js to drone, not from GuI.
1 parent a243a38 commit 60c2d23

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

js/mavsp/MAVSPHelper.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,21 @@ async function send_canned_mission_to_drone() {
103103
MissionObj.MissionToDrone(miss).then(results => { console.log('END SEND MISSION to drone'); });
104104
}
105105

106-
function get_mission_from_drone() {
106+
async function get_mission_from_drone(cb) {
107107
// obj for missions
108108
if (MissionObj ==undefined ) MissionObj = new MavMission(SYSID,COMPID,mavlink20, mavParserObj , null, logger);
109109

110110
var writefilename = "./gotmission1.js"; // default if not specificed
111111

112112
console.log('START READ MISSION from drone',writefilename)
113113
// awaiting in a non-async is like this...
114-
MissionObj.DroneToMission(writefilename).then(results => { console.log('END READ MISSION from drone'); });
114+
await MissionObj.DroneToMission(writefilename).then(results => {
115+
console.log('END READ MISSION from drone');
116+
console.log(MISSION_PLANER);
117+
if ( cb ) cb();
118+
});
115119

120+
116121
}
117122

118123
function mavFlightModes_rehook() {
@@ -4146,7 +4151,7 @@ var mspHelper = (function (gui) {
41464151
MISSION_PLANER.reinit();
41474152
let waypointId = 1;
41484153

4149-
get_mission_from_drone();
4154+
get_mission_from_drone(callback);
41504155
// //MSP.send_message(MSPCodes.MSP_WP_GETINFO, false, false, null);
41514156
// getFirstWP();
41524157

@@ -4166,6 +4171,7 @@ var mspHelper = (function (gui) {
41664171
// callback(); // without a response, we'll call the callback anyway
41674172
// }
41684173
// };
4174+
//callback();
41694175
};
41704176

41714177
self.saveWaypoints = function (callback) { //sendWaypointsToFC

js/mavsp/mavMission.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,26 @@ MavMission.prototype.DroneToMission = async function(filename) {
360360
data2 += "[";
361361
data2 += l.toString();
362362
data2 += "],\n";
363+
364+
var wp_type = MWNP.WPTYPE.WAYPOINT;
365+
//if ( e.command == 16 ) wp_type = MWNP.WPTYPE.WAYPOINT; // The scheduled action for the waypoint.
366+
367+
// skip 'home' = 'zero' wp from drone
368+
if ( e.seq != 0 ) {
369+
//number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endMission=0, isUsed=true, isAttached=false, attachedId=""
370+
MISSION_PLANER.put(new Waypoint(
371+
e.seq,//data.getUint8(0),//number
372+
wp_type,//data.getUint8(1), //action like MWNP.WPTYPE.JUMP or MWNP.WPTYPE.WAYPOINT
373+
e.x*10000000,//data.getInt32(2, true), //lat
374+
e.y*10000000,//data.getInt32(6, true), //lon
375+
e.z,//data.getInt32(10, true), //alt
376+
e.param1,//data.getInt16(14, true), //p1
377+
e.param2,//data.getInt16(16, true), //p2
378+
e.param3,//data.getInt16(18, true) //p3
379+
// eep buzz todo, fit e.param4
380+
));
381+
}
382+
//
363383
});
364384
data2 += '];\n//module.exports = missionItems;\n';
365385
await fs.writeFile(filename, data2);

tabs/mission_control.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,10 @@ TABS.mission_control.initialize = function (callback) {
392392

393393
//////////////////////////////////////////////////////////////////////////////////////////////
394394
// define & init Waypoints parameters
395-
//////////////////////////////////////////////////////////////////////////////////////////////
395+
//////////////////////////////////////////////////////////////////////////////////////////////
396+
// buzz todo need ot understand diff between global MISSION_PLANER and this var..
397+
// this 'var mission =' is updated/modifled/adjusted by the user in the GUI , NOT the drone.
398+
// and i think MISSION_PLANER is used for the drone to read/write from/to.
396399
var mission = new WaypointCollection();
397400

398401
//////////////////////////////////////////////////////////////////////////////////////////////
@@ -1843,14 +1846,14 @@ TABS.mission_control.initialize = function (callback) {
18431846
//
18441847
/////////////////////////////////////////////
18451848
function getWaypointsFromFC() {
1846-
mspHelper.loadWaypoints();
1849+
mspHelper.loadWaypoints(); // getWaypointsFromFC
18471850
setTimeout(function(){
18481851
mission.reinit();
18491852
mission.copy(MISSION_PLANER);
18501853
mission.update(true);
18511854
redrawLayers();
18521855
updateTotalInfo();
1853-
}, 2000);
1856+
}, 5000);
18541857
}
18551858

18561859
function sendWaypointsToFC() {

0 commit comments

Comments
 (0)