Skip to content

Commit

Permalink
Merge e3e8292 into e82c5e0
Browse files Browse the repository at this point in the history
  • Loading branch information
rSchwartz1 committed Mar 12, 2020
2 parents e82c5e0 + e3e8292 commit c4ad1ac
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 36 deletions.
5 changes: 0 additions & 5 deletions src/common/struct/Vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,6 @@ export default class Vehicle {
this.sendMessage({
type: 'start',
jobType,
geofence: {
topLeft: [0, 0],
botRight: [0, 0],
keepOut: true,
},
});

this.updateEventHandler.addHandler<VehicleStatus>('status', (value): boolean => {
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/mainWindow/map/MapContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default class MapContainer extends Component<ThemeProps, State> {
*/
private ref: React.RefObject<Map>;


public constructor(props: ThemeProps) {
super(props);

Expand Down Expand Up @@ -318,7 +319,7 @@ export default class MapContainer extends Component<ThemeProps, State> {
boundingBoxes.forEach((boundingBox): void => {
if (!newBoundingBoxes[boundingBox.name]) {
newBoundingBoxes[boundingBox.name] = {
color: boundingBox.color || 'red',
color: boundingBox.color || 'blue',
bounds: boundingBox.bounds || (viewport.center && {
top: viewport.center[0],
bottom: viewport.center[0],
Expand Down
79 changes: 76 additions & 3 deletions src/renderer/missionWindow/MissionWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ const title: { [missionName in MissionInformation.MissionName]: string } = {
uuvRescue: 'UUV Rescue',
};

type GeofenceChecklistType = 'geofenceTop' | 'geofenceLeft' | 'geofenceRight' | 'geofenceBottom';
type GeofenceChecklistType = 'geofenceTop' | 'geofenceLeft' | 'geofenceRight' | 'geofenceBottom' | 'geofenceTop2' | 'geofenceLeft2' | 'geofenceRight2' | 'geofenceBottom2';

const checklistCache: { [check in GeofenceChecklistType ]: number | undefined} = {
geofenceTop: undefined,
geofenceLeft: undefined,
geofenceRight: undefined,
geofenceBottom: undefined,
geofenceTop2: undefined,
geofenceLeft2: undefined,
geofenceRight2: undefined,
geofenceBottom2: undefined,
};

type Locked = {
Expand Down Expand Up @@ -271,6 +275,54 @@ export default class MissionWindow extends Component<ThemeProps, State> {
});
break;

case 'geofenceTop2':
ipc.postUpdateBoundingBoxes(true, {
name: 'Geofencing2',
bounds: {
top: value,
bottom: checklist.geofenceBottom2 as number,
left: checklist.geofenceLeft2 as number,
right: checklist.geofenceRight2 as number,
},
});
break;

case 'geofenceLeft2':
ipc.postUpdateBoundingBoxes(true, {
name: 'Geofencing2',
bounds: {
top: checklist.geofenceTop2 as number,
bottom: checklist.geofenceBottom2 as number,
left: value,
right: checklist.geofenceRight2 as number,
},
});
break;

case 'geofenceRight2':
ipc.postUpdateBoundingBoxes(true, {
name: 'Geofencing2',
bounds: {
top: checklist.geofenceTop2 as number,
bottom: checklist.geofenceBottom2 as number,
left: checklist.geofenceLeft2 as number,
right: value,
},
});
break;

case 'geofenceBottom2':
ipc.postUpdateBoundingBoxes(true, {
name: 'Geofencing2',
bounds: {
top: checklist.geofenceTop2 as number,
bottom: value,
left: checklist.geofenceLeft2 as number,
right: checklist.geofenceRight2 as number,
},
});
break;

default:
this.updateChecklist({ [name]: value });
break;
Expand Down Expand Up @@ -375,6 +427,13 @@ export default class MissionWindow extends Component<ThemeProps, State> {
checks.geofenceBottom = boxpoint.bounds.bottom;
break;

case 'Geofencing2':
checks.geofenceTop2 = boxpoint.bounds.top;
checks.geofenceRight2 = boxpoint.bounds.right;
checks.geofenceLeft2 = boxpoint.bounds.left;
checks.geofenceBottom2 = boxpoint.bounds.bottom;
break;

default: break;
}
});
Expand Down Expand Up @@ -450,6 +509,9 @@ export default class MissionWindow extends Component<ThemeProps, State> {
if (waypointType === 'geofence') {
newLocked.geofence = false;
}
if (waypointType === 'geofence2') {
newLocked.geofence = false;
}

this.setState({ locked: newLocked });
}
Expand Down Expand Up @@ -517,15 +579,26 @@ export default class MissionWindow extends Component<ThemeProps, State> {
<MissionOptions title={title} missionNames={missionNames} options={options} />
</div>
<div className="geofenceContainer">
<h1>Geofencing</h1>
<h1>Keep-IN</h1>
<input className="inputFields" type="number" name="geofenceScanTop" value={checklist.geofenceTop || ''} disabled={locked.geofence} onChange={this.onChange} placeholder="Top" />
<br />
<input className="inputFields" type="number" name="geofenceBottom" value={checklist.geofenceBottom || ''} disabled={locked.geofence} onChange={this.onChange} placeholder="Bottom" />
<br />
<input className="inputFields" type="number" name="geofenceLeft" value={checklist.geofenceLeft || ''} disabled={locked.geofence} onChange={this.onChange} placeholder="Left" />
<br />
<input className="inputFields" type="number" name="geofenceRight" value={checklist.geofenceRight || ''} disabled={locked.geofence} onChange={this.onChange} placeholder="Right" />
<CreateBoundingBoxButton theme={theme} name="geofence" value="Geofencing" />
<CreateBoundingBoxButton theme={theme} name="geofence" value="Geofencing" color="green" />
</div>
<div className="geofenceContainer2">
<h1>Keep-OUT</h1>
<input className="inputFields" type="number" name="geofenceScanTop" value={checklist.geofenceTop2 || ''} disabled={locked.geofence} onChange={this.onChange} placeholder="Top" />
<br />
<input className="inputFields" type="number" name="geofenceBottom" value={checklist.geofenceBottom2 || ''} disabled={locked.geofence} onChange={this.onChange} placeholder="Bottom" />
<br />
<input className="inputFields" type="number" name="geofenceLeft" value={checklist.geofenceLeft2 || ''} disabled={locked.geofence} onChange={this.onChange} placeholder="Left" />
<br />
<input className="inputFields" type="number" name="geofenceRight" value={checklist.geofenceRight2 || ''} disabled={locked.geofence} onChange={this.onChange} placeholder="Right" />
<CreateBoundingBoxButton theme={theme} name="geofence2" value="Geofencing2" color="red" />
</div>
<div className="buttonContainer">
{status === 'ready' && <button type="button" disabled={!unlockStartMissionButton} onClick={this.postStartMissions}>Start Missions</button>}
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/missionWindow/extra/CreateBoundingBoxButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface CreateBoundingBoxButtonProps extends ThemeProps{
* Name of the box itself, when it shows up on the map.
*/
value: string;

color: string;
}

export default class CreateBoundingBoxButton extends PureComponent<CreateBoundingBoxButtonProps> {
Expand All @@ -23,9 +25,9 @@ export default class CreateBoundingBoxButton extends PureComponent<CreateBoundin
}

private onClick(): void {
const { name, value } = this.props;
const { name, value, color } = this.props;
ipc.postUnlockParameterInputs(name);
ipc.postCreateBoundingBoxes({ name: value });
ipc.postCreateBoundingBoxes({ name: value, color });
}

public render(): ReactNode {
Expand Down
11 changes: 8 additions & 3 deletions src/renderer/missionWindow/mission.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
'parameter parameter parameter mapping'
'parameter parameter parameter mapping'
'parameter parameter parameter mapping'
'geofence geofence geofence options'
'geofence geofence geofence options'
'geofence geofence geofence2 options'
'geofence geofence geofence2 options'
'button button button options';
grid-template-rows: 25px 1fr 1fr 0.8fr 1fr 0.3fr 25px;
grid-template-rows: 25px 1fr 1fr 1fr 1fr 0.2fr 25px;
grid-template-columns: repeat(4, 1fr);
}

Expand All @@ -32,6 +32,11 @@
padding-left: 20px;
}

.geofenceContainer2 {
grid-area: geofence2;
padding-left: 20px;
}

.mappingContainer {
grid-area: mapping;
padding-left: 20px;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/missionWindow/parameter/VTOLSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class VTOLSearch extends Component<VTOLSearchProps, State> {
<input className="inputFields" type="number" name="quickScanLeft" value={checklist.quickScanLeft || ''} disabled={locked.quickScan} onChange={this.onChange} placeholder="Left" />
<br />
<input className="inputFields" type="number" name="quickScanRight" value={checklist.quickScanRight || ''} disabled={locked.quickScan} onChange={this.onChange} placeholder="Right" />
<CreateBoundingBoxButton theme={theme} name="quickScan" value="Bounding Box" />
<CreateBoundingBoxButton theme={theme} name="quickScan" value="Bounding Box" color="blue" />
</div>
);
}
Expand Down
52 changes: 31 additions & 21 deletions src/types/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,42 @@ interface MessageBase {
}

// Definitions for all messages from GCS to vehicles.

export interface StartMessage extends MessageBase {
type: 'start';
export interface GeofenceMessage extends MessageBase {
type: 'geofence';

/**
* Name of job to perform.
*/
jobType: JobType;

/**
* Geofencing coordinates in the form of a rectangle, and geofence type sent with start message.
* Geofencing coordinates in the form of a rectangle, and geofence type sent
along with start message.
*/
geofence: {
geofence?: {
'keepOut': [number, number][],
'keepIn': [number, number][]
}

}

export interface StartMessage extends MessageBase {
type: 'start';

/**
* Top Left coordinate of geofencing rectangle, in form of latitude, longitude.
*/
topLeft: [number, number];

/**
* Bottom right coordinate of geofencing rectangle, in form of latitude, longitude.
*/
botRight: [number, number];
/**
* Name of job to perform.
*/
jobType: JobType;
}

/**
* Boolean to specify whether geofence is keep out type (true), or keep in type (false).
*/
keepOut: boolean;
};

/**
* Type guard for Geofence Message.
*/
function isGeofenceMessage(message: Message): boolean {
return message.type === 'geofence'
&& vehicleConfig.isValidJobType(message.jobType);
}

/**
Expand Down Expand Up @@ -280,9 +286,11 @@ export function isBadMessage(message: Message): boolean {
/**
* All types of messages sent to and from the GCS.
*/
export type Message = StartMessage | AddMissionMessage | PauseMessage | ResumeMessage | StopMessage
| ConnectionAckMessage | UpdateMessage | POIMessage | CompleteMessage | ConnectMessage
| AcknowledgementMessage | BadMessage;

export type Message = GeofenceMessage | StartMessage | AddMissionMessage
| PauseMessage | ResumeMessage | StopMessage | ConnectionAckMessage |
UpdateMessage | POIMessage | CompleteMessage
| ConnectMessage | AcknowledgementMessage | BadMessage;

/**
* Simply checks if the message has a valid type field. This is different from the type
Expand All @@ -293,6 +301,7 @@ export type Message = StartMessage | AddMissionMessage | PauseMessage | ResumeMe
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isMessage(message: { [key: string]: any }): boolean {
return message.type && typeof message.type === 'string' && [
'geofence',
'start',
'addMission',
'pause',
Expand Down Expand Up @@ -343,6 +352,7 @@ export function isJSONMessage(message: { [key: string]: any }): boolean {
* Type guards for a message.
*/
export const TypeGuard = {
isGeofenceMessage,
isStartMessage,
isAddMissionMessage,
isPauseMessage,
Expand Down

0 comments on commit c4ad1ac

Please sign in to comment.