Skip to content

Commit a243a38

Browse files
committed
download from drone to .js file works, upload from .js file to drone works.
gui doesn't show it yet.
1 parent 188f7c0 commit a243a38

File tree

3 files changed

+90
-52
lines changed

3 files changed

+90
-52
lines changed

gotmission1.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
window.missionItems = [
2+
[0,0,0,16,0,0,0,0,0,0,0,1],
3+
[1,0,3,16,0,0,0,0,-27.51346206665039,153.00894165039062,100,1],
4+
[2,0,3,16,0,0,0,0,-27.513059616088867,153.00894165039062,100,1],
5+
[3,0,3,16,0,0,0,0,-27.512985229492188,153.0095672607422,100,1],
6+
[4,0,3,16,0,0,0,0,-27.513309478759766,153.00994873046875,100,1],
7+
[5,0,3,16,0,0,0,0,-27.513763427734375,153.00987243652344,100,1],
8+
[6,0,3,16,0,0,0,0,-27.513927459716797,153.00933837890625,100,1],
9+
[7,0,3,16,0,0,0,0,-27.513683319091797,153.00881958007812,100,1],
10+
];
11+
//module.exports = missionItems;

js/mavsp/MAVSPHelper.js

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,21 @@ sysids[SYSID] = true;
8282
// global mav mission object for gettting/sending missions to drone
8383
var MissionObj = undefined ; // we delay instantion till we know SYSID // new MavMission(SYSID,COMPID,mavlink20, mavParserObj , null, logger);
8484

