Skip to content

Commit

Permalink
Pre-test updates
Browse files Browse the repository at this point in the history
Decided will not fix #65 and #70 as those are actually more difficult to implement than expected.

Will test this branch more to see basic functionality and then will merge to dev-2018 and then to master
  • Loading branch information
Luis729 committed May 4, 2019
1 parent 34054c2 commit 9593f74
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 53 deletions.
1 change: 1 addition & 0 deletions src/common/MessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class MessageHandler {
const onDisconnect = (): void => {
clearInterval(expiry);
this.sending.delete(jsonMessage.tid);
this.outbox.clear(`${jsonMessage.tid}`);
ipc.postDisconnectFromVehicle(jsonMessage.tid);
};

Expand Down
22 changes: 14 additions & 8 deletions src/common/Orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ class Orchestrator {
status: 'ready',
});

this.ping(this.vehicles[jsonMessage.sid]);
setTimeout(
(): void => this.ping(this.vehicles[jsonMessage.sid]),
config.vehicleDisconnectionTime * 1000,
);
} else {
this.vehicles[jsonMessage.sid].connect();
}
Expand All @@ -142,11 +145,14 @@ class Orchestrator {
* @param vehicle Vehicle to "ping".
*/
private ping(vehicle: Vehicle): void {
const delta = Date.now() - vehicle.getLastConnectionTime();
const delta = Math.abs(Date.now() - vehicle.getLastConnectionTime());

if (delta >= 0 && delta <= config.vehicleDisconnectionTime * 1000) {
// Handler that expires and creates itself everytime it "pings" the vehicle.
setTimeout((): void => { this.ping(vehicle); }, delta);
setTimeout(
(): void => { this.ping(vehicle); },
config.vehicleDisconnectionTime * 1000 - delta,
);
} else {
this.disconnectFromVehicle(vehicle.getVehicleId());
}
Expand Down Expand Up @@ -358,12 +364,12 @@ class Orchestrator {
this.stopMissions();
} else {
this.missions[this.currentMissionIndex + 1].parameters = completionParameters;
}

if (this.requireConfirmation) {
ipc.postConfirmCompleteMission(); // Start next mission on "startNextMission" notification.
} else {
this.startNextMission();
if (this.requireConfirmation) {
ipc.postConfirmCompleteMission(); // Start next mission on "startNextMission" notification.
} else {
this.startNextMission();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/Xbee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { JSONMessage } from '../types/message';
import ipc from '../util/ipc';

// TODO: Add a feature with Vehicle container to change this dynamically and reconnect.
const port: string | undefined = 'COM5';
const port: string | undefined = '/dev/tty.SLAB_USBtoUART';

const serialport = new SerialPort(port, { baudRate: 57600 }, (error): void => {
if (error) {
Expand Down
40 changes: 3 additions & 37 deletions src/common/missions/PayloadDrop.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import DictionaryList from '../struct/DictionaryList';
import Mission from '../struct/Mission';

import { JobType, Location } from '../../static/index';
import { JobType } from '../../static/index';

import * as Message from '../../types/message';
import * as MissionInformation from '../../types/missionInformation';
import { Task, TaskParameters } from '../../types/task';

import ipc from '../../util/ipc';

export const missionName: MissionInformation.MissionName = 'payloadDrop';

export const jobTypes: JobType[] = ['payloadDrop'];
Expand All @@ -20,11 +17,6 @@ export class PayloadDrop extends Mission {

protected addTaskCompare = {};

/**
* Point of interest.
*/
private missionData: Location | null = null;

protected generateTasks(): DictionaryList<Task> | undefined {
const information = this.information as MissionInformation.PayloadDropInformation;
const missionParameters = information.parameters;
Expand Down Expand Up @@ -54,35 +46,9 @@ export class PayloadDrop extends Mission {
return tasks;
}

public update(jsonMessage: Message.JSONMessage): void {
super.update(jsonMessage);

if (Message.TypeGuard.isPOIMessage(jsonMessage)
&& this.activeVehicleMapping[this.missionName][jsonMessage.sid] === 'payloadDrop') {
const poiMessage = jsonMessage as Message.POIMessage;
this.missionData = {
lat: poiMessage.lat,
lng: poiMessage.lng,
};
}
}

// eslint-disable-next-line class-methods-use-this
protected generateCompletionParameters(): { [key: string]: TaskParameters } | undefined {
if (!this.missionData) {
ipc.postLogMessages({
type: 'failure',
message: 'No target location was provided in payload drop',
});
return undefined; // Mission will stop from this, not complete.
}

return {
retrieveTarget: {
lat: this.missionData.lat,
lng: this.missionData.lng,
},
// TODO: generate data for deliverTarget
};
return {};
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/common/struct/Mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ export default abstract class Mission {
this.waitingVehicles.push(jobType, vehicle);
});

const allVehiclesWaiting = pendingAssignVehicleIds.some(
(vehicleId): boolean => this.vehicles[vehicleId].getStatus() !== 'waiting',
const allVehiclesWaiting = pendingAssignVehicleIds.every(
(vehicleId): boolean => this.vehicles[vehicleId].getStatus() === 'waiting',
);

if (!allVehiclesWaiting) {
Expand Down Expand Up @@ -333,6 +333,8 @@ export default abstract class Mission {
if (Message.TypeGuard.isCompleteMessage(jsonMessage)) {
const jobType = this.activeVehicleMapping[this.missionName][jsonMessage.sid];

ipc.postLogMessages({ message: `Finished a task for ${this.missionName}` });

/*
* Mission is not yet finished, continue to assign tasks. One of the following will happen:
* 1. Assigns next task to vehicle.
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/missionWindow/parameter/PayloadDrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ export class PayloadDrop extends Component<PayloadDropProps, State> {
<p>Payload Drop Coordinates</p>
<input className="inputFields" type="number" name="payloadDropLat1" value={checklist.payloadDropLat1 || ''} disabled={locked.payloadDrop1} onChange={this.onChange} placeholder="Latitude" />
<input className="inputFields" type="number" name="payloadDropLng1" value={checklist.payloadDropLng1 || ''} disabled={locked.payloadDrop1} onChange={this.onChange} placeholder="Longitude" />
<input className="inputFields" type="number" name="payloadDropAlt" value={checklist.payloadDropAlt1 || ''} disabled={locked.payloadDrop1} onChange={this.onChange} placeholder="Altitude" />
<input className="inputFields" type="number" name="payloadDropAlt1" value={checklist.payloadDropAlt1 || ''} disabled={locked.payloadDrop1} onChange={this.onChange} placeholder="Altitude" />
<CreateWaypointButton theme={theme} name="payloadDrop1" value="Payload Drop 1" />
<br />
<input className="inputFields" type="number" name="payloadDropLat2" value={checklist.payloadDropLat2 || ''} disabled={locked.payloadDrop2} onChange={this.onChange} placeholder="Latitude" />
<input className="inputFields" type="number" name="payloadDropLng2" value={checklist.payloadDropLng2 || ''} disabled={locked.payloadDrop2} onChange={this.onChange} placeholder="Longitude" />
<input className="inputFields" type="number" name="payloadDropAlt" value={checklist.payloadDropAlt2 || ''} disabled={locked.payloadDrop2} onChange={this.onChange} placeholder="Altitude" />
<input className="inputFields" type="number" name="payloadDropAlt2" value={checklist.payloadDropAlt2 || ''} disabled={locked.payloadDrop2} onChange={this.onChange} placeholder="Altitude" />
<CreateWaypointButton theme={theme} name="payloadDrop2" value="Payload Drop 2" />

<p>Land Waypoints</p>
Expand Down
7 changes: 6 additions & 1 deletion src/static/location.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"startLocation": "Cal Poly SLO",
"startLocation": "Prado Airpark",
"locations": {
"Cal Poly SLO": {
"lat": 35.306205,
Expand All @@ -10,6 +10,11 @@
"lat": 34.055869,
"lng": -117.819964,
"zoom": 18
},
"Prado Airpark": {
"lat": 33.9325635,
"lng": -117.6288792,
"zoom": 18
}
}
}
4 changes: 2 additions & 2 deletions src/static/vehicle.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
"type": "station"
},
"100": {
"macAddress": "",
"macAddress": "0013A200419477B6",
"name": "Skywalker",
"type": "plane"
},
"101": {
"macAddress": "",
"name": "Piper Club",
"name": "Piper Cub",
"type": "plane"
},
"200": {
Expand Down

0 comments on commit 9593f74

Please sign in to comment.