Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve linting and fix build errors #35

Merged
merged 5 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions shims-vue-mat-icons.d.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import { useControllerStore } from '../store/useController';
const roslib = useRoslibStore();
const controller = useControllerStore();
const currentTab = ref(0);
const setCurrentTab = (e) => {
currentTab.value = e;
const setCurrentTab = (newValue: number) => {
currentTab.value = newValue;
};

type PageIcon = { icon: string; label: string; helperText: string }[];
type PageIcon = { icon: object; label: string; helperText: string }[];

const pageIconArr: PageIcon = [
{
Expand Down
59 changes: 37 additions & 22 deletions src/components/telemetry/moteus/GenericMotorTelemetry.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- TODO: Need to refactor entire to fix Typescript issues -->
<script lang="ts" setup>
import { ref, onMounted, inject } from 'vue';

Check warning on line 3 in src/components/telemetry/moteus/GenericMotorTelemetry.vue

View workflow job for this annotation

GitHub Actions / lint

'inject' is defined but never used. Allowed unused vars must match /^_/u
import DropDownItem from './DropDownItem.vue';
import TelemetryDataDisplay from './TelemetryDataDisplay.vue';
import SaveCSVData from '../../../lib/saveCSVData';
Expand All @@ -9,28 +9,33 @@

onMounted(() => initialize());

const props = defineProps({
displayName: String,
dataSourceMethod: Function,
dataSourceParamater: String,
update_ms: String,
showAllFeatures: Boolean,
motorType: String,
});
export interface GenericMotorTelemetryProps {
displayName: string;
dataSourceMethod: (
param: number,
dataCallback: (result: { json_payload: string }) => void,
) => void;
dataSourceParameter: number;
updateMs: number;
showAllFeatures: boolean;
motorType: string;
}

const props = defineProps<GenericMotorTelemetryProps>();

let isRecordingData = false;
let csvData;
let csvData: SaveCSVData;

// We use this to fill up csv data
//Each element is another array that holds the actual data
let showCheckbox = ref(true);

let recordButtonText = ref('Start Recording');

let pollingData; //Used to keep track of the object id when we do setInterval
let pollingData: number; //Used to keep track of the object id when we do setInterval

let getMoteusMotorStateService: ROSLIB.Service;

Check warning on line 37 in src/components/telemetry/moteus/GenericMotorTelemetry.vue

View workflow job for this annotation

GitHub Actions / lint

'getMoteusMotorStateService' is defined but never used. Allowed unused vars must match /^_/u
const roslib = useRoslibStore();

Check warning on line 38 in src/components/telemetry/moteus/GenericMotorTelemetry.vue

View workflow job for this annotation

GitHub Actions / lint

'roslib' is assigned a value but never used. Allowed unused vars must match /^_/u

/**
* This is used to store what kind of data we will be displaying
Expand All @@ -40,7 +45,15 @@
* show up, assuming that the data recieved from the the rover also has these values
*/

const moteuesDataChoice = ref([]);
interface MoteuesDataChoice {
prettyName: string;
identifier: string;
dataValue: string;
isSelected: boolean;
shouldRecordData: boolean;
}

const moteuesDataChoice = ref<MoteuesDataChoice[]>([]);
let hasBuiltMoteusDataChoice = false;

function initialize() {
Expand All @@ -49,9 +62,9 @@
// pollingData = setInterval(updateUIWithNewData, props.update_ms);
}

function updateUIWithNewData(jsonString) {
function updateUIWithNewData(_jsonString: unknown) {

Check warning on line 65 in src/components/telemetry/moteus/GenericMotorTelemetry.vue

View workflow job for this annotation

GitHub Actions / lint

'updateUIWithNewData' is defined but never used. Allowed unused vars must match /^_/u
if (props.dataSourceMethod !== undefined) {
let result = props.dataSourceMethod(props.dataSourceParamater, dataCallback);
let result = props.dataSourceMethod(props.dataSourceParameter, dataCallback);

Check warning on line 67 in src/components/telemetry/moteus/GenericMotorTelemetry.vue

View workflow job for this annotation

GitHub Actions / lint

'result' is assigned a value but never used. Allowed unused vars must match /^_/u
}

if (isRecordingData) {
Expand All @@ -61,15 +74,15 @@
//This code section is used to change the polling rate
clearInterval(pollingData); //Stop the interval

if (props.update_ms < 4) {
if (props.updateMs === undefined || props.updateMs < 4) {
//So we dont break the thing by going slower. It is 4 because browser limitations
pollingData = setInterval(updateUIWithNewData, 4);
} else {
pollingData = setInterval(updateUIWithNewData, props.update_ms);
pollingData = setInterval(updateUIWithNewData, props.updateMs);
}
}

function dataCallback(result) {
function dataCallback(result: { json_payload: string }) {
if (!hasBuiltMoteusDataChoice) {
hasBuiltMoteusDataChoice = true;
buildMoteusDataChoice(result);
Expand All @@ -88,7 +101,7 @@
if (!Number.isNaN(dataEntry)) {
if (Number.isInteger(dataEntry)) {
//if int
object.dataValue = dataEntry;
object.dataValue = dataEntry.toString();
} else {
object.dataValue = dataEntry.toFixed(5);
}
Expand All @@ -100,7 +113,7 @@
}
}

function buildMoteusDataChoice(result) {
function buildMoteusDataChoice(result: { json_payload: string }) {
let json = JSON.parse(result.json_payload);

for (const key in json) {
Expand Down Expand Up @@ -129,7 +142,7 @@
let entry = moteuesDataChoice.value[index];

//If we have selected that entry to be recorded
if (entry.shouldRecordData === true) {
if (entry.shouldRecordData) {
if (entry.dataValue !== 'N/A') {
tempDataArray.push(entry.dataValue);
} else {
Expand All @@ -150,7 +163,7 @@
function itemClicked(itemName: string) {
let mything = getMoteusDataObjectFromIdentifier(itemName);
if (mything !== null) {
mything.isSelected.value = !mything.isSelected.value;
mything.isSelected = !mything.isSelected;
}
}

Expand Down Expand Up @@ -181,13 +194,15 @@
recordButtonText.value = 'Start Recording';
showCheckbox.value = true;

csvData.saveToFile(props.displayName);
if (props.displayName) {
csvData.saveToFile(props.displayName);
}
}

isRecordingData = !isRecordingData;
}

function getMoteusDataObjectFromIdentifier(itemName: string) {
function getMoteusDataObjectFromIdentifier(itemName: string): MoteuesDataChoice | null {
for (let index = 0; index < moteuesDataChoice.value.length; index++) {
if (moteuesDataChoice.value[index].identifier === itemName) {
return moteuesDataChoice.value[index];
Expand Down
20 changes: 9 additions & 11 deletions src/lib/interface/robotInfo.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import ROSLIB from 'roslib';

export default class RobotInfo {
myROS = null;
getMoteusMotorStateService = null;
myROS: ROSLIB.Ros;
getMoteusMotorStateService: ROSLIB.Service<{ target_can_id: number }, { json_payload: string }>;

constructor(givenROS) {
constructor(givenROS: ROSLIB.Ros) {
this.myROS = givenROS;

if (this.myROS !== null) {
this.getMoteusMotorStateService = new ROSLIB.Service({
ros: this.myROS,
name: '/get_moteus_motor_state',
serviceType: 'MoteusState',
});
}
this.getMoteusMotorStateService = new ROSLIB.Service({
ros: this.myROS,
name: '/get_moteus_motor_state',
serviceType: 'MoteusState',
});
}

getMoteusMotorState(canfdID: number, callback) {
getMoteusMotorState(canfdID: number, callback: (result: { json_payload: string }) => void) {
const request = {
target_can_id: canfdID,
};
Expand Down
9 changes: 3 additions & 6 deletions src/lib/saveCSVData.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export default class SaveCSVData {
header: string[] = [];
csvDataObjects: object[] = [];
csvDataObjects: string[][] = [];

constructor() {}

setHeader(target: string[]) {
this.header = target;
}

addDataEntry(dataEntry: object[]) {
addDataEntry(dataEntry: string[]) {
//console.log(dataEntry.toString())
this.csvDataObjects.push(dataEntry);
}
Expand All @@ -20,10 +20,7 @@ export default class SaveCSVData {
// Fill in the values
for (let fullEntryIndex = 0; fullEntryIndex < this.csvDataObjects.length; fullEntryIndex++) {
//Grabs the data array entry from the list of data (csvDataObjects)
// TODO: Refactor so do not use "any"
// Make type probably
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const entryArray: any = this.csvDataObjects[fullEntryIndex];
const entryArray = this.csvDataObjects[fullEntryIndex];
let entryString = '';

//Builds the line
Expand Down
15 changes: 9 additions & 6 deletions src/pages/Telemetry.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- All information about rover like motor speed etc, position, potential record and export to csv -->
<script setup lang="ts">
import GenericMotorTelemetry from '../components/telemetry/moteus/GenericMotorTelemetry.vue';
import { ref, onMounted, watch } from 'vue';
import { ref, onMounted, watch, useTemplateRef } from 'vue';
import RobotInfo from '@/lib/interface/robotInfo';
import { useRoslibStore } from '@/store/useRoslib';

Expand Down Expand Up @@ -68,9 +68,9 @@ let updateTimeMs = ref(100);
let recordingAll = ref(false);
let isFinishedLoading = ref(false);

const myChild = ref(null);
const myChild = useTemplateRef<(typeof GenericMotorTelemetry)[]>('myChild');

let robotInfo;
let robotInfo: RobotInfo;

onMounted(() => initialize());

Expand Down Expand Up @@ -100,7 +100,10 @@ function recordAllPressed() {
recordingAll.value = !recordingAll.value;
}

function getMoteusStateProxy(param, dataCallback) {
function getMoteusStateProxy(
param: number,
dataCallback: (result: { json_payload: string }) => void,
) {
return robotInfo.getMoteusMotorState(param, dataCallback);
}
</script>
Expand Down Expand Up @@ -136,10 +139,10 @@ function getMoteusStateProxy(param, dataCallback) {
class="telemetry-motor"
:display-name="item.displayName"
:show-all-features="true"
:update-ms="updateTimeMs.toString()"
:update-ms="updateTimeMs"
:motor-type="item.controller"
:data-source-method="getMoteusStateProxy"
:data-source-paramater="item.canfdID.toString()"
:data-source-parameter="item.canfdID"
>
</GenericMotorTelemetry>
</div>
Expand Down
12 changes: 12 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
// Any Global Types go here
declare module 'vue-material-design-icons/*.vue' {
import type { DefineComponent } from 'vue';

const IconVue: DefineComponent<{
/// `size` defaults to 24
size?: number;
/// `fillColor` defaults to 'currentColor'
fillColor?: string;
title?: string;
}>;
export default IconVue;
}
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
"compilerOptions": {
"importsNotUsedAsValues": "remove",
"isolatedModules": false,
"noImplicitAny": false,
"noImplicitAny": true,
"strict": true,
"baseUrl": ".",
"types": ["node"],

"paths": {
"@/*": ["./src/*"]
},
Expand Down
Loading