Skip to content

Commit

Permalink
RSDK-4317 RC card power sensor (viamrobotics#2765)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviamiller authored Aug 9, 2023
1 parent 532f806 commit 63ae19a
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/powersensor/powersensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ func Readings(ctx context.Context, g PowerSensor, extra map[string]interface{})
readings["is_ac"] = isAC
}

cur, _, err := g.Current(ctx, extra)
cur, isAC, err := g.Current(ctx, extra)
if err != nil {
if !strings.Contains(err.Error(), ErrMethodUnimplementedCurrent.Error()) {
return nil, err
}
} else {
readings["current"] = cur
readings["is_ac"] = isAC
}

pow, err := g.Power(ctx, extra)
Expand Down
4 changes: 4 additions & 0 deletions examples/apis.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
"func": "LinearAcceleration",
"args": ["context.Background()", "map[string]interface{}{}"]
},
"power_sensor": {
"func": "Voltage",
"args": ["context.Background()", "map[string]interface{}{}"]
},
"pose_tracker": {
"func": "Poses",
"args": []
Expand Down
81 changes: 81 additions & 0 deletions web/frontend/src/components/power-sensor/index.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<script lang="ts">
import { PowerSensorClient, type ServiceError } from '@viamrobotics/sdk';
import { displayError } from '@/lib/error';
import Collapse from '@/lib/components/collapse.svelte';
import { rcLogConditionally } from '@/lib/log';
import { setAsyncInterval } from '@/lib/schedule';
import { useRobotClient, useDisconnect } from '@/hooks/robot-client';
export let name: string;
const { robotClient } = useRobotClient();
const powerSensorClient = new PowerSensorClient($robotClient, name, {
requestLogger: rcLogConditionally,
});
let voltageValue: number | undefined;
let currentValue: number | undefined;
let powerValue: number | undefined;
let clearInterval: (() => void) | undefined;
const refresh = async () => {
try {
const readings = await powerSensorClient.getReadings();
voltageValue = readings.voltage;
currentValue = readings.current;
powerValue = readings.power;
} catch (error) {
displayError(error as ServiceError);
}
};
const handleToggle = (event: CustomEvent<{ open: boolean }>) => {
if (event.detail.open) {
refresh();
clearInterval = setAsyncInterval(refresh, 500);
} else {
clearInterval?.();
}
};
useDisconnect(() => clearInterval?.());
</script>

<Collapse title={name} on:toggle={handleToggle}>
<v-breadcrumbs slot="title" crumbs="power_sensor" />
<div class="flex flex-wrap gap-5 text-sm border border-t-0 border-medium p-4">
{#if voltageValue !== undefined}
<div class="overflow-auto">
<small class='block pt-1 text-sm text-subtle-2'> voltage (volts)</small>
<div class="flex gap-1.5">
<small class='block pt-1 text-sm text-subtle-1'> {voltageValue.toFixed(4)} </small>
</div>
</div>
{/if}
{#if currentValue !== undefined}
<div class="overflow-auto">
<small class='block pt-1 text-sm text-subtle-2'>
current (amps)
</small>
<div class="flex gap-1.5">
<small class='block pt-1 text-sm text-subtle-1'> {currentValue.toFixed(4)}</small>
</div>
</div>
{/if}
{#if powerValue !== undefined}
<div class="overflow-auto">
<small class='block pt-1 text-sm text-subtle-2'>
power (watts)
</small>
<div class="flex gap-1.5">
<small class='block pt-1 text-sm text-subtle-1'> {powerValue.toFixed(4)} </small>
</div>
</div>
{/if}
</div>
</Collapse>

6 changes: 6 additions & 0 deletions web/frontend/src/components/remote-control-cards.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import InputController from './input-controller/index.svelte';
import Motor from './motor/index.svelte';
import MovementSensor from './movement-sensor/index.svelte';
import Navigation from './navigation/index.svelte';
import PowerSensor from './power-sensor/index.svelte';
import Servo from './servo/index.svelte';
import Sensors from './sensors/index.svelte';
import Slam from './slam/index.svelte';
Expand Down Expand Up @@ -119,6 +120,11 @@ const getStatus = (statusMap: Record<string, unknown>, resource: commonApi.Resou
<MovementSensor {name} />
{/each}

<!-- ******* POWER SENSOR ******* -->
{#each filterSubtype($components, 'power_sensor') as { name } (name)}
<PowerSensor {name} />
{/each}

<!-- ******* ARM ******* -->
{#each filterSubtype($components, 'arm') as arm (arm.name)}
<Arm
Expand Down

0 comments on commit 63ae19a

Please sign in to comment.