Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Commit

Permalink
[sim] new obstacle interface for 2D sim (#1108)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljiang520 authored Jun 1, 2022
1 parent c56f477 commit 82af902
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 205 deletions.
7 changes: 7 additions & 0 deletions rover_msgs/ObstacleList.lcm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package rover_msgs;

//+x is to the right of camera, +y is down from camera, +z is forward (out) from the camera
struct ObstacleList {
int32_t numObstacles;
Obstacle obstacles[numObstacles];
}
13 changes: 11 additions & 2 deletions simulators/nav/src/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module.exports = {
sourceType: 'module',
ecmaVersion: 2020,
},
"plugins": [
"@typescript-eslint"
],
"settings": {
"import/resolver": {
"node": {
Expand Down Expand Up @@ -41,6 +44,7 @@ module.exports = {
"camelcase": ["error", {
"allow": [
"bearing_deg",
"bottom_left_coordinate_meters",
"completed_wps",
"forward_back",
"gate_width",
Expand All @@ -54,7 +58,9 @@ module.exports = {
"num_waypoints",
"path_type",
"pattern_size",
"obstacle_list",
"signal_strength",
"top_right_coordinate_meters",
"total_wps"
]
}],
Expand Down Expand Up @@ -132,7 +138,7 @@ module.exports = {
"no-multi-spaces": "off",
"no-multiple-empty-lines": ["error", { "max": 2 }],
"no-new": "error",
"no-param-reassign": "error",
"no-param-reassign": 0,
"no-redeclare": "error",
"no-return-assign": "error",
"no-shadow": "error",
Expand Down Expand Up @@ -219,6 +225,7 @@ module.exports = {
"@typescript-eslint/camelcase": ["error", {
"allow": [
"bearing_deg",
"bottom_left_coordinate_meters",
"completed_wps",
"forward_back",
"gate_width",
Expand All @@ -232,7 +239,9 @@ module.exports = {
"num_waypoints",
"path_type",
"pattern_size",
"obstacle_list",
"signal_strength",
"top_right_coordinate_meters",
"total_wps"
]
}],
Expand All @@ -245,7 +254,7 @@ module.exports = {
{
"files": ["store/modules/*State.ts"],
"rules": {
"no-param-reassign": "off"
"no-param-reassign": 0
}
},
{
Expand Down
5 changes: 5 additions & 0 deletions simulators/nav/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ The `utils` directory contains code that is reused throughout the project. This

---

<!----------------------------- Related Documents ---------------------------->
## Important Note
* ObstacleMessage is ahead of nav and perception right as of May 28, 2022. This version is sending the bounding box of each obstacle via ObstacleList.lcm in the /obstacle_list channel. As long as when running the 2d sim, obstacle is OFF it doesn't cause the sim the crash
---

<!----------------------------- Related Documents ---------------------------->
## Related Documents
* [project `README`](../README.md)
Expand Down
24 changes: 16 additions & 8 deletions simulators/nav/src/components/NavSimulator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ import {
TargetListMessage,
Waypoint,
ZedGimbalPosition,
Point2D,
ProjectedPointsMessage
ProjectedPointsMessage,
Point2D
} from '../utils/types';
import ControlPanel from './control_panel/ControlPanel.vue';
import Field from './field/Field.vue';
Expand Down Expand Up @@ -396,7 +396,7 @@ export default class NavSimulator extends Vue {
this.navPulse = true;
this.setNavStatus(msg.message);
}
else if (msg.topic === '/obstacle') {
else if (msg.topic === '/obstacle_list') {
if (!this.simulatePercep) {
this.percepPulse = true;
this.setObstacleMessage(msg.message);
Expand Down Expand Up @@ -442,13 +442,13 @@ export default class NavSimulator extends Vue {
{ topic: '/autonomous', type: 'Joystick' },
{ topic: '/auton_drive_control', type: 'AutonDriveControl' },
{ topic: '/nav_status', type: 'NavStatus' },
{ topic: '/obstacle', type: 'Obstacle' },
{ topic: '/obstacle_list', type: 'ObstacleList' },
{ topic: '/odometry', type: 'Odometry' },
{ topic: '/rr_drop_init', type: 'RepeaterDropInit' },
{ topic: '/target_list', type: 'TargetList' },
{ topic: '/zed_gimbal_cmd', type: 'ZedGimbalPosition' },
{ topic: '/debugMessage', type: 'DebugMessage' },
{ topic: '/projected_points', type: 'ProjectedPoints' }
{ topic: '/projected_points', type: 'ProjectedPoints' },
{ topic: '/debugMessage', type: 'DebugMessage' }
]
);

Expand All @@ -462,8 +462,16 @@ export default class NavSimulator extends Vue {
}

if (this.simulatePercep) {
const obs:any = Object.assign(this.obstacleMessage, { type: 'Obstacle' });
this.publish('/obstacle', obs, true);
const obs:any = {
type: 'ObstacleList',
numObstacles: this.obstacleMessage.obstacles.length,
obstacles: this.obstacleMessage.obstacles.map((o) => ({
type: 'Obstacle',
bottom_left_coordinate_meters: o.bottom_left_coordinate_meters,
top_right_coordinate_meters: o.top_right_coordinate_meters
}))
};
this.publish('/obstacle_list', obs, true);

/* eslint no-magic-numbers: ["error", { "ignore": [0, 1] }] */
const targetList:any = { targetList: this.targetList, type: 'TargetList' };
Expand Down
13 changes: 5 additions & 8 deletions simulators/nav/src/components/field/Field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ import {
ProjectedPointsMessage,
Waypoint,
WaypointDrawOptions,
ZedGimbalPosition
ZedGimbalPosition,
ObstacleField
} from '../../utils/types';
import { canvasToOdom } from '../../utils/utils';
import CanvasArTags from './ar_tags';
Expand Down Expand Up @@ -171,10 +172,10 @@ export default class Field extends Vue {
private readonly obstacleDrawOptions!:ObstacleDrawOptions;

@Getter
private readonly obstacles!:Obstacle[];
private readonly projectedPointsMessage!:ProjectedPointsMessage;

@Getter
private readonly projectedPointsMessage!:ProjectedPointsMessage;
private readonly obstacles!:ObstacleField[];

@Getter
private readonly referencePoints!:Odom[];
Expand Down Expand Up @@ -219,7 +220,7 @@ export default class Field extends Vue {
private readonly pushGate!:(newGate:Gate)=>void;

@Mutation
private readonly pushObstacle!:(newObstacle:Obstacle)=>void;
private readonly pushObstacle!:(newObstacle:ObstacleField)=>void;

@Mutation
private readonly pushReferencePoint!:(newReferencePoint:Odom)=>void;
Expand Down Expand Up @@ -433,8 +434,6 @@ export default class Field extends Vue {
if (!this.autonOn) {
this.setCurrOdom(newCurrOdom);
this.clearRoverPath();

// this.clearFOVAreaPath();
}
} /* moveRover() */

Expand All @@ -444,8 +443,6 @@ export default class Field extends Vue {
this.setStartLoc(newStartLoc);
this.setCurrOdom(newStartLoc);
this.clearRoverPath();

// this.clearFOVAreaPath();
}
} /* moveStartLoc() */

Expand Down
24 changes: 12 additions & 12 deletions simulators/nav/src/components/field/obstacles.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
/* This file contains the CanvasObstacles class for drawing obstacles on the
canvas. */
canvas. */

import { odomToCanvas } from '../../utils/utils';
import { Obstacle, Odom, Point2D } from '../../utils/types';
import { ObstacleField, Odom, Point2D } from '../../utils/types';

/**************************************************************************************************
* Constants
**************************************************************************************************/
* Constants
**************************************************************************************************/
/* Space needed to draw label inside obstacle in pixels. */
const LABEL_SPACE_REQUIRED = 30;

/* Class for drawing obstacles on the field canvas. */
export default class CanvasObstacles {
/************************************************************************************************
* Private Members
************************************************************************************************/
* Private Members
************************************************************************************************/
/* GPS point of the center of the canvas */
private canvasCent!:Odom;

/* Canvas context */
private ctx!:CanvasRenderingContext2D;

/* list of all obstacles on field */
private obstacles!:Obstacle[];
private obstacles!:ObstacleField[];

/* scale of the canvas in pixels/meter */
private scale!:number;

/************************************************************************************************
* Public Methods
************************************************************************************************/
* Public Methods
************************************************************************************************/
/* Initialize CanvasObstacles instance. */
constructor(
obstacles:Obstacle[],
obstacles:ObstacleField[],
canvasCent:Odom,
scale:number /* pixels/meter */
) {
Expand Down Expand Up @@ -66,8 +66,8 @@ export default class CanvasObstacles {
} /* drawObstacles() */

/************************************************************************************************
* Private Methods
************************************************************************************************/
* Private Methods
************************************************************************************************/
/* Draw a single obstacle on the canvas. */
private drawObstacle(size:number, label:string):void {
this.ctx.beginPath();
Expand Down
8 changes: 4 additions & 4 deletions simulators/nav/src/components/field_items/ObstacleItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';
import { Mutation } from 'vuex-class';
import { Obstacle, RoverLocationSource } from '../../utils/types';
import { ObstacleField, RoverLocationSource } from '../../utils/types';
import Button from '../common/Button.vue';
import NumberInput from '../common/NumberInput.vue';
import FieldItemInfo from './FieldItemInfo.vue';
Expand Down Expand Up @@ -81,14 +81,14 @@ export default class ObstacleItem extends Vue {
private readonly index!:number;

/* Obstacle represented by this ObstacleItem. */
@Prop({ required: true, type: Object as ()=>Obstacle })
private readonly obstacle!:Obstacle;
@Prop({ required: true, type: Object as ()=>ObstacleField })
private readonly obstacle!:ObstacleField;

/************************************************************************************************
* Vuex Mutations
************************************************************************************************/
@Mutation
private readonly editObstacle!:(updatedObstacle:[Obstacle, number])=>void;
private readonly editObstacle!:(updatedObstacle:[ObstacleField, number])=>void;

@Mutation
private readonly removeObstacle!:(index:number)=>void;
Expand Down
8 changes: 4 additions & 4 deletions simulators/nav/src/components/lcm_center/ObstacleLCM.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<div class="box">
<fieldset class="obstacle">
<legend>Obstacle</legend>
<p>Distance: {{ dist }} m</p>
<p>Bearing: {{ bear }}º</p>
<p>bottom_left_coordinate_meters: {{ dist }} m</p>
<p>top_right_coordinate_meters: {{ bear }}º</p>
</fieldset>
</div>
</template>
Expand All @@ -34,12 +34,12 @@ export default class ObstacleLCM extends Vue {
/* distance to the closest obstacle (if one exists) in the obstacle message
LCM */
private get dist():number {
return Number(this.obstacleMessage.distance.toFixed(2));
return Number(this.obstacleMessage.numObstacles.toFixed(2));
}

/* bearing to turn to in the obstacle message LCM */
private get bear():number {
return Number(this.obstacleMessage.bearing.toFixed(2));
return Number(this.obstacleMessage.numObstacles.toFixed(2));
}
}
</script>
Expand Down
6 changes: 3 additions & 3 deletions simulators/nav/src/components/perception/Perception.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import {
ArTag,
FieldOfViewOptions,
Gate,
Obstacle,
ObstacleMessage,
Odom,
TargetListMessage,
ZedGimbalPosition
ZedGimbalPosition,
ObstacleField
} from '../../utils/types';
import ObstacleDetector from './obstacle_detector';
import TargetDetector from './target_detector';
Expand Down Expand Up @@ -56,7 +56,7 @@ export default class Perception extends Vue {
private readonly gates!:Gate[];

@Getter
private readonly obstacles!:Obstacle[];
private readonly obstacles!:ObstacleField[];

@Getter
private readonly simulatePercep!:boolean;
Expand Down
Loading

0 comments on commit 82af902

Please sign in to comment.