Skip to content

Commit

Permalink
Allow user to change mission type
Browse files Browse the repository at this point in the history
  • Loading branch information
yashdeep97 committed Jul 22, 2020
1 parent 5d5262c commit 3fb1e87
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 96 deletions.
63 changes: 0 additions & 63 deletions experiments/WebUI/src/assets/jc2.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,66 +639,3 @@ export class UpdateMissionReq extends AbstractRequest {
super('org.arl.jc2.messages.management.UpdateMissionReq', params);
}
}


//*************** Classes for different Mission types ***************

export class SimpleMT extends AbstractRequest {

/**
* Constructs an SimpleMT mission task.
*
* @param {Object} params parameters.
*/
constructor(params) {
super('org.arl.jc2.mtt.SimpleMT', params);
}
}

export class LawnMowerMT extends AbstractRequest {

/**
* Constructs an LawnMowerMT mission task.
*
* @param {Object} params parameters.
*/
constructor(params) {
super('org.arl.jc2.mtt.LawnMowerMT', params);
}
}

export class StationKeepingMT extends AbstractRequest {

/**
* Constructs an StationKeepingMT mission task.
*
* @param {Object} params parameters.
*/
constructor(params) {
super('org.arl.jc2.mtt.StationKeepingMT', params);
}
}

export class SwanArmMT extends AbstractRequest {

/**
* Constructs an SwanArmMT mission task.
*
* @param {Object} params parameters.
*/
constructor(params) {
super('org.arl.jc2.mtt.SwanArmMT', params);
}
}

export class TargetLocMT extends AbstractRequest {

/**
* Constructs an TargetLocMT mission task.
*
* @param {Object} params parameters.
*/
constructor(params) {
super('org.arl.jc2.mtt.TargetLocMT', params);
}
}
115 changes: 95 additions & 20 deletions experiments/WebUI/src/components/content/MLegInfoComponent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import React from 'react';
import { StyleSheet, css } from 'aphrodite';
import { Table, ListGroup, Tab, FormControl, Button } from 'react-bootstrap';

import { Table, ListGroup, Tab, FormControl, Button, Form } from 'react-bootstrap';

const MissionTypes = [
"BioCastMT",
"CoopPosMT",
"LawnMowerMT",
"SimpleMT",
"StationKeepingMT",
"SwanArmMT",
"TargetLocMT",
"WaterSampleMT",
];

