Skip to content

Commit

Permalink
[RSDK 4318] - Obstacle avoidance bugfixes (#2741)
Browse files Browse the repository at this point in the history
  • Loading branch information
micheal-parks authored Aug 4, 2023
1 parent 509771f commit 6036fd0
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 206 deletions.
22 changes: 22 additions & 0 deletions etc/configs/fake.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,28 @@
"movement_sensor": "movement_sensor1",
"base": "base1",
"obstacles": [
{
"location": {
"latitude": 40.6705209,
"longitude": -73.9659182
},
"geometries": [
{
"r": 2000
}
]
},
{
"location": {
"longitude": -73.976472,
"latitude": 40.693268
},
"geometries": [
{
"r": 2000000
}
]
},
{
"geometries": [
{
Expand Down
10 changes: 10 additions & 0 deletions web/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion web/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viamrobotics/remote-control",
"version": "2.0.11",
"version": "2.0.12",
"license": "Apache-2.0",
"type": "module",
"files": [
Expand Down Expand Up @@ -52,6 +52,7 @@
"postcss": "8.4.24",
"svelte": "^4.0.0",
"svelte-check": "^3.4.4",
"svelte-inview": "^4.0.1",
"tailwindcss": "3.3.2",
"three": "0.152.2",
"three-inspect": "0.3.4",
Expand Down
4 changes: 4 additions & 0 deletions web/frontend/src/api/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export const getLocation = async (robotClient: Client, name: string) => {
const lat = location?.getLatitude();
const lng = location?.getLongitude();

rcLogConditionally(response?.getLocation()?.toObject());
rcLogConditionally(location?.getLatitude());
rcLogConditionally(location?.getLongitude());

if (typeof lat !== 'number' || typeof lng !== 'number') {
// eslint-disable-next-line unicorn/prefer-type-error
throw new Error('Unable to locate robot');
Expand Down
13 changes: 7 additions & 6 deletions web/frontend/src/components/base/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
const stop = async () => {
stopped = true;
try {
await baseClient.stop();
} catch (error) {
Expand Down Expand Up @@ -200,17 +201,17 @@
disableViews = liveCameras > 1;
};
const handleVisibilityChange = () => {
// only issue the stop if there are keys pressed as to not interfere with commands issued by scripts/commands
if (document.visibilityState === 'hidden' && pressed.size > 0) {
const handleOnBlur = () => {
if (pressed.size <= 0) {
pressed.clear();
stop();
}
};
const handleOnBlur = () => {
if (pressed.size <= 0) {
stop();
const handleVisibilityChange = () => {
// only issue the stop if there are keys pressed as to not interfere with commands issued by scripts/commands
if (document.visibilityState === 'hidden') {
handleOnBlur();
}
};
Expand Down
80 changes: 66 additions & 14 deletions web/frontend/src/components/motor/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,63 @@ const setMovementType = (event: CustomEvent) => {
};
const setPosition = (event: CustomEvent) => {
position = event.detail.value;
const target = event.currentTarget as HTMLInputElement;
if (event.type === 'blur' && target.value === undefined) {
position = 0;
}
if (target.value === '') {
return;
}
const num = Number.parseFloat(target.value);
if (Number.isNaN(num)) {
return;
}
position = num;
};
const setRpm = (event: CustomEvent) => {
rpm = event.detail.value;
const target = event.currentTarget as HTMLInputElement;
if (event.type === 'blur' && target.value === undefined) {
rpm = 0;
}
if (target.value === '') {
return;
}
const num = Number.parseFloat(target.value);
if (Number.isNaN(num)) {
return;
}
rpm = num;
};
const setRevolutions = (event: CustomEvent) => {
revolutions = event.detail.value;
const target = event.currentTarget as HTMLInputElement;
if (event.type === 'blur' && target.value === undefined) {
revolutions = 0;
}
if (target.value === '') {
return;
}
const num = Number.parseInt(target.value, 10);
if (Number.isNaN(num)) {
return;
}
revolutions = num;
};
const setPowerSlider = (event: CustomEvent) => {
Expand Down Expand Up @@ -167,12 +215,13 @@ const handleToggle = async (event: CustomEvent<{ open: boolean }>) => {
<div class="border border-t-0 border-medium p-4">
<div class='mb-6'>
<v-radio
class='inline-block'
label="Set power"
options={properties?.positionReporting ? 'Go, Go for, Go to' : 'Go'}
selected={movementType}
on:input={setMovementType}
/>
<small class='text-xs text-subtle-2'>
<small class='block pt-2 text-xs text-subtle-2'>
{#if movementType === 'Go'}
Continuously moves
{:else if movementType === 'Go for'}
Expand All @@ -184,31 +233,34 @@ const handleToggle = async (event: CustomEvent<{ open: boolean }>) => {
</div>

<div class="flex flex-col gap-2">
{#if movementType === 'Go to'}
<div class='flex gap-2'>
<div class='flex gap-4 items-end'>
{#if movementType === 'Go to'}
<v-input
type="number"
label="Position in revolutions"
placeholder='0'
value={position}
class="w-36 pr-2"
on:input={setPosition}
on:blur={setPosition}
/>
<v-input
type="number"
class="w-36 pr-2"
label="RPM"
placeholder='0'
value={rpm}
on:input={setRpm}
/>
</div>
{:else if movementType === 'Go for'}
<div class='flex gap-4 items-end'>
{:else if movementType === 'Go for'}
<v-input
type="number"
class="w-36"
label="# in revolutions"
placeholder='0'
value={revolutions}
on:input={setRevolutions}
on:blur={setRevolutions}
/>
<v-radio
label="Direction of rotation"
Expand All @@ -219,13 +271,13 @@ const handleToggle = async (event: CustomEvent<{ open: boolean }>) => {
<v-input
type="number"
label="RPM"
placeholder='0'
class="w-36"
value={rpm}
on:input={setRpm}
on:blur={setRpm}
/>
</div>
{:else if movementType === 'Go'}
<div class='flex gap-4'>
{:else if movementType === 'Go'}
<v-radio
label="Direction of rotation"
options="Forwards, Backwards"
Expand All @@ -245,8 +297,8 @@ const handleToggle = async (event: CustomEvent<{ open: boolean }>) => {
on:input={setPowerSlider}
/>
</div>
</div>
{/if}
{/if}
</div>
</div>

<div class="flex flex-row-reverse flex-wrap">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ export let readonly: true | undefined = undefined;
export let lng: number | undefined;
export let lat: number | undefined;
const decimalFormat = new Intl.NumberFormat(undefined, { maximumFractionDigits: 6 });
$: lngRounded = decimalFormat.format(lng ?? 0);
$: latRounded = decimalFormat.format(lat ?? 0);
const dispatch = createEventDispatcher<{ input: LngLat }>();
const handleLng = (event: CustomEvent<{ value: string }>) => {
Expand All @@ -40,7 +35,7 @@ const handleLat = (event: CustomEvent<{ value: string }>) => {
label={label ?? 'Latitude'}
placeholder='0'
incrementor={readonly ? undefined : 'slider'}
value={latRounded}
value={lat}
step={$mapZoom ** 5}
class='w-full'
on:input={handleLat}
Expand All @@ -51,7 +46,7 @@ const handleLat = (event: CustomEvent<{ value: string }>) => {
label={label ? '' : 'Longitude'}
placeholder='0'
incrementor={readonly ? undefined : 'slider'}
value={lngRounded}
value={lng}
step={$mapZoom ** 5}
class='w-full'
on:input={handleLng}
Expand Down
56 changes: 37 additions & 19 deletions web/frontend/src/components/navigation/components/map.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { onMount } from 'svelte';
import { Map, NavigationControl } from 'maplibre-gl';
import { map, mapZoom, mapCenter, view } from '../stores';
import { map, mapZoom, mapCenter, view, mapSize, cameraMatrix } from '../stores';
import { style } from '../style';
import ObstacleLayer from './obstacle-layer.svelte';
import Waypoints from './waypoints.svelte';
Expand All @@ -17,15 +17,6 @@ const handleViewSelect = (event: CustomEvent) => {
$view = event.detail.value;
};
const handleMove = () => {
if (!map.current) {
return;
}
mapCenter.set(map.current.getCenter());
mapZoom.set(map.current.getZoom() / map.current.getMaxZoom());
};
onMount(() => {
const mapInstance = new Map({
container: 'navigation-map',
Expand All @@ -36,14 +27,47 @@ onMount(() => {
minPitch,
maxPitch: minPitch,
});
$map = mapInstance;
const handleMove = () => {
mapCenter.set(mapInstance.getCenter());
mapZoom.set(mapInstance.getZoom() / mapInstance.getMaxZoom());
};
const handleResize = () => {
mapSize.update((value) => {
const { clientWidth, clientHeight } = mapInstance.getCanvas();
value.width = clientWidth;
value.height = clientHeight;
return value;
});
};
const nav = new NavigationControl({ showZoom: false });
mapInstance.addControl(nav, 'top-right');
mapInstance.on('move', handleMove);
mapInstance.on('resize', handleResize);
mapInstance.on('style.load', () => {
mapInstance.addLayer({
id: 'obstacle-layer',
type: 'custom',
renderingMode: '3d',
render (_ctx, viewProjectionMatrix) {
cameraMatrix.fromArray(viewProjectionMatrix);
mapInstance.triggerRepaint();
},
});
});
handleMove();
handleResize();
$map = mapInstance;
return () => {
if (mapInstance.getLayer('obstacle-layer')) {
mapInstance.removeLayer('obstacle-layer');
}
};
});
$: {
Expand All @@ -70,11 +94,5 @@ $: {
{#if $map}
<RobotMarker {name} />
<Waypoints {name} map={$map} />
<ObstacleLayer {name} map={$map} />
<ObstacleLayer />
{/if}

<style>
:global(#navigation-map ~ canvas) {
display: none;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export let visible = true;
export let color: string | null = null;
const marker = new Marker({ scale, color: color ?? undefined });
marker.getElement().style.zIndex = '1';
$: {
marker.setLngLat(lngLat);
Expand Down
Loading

0 comments on commit 6036fd0

Please sign in to comment.