85-
function send_canned_mission_to_drone() {
85+
async function send_canned_mission_to_drone() {
8686
// obj for missions
8787
if (MissionObj ==undefined ) MissionObj = new MavMission(SYSID,COMPID,mavlink20, mavParserObj , null, logger);
8888

89-
var readfilename = "./gotmission3.js";
90-
var miss = require(readfilename);
89+
var module = { exports: {} }; // hack for node compat
90+
var readfilename = "/gotmission1.js"; // no leading . or ./ its an absolute url ah-la http://xxxx/gotmission1.js
91+
// var miss = require(readfilename); Node.js
92+
93+
//let modulePath = prompt("Which module to load?");
94+
95+
96+
mod = await import(readfilename);
97+
98+
var miss = window.missionItems;
99+
91100

92101
console.log('START SEND MISSION to drone:',readfilename);
93102
// awaiting in a non-async is like this...
@@ -1148,14 +1157,23 @@ var mspHelper = (function (gui) {
11481157

11491158

11501159

1151-
case mavlink20.MAVLINK_MSG_ID_MISSION_ITEM_REACHED:
1160+
case mavlink20.MAVLINK_MSG_ID_MISSION_ITEM_REACHED: //46
11521161
/* ["seq"]
11531162
seq: 7
11541163
// note that _header.srcSystem give the vehicle sysid that it came from as well
11551164
*/
11561165
// buzz todo
11571166
break;
11581167

1168+
case mavlink20.MAVLINK_MSG_ID_MISSION_ITEM_INT: // 73
1169+
case mavlink20.MAVLINK_MSG_ID_MISSION_ITEM: //39
1170+
case mavlink20.MAVLINK_MSG_ID_MISSION_REQUEST_INT: //51
1171+
case mavlink20.MAVLINK_MSG_ID_MISSION_REQUEST: //40
1172+
case mavlink20.MAVLINK_MSG_ID_MISSION_ACK: //47
1173+
1174+
// buzz todo
1175+
break;
1176+
11591177
// add more here
11601178

11611179
// case mavlink20.MAVLINK_MSG_ID_SENSOR_OFFSETS:
@@ -4124,51 +4142,57 @@ var mspHelper = (function (gui) {
41244142
callback(); // without a response, we'll call the callback anyway
41254143
};
41264144

4127-
self.loadWaypoints = function (callback) {
4145+
self.loadWaypoints = function (callback) { //getWaypointsFromFC
41284146
MISSION_PLANER.reinit();
41294147
let waypointId = 1;
4130-
//MSP.send_message(MSPCodes.MSP_WP_GETINFO, false, false, null);
4131-
getFirstWP();
4148+
4149+
get_mission_from_drone();
4150+
// //MSP.send_message(MSPCodes.MSP_WP_GETINFO, false, false, null);
4151+
// getFirstWP();
41324152

4133-
function getFirstWP() {
4134-
//MSP.send_message(MSPCodes.MSP_WP, [waypointId], false, null);
4135-
nextWaypoint();
4136-
};
4153+
// function getFirstWP() {
4154+
// //MSP.send_message(MSPCodes.MSP_WP, [waypointId], false, null);
4155+
// nextWaypoint();
4156+
// };
41374157

4138-
function nextWaypoint() {
4139-
waypointId++;
4140-
if (waypointId < MISSION_PLANER.getCountBusyPoints()) {
4141-
// MSP.send_message(MSPCodes.MSP_WP, [waypointId], false, null);
4142-
nextWaypoint();
4143-
}
4144-
else {
4145-
//MSP.send_message(MSPCodes.MSP_WP, [waypointId], false, null);
4146-
callback(); // without a response, we'll call the callback anyway
4147-
}
4148-
};
4158+
// function nextWaypoint() {
4159+
// waypointId++;
4160+
// if (waypointId < MISSION_PLANER.getCountBusyPoints()) {
4161+
// // MSP.send_message(MSPCodes.MSP_WP, [waypointId], false, null);
4162+
// nextWaypoint();
4163+
// }
4164+
// else {
4165+
// //MSP.send_message(MSPCodes.MSP_WP, [waypointId], false, null);
4166+
// callback(); // without a response, we'll call the callback anyway
4167+
// }
4168+
// };
41494169
};
4150-
4151-
self.saveWaypoints = function (callback) {
4170+
4171+
self.saveWaypoints = function (callback) { //sendWaypointsToFC
41524172
let waypointId = 1;
4173+
4174+
send_canned_mission_to_drone();
4175+
4176+
41534177
//MSP.send_message(MSPCodes.MSP_SET_WP, MISSION_PLANER.extractBuffer(waypointId), false, null);
4154-
nextWaypoint();
4178+
// nextWaypoint();
41554179

4156-
function nextWaypoint() {
4157-
waypointId++;
4158-
if (waypointId < MISSION_PLANER.get().length) {
4159-
//MSP.send_message(MSPCodes.MSP_SET_WP, MISSION_PLANER.extractBuffer(waypointId), false, null);
4160-
nextWaypoint();
4161-
}
4162-
else {
4163-
//MSP.send_message(MSPCodes.MSP_SET_WP, MISSION_PLANER.extractBuffer(waypointId), false, null);
4164-
endMission();
4165-
}
4166-
};
4180+
// function nextWaypoint() {
4181+
// waypointId++;
4182+
// if (waypointId < MISSION_PLANER.get().length) {
4183+
// //MSP.send_message(MSPCodes.MSP_SET_WP, MISSION_PLANER.extractBuffer(waypointId), false, null);
4184+
// nextWaypoint();
4185+
// }
4186+
// else {
4187+
// //MSP.send_message(MSPCodes.MSP_SET_WP, MISSION_PLANER.extractBuffer(waypointId), false, null);
4188+
// endMission();
4189+
// }
4190+
// };
41674191

4168-
function endMission() {
4169-
//MSP.send_message(MSPCodes.MSP_WP_GETINFO, false, false, null);
4170-
callback(); // without a response, we'll call the callback anyway
4171-
}
4192+
// function endMission() {
4193+
// //MSP.send_message(MSPCodes.MSP_WP_GETINFO, false, false, null);
4194+
// callback(); // without a response, we'll call the callback anyway
4195+
// }
41724196
};
41734197

41744198
self.loadSafehomes = function (callback) {

js/mavsp/mavMission.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var soccerFieldFlight = [
4444
];
4545

4646
// Waypoints, an ordered array of waypoint MAVLink objects
47-
var missionItems = [];
47+
//var missionItems = [];
4848

4949
// Mission object constructor
5050
class MavMission {
@@ -68,7 +68,8 @@ class MavMission {
6868

6969
}
7070

71-
util.inherits(MavMission, events.EventEmitter);
71+
//util.inherits(MavMission, events.EventEmitter);
72+
inherits(MavMission, EventEmitter);
7273

7374

7475
// Handler when the ArduPilot requests individual waypoints: upon receiving a request,
@@ -127,7 +128,7 @@ MavMission.prototype.enableSendMission = function() {
127128

128129
if(mavlink20.MAV_MISSION_ACCEPTED === ack.type) {
129130
console.log('mission:sent to drone');
130-
t.emit('mission:sent to drone');
131+
//t.emit('mission:sent to drone');
131132
t.send_complete = true; // t is this
132133
} else if(mavlink20.MAV_MISSION_INVALID === ack.type) {
133134
console.log("invalid mission");
@@ -138,7 +139,8 @@ MavMission.prototype.enableSendMission = function() {
138139
console.log("invalid sequence");
139140
} else {
140141
console.log(ack);
141-
throw new Error('Unexpected mission acknowledgement received in mavMission.js');
142+
//throw new Error('Unexpected mission acknowledgement received in mavMission.js');
143+
console.log('Unexpected mission acknowledgement received in mavMission.js');
142144
}
143145
});
144146

@@ -285,7 +287,8 @@ MavMission.prototype.enableGetMission = function() {
285287
// MissionItemMessage is a MAVLink MessageItem object
286288
MavMission.prototype.addMissionItem = function(missionItemMessage) {
287289
if( _.isUndefined(missionItemMessage)) {
288-
throw new Error('Undefined message item in MavMission.addMissionItem!');
290+
//throw new Error('Undefined message item in MavMission.addMissionItem!');
291+
console.log('Undefined message item in MavMission.addMissionItem!');
289292
}
290293
this.missionItems[missionItemMessage.seq] = missionItemMessage;
291294
};
@@ -336,7 +339,7 @@ MavMission.prototype.DroneToMission = async function(filename) {
336339
//await fs.writeFile(filename, data);
337340

338341
// write as mission format compatible with this script for cut-n-paste
339-
var data2 = 'var missionItems = [\n';
342+
var data2 = 'window.missionItems = [\n';
340343
_.each(this.missionItems, function(e, i, l) {
341344

342345
//console.log(e);
@@ -349,16 +352,16 @@ MavMission.prototype.DroneToMission = async function(filename) {
349352
e.param2, //5
350353
e.param3, //6
351354
e.param4, //7
352-
e.x/10000000, //8
353-
e.y/10000000, //9
355+
e.x,///10000000, //8
356+
e.y,///10000000, //9
354357
e.z, //10
355358
e.autocontinue]; //11
356359

357360
data2 += "[";
358361
data2 += l.toString();
359362
data2 += "],\n";
360363
});
361-
data2 += '];\nmodule.exports = missionItems;\n';
364+
data2 += '];\n//module.exports = missionItems;\n';
362365
await fs.writeFile(filename, data2);
363366

364367
console.log("MISSION FILE WRITTEN:",filename);// this happens after file written
@@ -397,8 +400,8 @@ this.enableGetMission(); // can be called too many times, thats fine.
397400
e[5], // param2,
398401
e[6], // param3
399402
e[7], // param4
400-
e[8], // x (latitude
401-
e[9], // y (longitude
403+
e[8],//*10000000, // x (latitude
404+
e[9],//*10000000, // y (longitude
402405
e[10], // z (altitude
403406
);
404407

@@ -578,4 +581,4 @@ var missionItemsQuadTesting = [
578581
# z
579582
*/
580583

581-
module.exports = MavMission;
584+
//module.exports = MavMission;

0 commit comments

Comments
 (0)