const styles = StyleSheet.create({
MLegInfoContainer: {
Expand Down Expand Up @@ -76,32 +86,45 @@ class MLegInfoComponent extends React.Component {
this.modifyEditedMissionsArr();
}

onMissionTaskEdit(e) {
var missionLeg = this.state.missionLeg;
this.state.missionLeg[e.target.name] = e.target.value;
this.setState({
missionLeg: missionLeg
});
this.modifyEditedMissionsArr();
}

onMissionTypeChange(e) {
// console.log(e.target.value);
this.props.changeMissionType(e.target.value);
this.modifyEditedMissionsArr();
}

render() {
var propertyTableRows = [];
var paramTableRows = [];
var payloadObject = {};
var missionTaskTableRows = [];

// var actionButtons = null;
if (this.state.missionLeg !== null) {

//Property table - TODO currently hard coded, find better way to do this.
propertyTableRows.push(
<tr>
<td>x</td>
<td><FormControl name="x" onChange={(e) => this.onPropertyChange(e)} value={this.state.missionLeg.mp.x}></FormControl></td>
</tr>
);
propertyTableRows.push(
<tr>
<td>y</td>
<td><FormControl name="y" onChange={(e) => this.onPropertyChange(e)} value={this.state.missionLeg.mp.y}></FormControl></td>
</tr>
);
propertyTableRows.push(
<tr>
<td>z</td>
<td><FormControl name="z" onChange={(e) => this.onPropertyChange(e)} value={this.state.missionLeg.mp.z}></FormControl></td>
</tr>
);

var missionPoint = this.state.missionLeg.mp;
for (var key in missionPoint) {
if (missionPoint.hasOwnProperty(key)) {
if (key === "x" || key === "y" || key === "z") {
propertyTableRows.push(
<tr>
<td>{key}</td>
<td><FormControl name={key} onChange={(e) => this.onPropertyChange(e)} value={this.state.missionLeg.mp[key]}></FormControl></td>
</tr>
);
}
}
}

// console.log(this.state.missionLeg);
var params = this.state.missionLeg.mp.params;
Expand All @@ -118,6 +141,41 @@ class MLegInfoComponent extends React.Component {
}

payloadObject = this.state.missionLeg.payload;
var MissionTypeOptions = [];

var missionTaskObject = this.state.missionLeg;
var selectedType = missionTaskObject.taskID.substring(0, missionTaskObject.taskID.indexOf("MT") + 2);
MissionTypes.forEach((missionType) => {
if (missionType === selectedType) {
MissionTypeOptions.push(<option selected>{missionType}</option>);
} else {
MissionTypeOptions.push(<option>{missionType}</option>);
}
});

for (var key in missionTaskObject) {
if (missionTaskObject.hasOwnProperty(key)) {
if (key == "taskID") {
missionTaskTableRows.push(
<tr>
<td>Task Type</td>
<td>
<Form.Control as="select" onChange={(e) => this.onMissionTypeChange(e)}>
{MissionTypeOptions}
</Form.Control>
</td>
</tr>
);
} else if (key !== "mp" && key !== "payload") {
missionTaskTableRows.push(
<tr>
<td>{key}</td>
<td><FormControl name={key} onChange={(e) => this.onMissionTaskEdit(e)} value={this.state.missionLeg[key]}></FormControl></td>
</tr>
);
}
}
}
}

const Properties =
Expand Down Expand Up @@ -150,13 +208,27 @@ class MLegInfoComponent extends React.Component {
<div>
<FormControl onChange={(e) => this.onPayloadChange(e)} value={JSON.stringify(payloadObject, null, 0)}></FormControl>
</div>;

const MissionTask = <Table striped bordered hover>
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{missionTaskTableRows}
</tbody>
</Table>;

return (
<div className={css(styles.MLegInfoContainer)}>
<Tab.Container id="list-group-tabs-example" defaultActiveKey="#Parameters">
<ListGroup horizontal>
<ListGroup.Item action href="#Property">Property</ListGroup.Item>
<ListGroup.Item action href="#Parameters">Parameters</ListGroup.Item>
<ListGroup.Item action href="#Payload">Payload</ListGroup.Item>
<ListGroup.Item action href="#MissionTask">Mission Task</ListGroup.Item>
</ListGroup>

<Tab.Content>
Expand All @@ -169,6 +241,9 @@ class MLegInfoComponent extends React.Component {
<Tab.Pane eventKey="#Payload">
{Payload}
</Tab.Pane>
<Tab.Pane eventKey="#MissionTask">
{MissionTask}
</Tab.Pane>
</Tab.Content>
</Tab.Container>
{/* {actionButtons} */}
Expand Down
104 changes: 94 additions & 10 deletions experiments/WebUI/src/components/content/MapComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import '../../assets/MissionPlanner.css';
import CoordSys from '../../assets/CoordSys.js';

import { FjageHelper } from "../../assets/fjageHelper.js";
import { Management, TargetLocMT } from "../../assets/jc2.js";
import { Management } from "../../assets/jc2.js";
import { mapPin, mapPinSelected, readyMarker, notReadyMarker } from "../../assets/MapIcons.js";
// import ManualCommands from '../../assets/ManualCommands.js';
import ToolbarComponent from '../ToolbarComponent';
Expand Down Expand Up @@ -66,13 +66,27 @@ function MissionTask() {
this.payload = {};
}

function SimpleMT() {
this.taskID = "SimpleMT";
this.endHeading = 0.0;
function BioCastMT() {
this.taskID = "BioCastMT";
this.SourceSLevel = 0.0;
this.mtTime = 0;
this.resamplingTime = 0;
this.sourceX = 0.0;
this.sourceY = 0.0;
MissionTask.call(this);
}

function CoopPosMT() {
this.taskID = "CoopPosMT";
this.lookAheadLevel = [];
this.missionNum = [];
this.numOfSurveyAuv = 0;
this.posInterval = [];
this.vehicleID = [];
MissionTask.call(this);
}

function LawnMoverMT() {
function LawnMowerMT() {
this.taskID = "LawnMoverMT";
this.xLength = 0.0;
this.yLength = 0.0;
Expand All @@ -81,6 +95,38 @@ function LawnMoverMT() {
MissionTask.call(this);
}

function SimpleMT() {
this.taskID = "SimpleMT";
this.endHeading = 0.0;
MissionTask.call(this);
}

function StationKeepingMT() {
this.taskID = "StationKeepingMT";
this.duration = 0.0;
MissionTask.call(this);
}

function SwanArmMT() {
this.taskID = "SwanArmMT";
this.armDepth = {};
this.missionTaskTimeout = {};
this.reposeBehavior = {};
MissionTask.call(this);
}

function TargetLocMT() {
this.taskID = "TargetLocMT";
this.mtTimeOut = 0;
MissionTask.call(this);
}

function WaterSampleMT() {
this.taskID = "WaterSampleMT";
this.armDepth = 0.0;
MissionTask.call(this);
}

class MapComponent extends React.Component {
constructor(props, context) {
super(props, context);
Expand Down Expand Up @@ -173,6 +219,8 @@ class MapComponent extends React.Component {
this.abortMission = this.abortMission.bind(this);
this.stationKeep = this.stationKeep.bind(this);
this.goHome = this.goHome.bind(this);

this.changeMissionType = this.changeMissionType.bind(this);
}

componentDidMount() {
Expand Down Expand Up @@ -303,9 +351,6 @@ class MapComponent extends React.Component {
positionError: this.state.positionError - 1
})},
200);

var x = new TargetLocMT();
console.log(x);
}

componentDidUpdate() {
Expand Down Expand Up @@ -596,7 +641,6 @@ class MapComponent extends React.Component {
}

dragEndGeoFenceMarker(e) {
// console.log(e);
var newlat = e.target._latlng.lat;
var newlng = e.target._latlng.lng;
var oldlat = e.target.options.position[0];
Expand Down Expand Up @@ -685,6 +729,46 @@ class MapComponent extends React.Component {
this.management.abortToHome();
}

changeMissionType(missionLegIndex, newType) {
var currentMissionArr = this.state.currentMission;

var constructorName = newType + "()";
// var mission_task = new window[constructorName]();
var mission_task;
if (newType === "BioCastMT") {
mission_task = new BioCastMT();
} else if (newType === "CoopPosMT") {
mission_task = new CoopPosMT();
} else if (newType === "LawnMowerMT") {
mission_task = new LawnMowerMT();
} else if (newType === "StationKeepingMT") {
mission_task = new StationKeepingMT();
} else if (newType === "SwanArmMT") {
mission_task = new SwanArmMT();
} else if (newType === "TargetLocMT") {
mission_task = new TargetLocMT();
} else if (newType === "WaterSampleMT") {
mission_task = new WaterSampleMT();
} else {
mission_task = new SimpleMT();
}

var missions = this.state.missions;
console.log(mission_task);
var oldMissionTask = missions[this.state.missionNumber][missionLegIndex - 1];
console.log(oldMissionTask);

mission_task.mp = oldMissionTask.mp;
mission_task.payload = oldMissionTask.payload;


missions[this.state.missionNumber][missionLegIndex - 1] = mission_task;

this.setState({
missions: missions
});
}

render() {
const position = [this.state.vehiclePosition.latitude, this.state.vehiclePosition.longitude];
const mapCenter = [this.state.mapCenter.latitude, this.state.mapCenter.longitude];
Expand Down Expand Up @@ -767,7 +851,7 @@ class MapComponent extends React.Component {

const MissionPlannerPanels = (this.state.MissionPlannerEnabled) ?
<Row>
<MissionTreeViewComponent ref="missionTreeView" selectMissionPointFunc={this.selectMissionPoint} viewMissionFunc={this.viewMission} missions={this.state.missions} editedMissions={this.state.editedMissions} management={this.management}/>
<MissionTreeViewComponent ref="missionTreeView" selectMissionPointFunc={this.selectMissionPoint} viewMissionFunc={this.viewMission} changeMissionType={this.changeMissionType} missions={this.state.missions} editedMissions={this.state.editedMissions} management={this.management}/>
</Row> :
null;

Expand Down
Loading

0 comments on commit 3fb1e87

Please sign in to comment.