gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
please convert this code to a sequential style : no object, no functions class Mav {…
- User
please convert this code to a sequential style : no object, no functions
codeclass Mav { constructor(plan, version, takeoff) { this.plan = plan; this.header = `QGC WPL ${version}`; this.takeoff = takeoff; this.missionItems = this.convert(); this.file = this.formatItems(); } convert() { const mavItems = []; const planItems = this.plan.mission.items; planItems.forEach((item, index) => { const frame = item.frame; const command = item.command; const autoContinue = item.autoContinue ? 1 : 0; const parameters = item.params.map(param => (param === null ? "Nan" : param.toFixed(6))); const mavItem = [index, 0, frame, command, ...parameters, autoContinue]; mavItems.push(mavItem); }); return this.setCurrentWp(mavItems); } setCurrentWp(missionItems) { let flag = 0; for (let item of missionItems) { if (item[3] === TAKEOFF && flag === 0) { item[1] = 1; // set current waypoint flag = 1; } if (item[3] === WAYPOINT) { return missionItems; } } console.warn("No WAYPOINT detected! GroundSDK Flightplans require WAYPOINT to run flightplans"); return missionItems; } formatItems() { const mavFile = [this.header]; if (this.takeoff) { this.takeoff = [0, 1, 3, TAKEOFF, 0, 0, 0, 0, 0, 0, 0, 0]; mavFile.push('\n'); mavFile.push(this.insertTabs(this.takeoff)); } this.missionItems.forEach(line => { mavFile.push('\n'); mavFile.push(this.insertTabs(line)); }); return mavFile.join(''); } insertTabs(target) { return target.join('\t\t'); } } - Assistant