Skip to content

Commit

Permalink
feat: separate yaw/pitch/roll widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
nvsukhanov committed Mar 11, 2024
1 parent 4233eef commit 2c82500
Show file tree
Hide file tree
Showing 95 changed files with 1,434 additions and 700 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ export class ControlSchemePageComponent implements OnInit, OnDestroy, ISchemeRun
return this.widgetDefaultConfigFactory.createConfigs(
addableWidgetData.ios,
addableWidgetData.portModes,
addableWidgetData.portModesInfo
addableWidgetData.portModesInfo,
addableWidgetData.existingWidgets
);
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
HUB_RUNTIME_DATA_SELECTORS,
HubModel,
ROUTER_SELECTORS,
WidgetConfigModel,
attachedIoModesIdFn,
attachedIoPortModeInfoIdFn,
attachedIosIdFn
Expand Down Expand Up @@ -288,28 +289,22 @@ export const CONTROL_SCHEME_PAGE_SELECTORS = {
ios: AttachedIoModel[];
portModes: Dictionary<AttachedIoModesModel>;
portModesInfo: Dictionary<AttachedIoPortModeInfoModel>;
existingWidgets: WidgetConfigModel[];
} => {
if (!controlScheme || schemeRunningState !== ControlSchemeRunState.Idle) {
return {
ios: [],
portModes: {},
portModesInfo: {}
portModesInfo: {},
existingWidgets: []
};
}
// There are certain limitations on IO value reading: only one IO mode can be used at a time.
// This means that if an IO is used for a widget, it cannot be re-used for another widget.
// And if an IO is used for a binding, it also cannot be used for a widget due to output mode not strictly matching to input mode.

const existingIoWidgetIds = new Set(controlScheme.widgets.map((widget) => attachedIosIdFn(widget)));
const iosWithoutWidgets = attachedIos.filter((attachedIo) => !existingIoWidgetIds.has(attachedIosIdFn(attachedIo)));

const controlledIosIds = new Set(controlScheme.bindings.map((binding) => attachedIosIdFn(binding)));
const remainingIos = iosWithoutWidgets.filter((attachedIo) => !controlledIosIds.has(attachedIosIdFn(attachedIo)));

return {
ios: remainingIos,
ios: attachedIos,
portModes: ioPortModes,
portModesInfo: portModesInfo
portModesInfo: portModesInfo,
existingWidgets: controlScheme.widgets
};
}
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export interface IControlSchemeWidgetConfigFactory<T extends WidgetConfigModel =
createConfigs(
attachedIos: AttachedIoModel[],
ioPortModes: Dictionary<AttachedIoModesModel>,
portModesInfo: Dictionary<AttachedIoPortModeInfoModel>
portModesInfo: Dictionary<AttachedIoPortModeInfoModel>,
existingWidgets: WidgetConfigModel[]
): T[];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:host {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
grid-auto-rows: 150px;
grid-auto-rows: 180px;
gap: 15px;
justify-items: stretch;
}
6 changes: 4 additions & 2 deletions modules/shared/misc/src/lib/types/widget-type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export enum WidgetType {
Voltage,
Tilt,
Temperature
Pitch,
Temperature,
Yaw,
Roll
}
4 changes: 3 additions & 1 deletion modules/shared/ui/src/lib/changelog/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export const CHANGELOG: Changelog = [
{
version: '1.3.0',
changeL10nKeys: [
'changelog.1-3-0.featOnOffToggleInputPreset'
'changelog.1-3-0.featOnOffToggleInputPreset',
'changelog.1-3-0.featSeparatePitchYawRollTiltSensorWidgets',
'changelog.bugfixesAndImprovements'
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { TiltGaugeSectorDefinition } from './tilt-gauge-sector-definition';
})
export class TiltGaugeSectorHighlightPipe implements PipeTransform {
public transform(
tiltDegrees?: number,
gaugeSector?: TiltGaugeSectorDefinition
tiltDegrees: number | null,
gaugeSector: TiltGaugeSectorDefinition
): boolean {
if (gaugeSector === undefined || tiltDegrees === undefined) {
if (tiltDegrees === null) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { TiltGaugeSectorHighlightPipe } from './tilt-gauge-sector-highlight.pipe
export class TiltGaugeSectorsComponent {
@Input() public viewBox = '0 0 0 0';

@Input() public tiltDegrees?: number;
@Input() public tiltDegrees: number | null = null;

@Input('libTiltGaugeSectors') public sectors: TiltGaugeSectorDefinition[] = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class="brackets"
></g>

@if (iconTemplate && tiltDegrees !== undefined) {
@if (iconTemplate && tiltDegrees !== null) {
<g [attr.transform]="iconTransform">
<ng-container [ngTemplateOutlet]="iconTemplate"></ng-container>
</g>
Expand Down
6 changes: 3 additions & 3 deletions modules/shared/ui/src/lib/tilt-gauge/tilt-gauge.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class TiltGaugeComponent implements OnInit {

private _viewBox: string;

private _tiltDegrees?: number;
private _tiltDegrees: number | null = null;

private _iconTransform = 'rotate(0)';

Expand All @@ -64,13 +64,13 @@ export class TiltGaugeComponent implements OnInit {

@Input()
public set tiltDegrees(
v: number | undefined
v: number | null
) {
this._tiltDegrees = v;
this.updateIconTransform();
}

public get tiltDegrees(): number | undefined {
public get tiltDegrees(): number | null {
return this._tiltDegrees;
}

Expand Down
9 changes: 6 additions & 3 deletions modules/store/src/lib/actions/attached-io-props.actions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { createActionGroup, props } from '@ngrx/store';
import { TiltData } from 'rxpoweredup';

export const ATTACHED_IO_PROPS_ACTIONS = createActionGroup({
source: 'Attached IO Props',
events: {
'motor encoder offset received': props<{ hubId: string; portId: number; offset: number }>(),
'startup servo calibration data received': props<{ hubId: string; portId: number; range: number; aposCenter: number }>(),
'compensate tilt': props<{ hubId: string; portId: number; compensationData: TiltData }>(),
'reset tilt compensation': props<{ hubId: string; portId: number }>(),
'compensate pitch': props<{ hubId: string; portId: number; currentPitch: number }>(),
'compensate yaw': props<{ hubId: string; portId: number; currentYaw: number }>(),
'compensate roll': props<{ hubId: string; portId: number; currentRoll: number }>(),
'reset pitch compensation': props<{ hubId: string; portId: number }>(),
'reset yaw compensation': props<{ hubId: string; portId: number }>(),
'reset roll compensation': props<{ hubId: string; portId: number }>(),
}
});
2 changes: 1 addition & 1 deletion modules/store/src/lib/effects/tasks-processing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export * from './i-task-filter';
export * from './i-task-runner';
export * from './i-task-factory';
export * from './i-task-input-extractor';
export { IWidgetReadTaskFactory, WIDGET_READ_TASK_FACTORY } from './scheme-pre-run';
export { IWidgetsReadTasksFactory, WIDGET_READ_TASKS_FACTORY } from './scheme-pre-run';

export const TASK_PROCESSING_EFFECTS: Record<string, FunctionalEffect> = {
preRunScheme: PRE_RUN_SCHEME_EFFECT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ import { Store } from '@ngrx/store';

import { CONTROL_SCHEME_WIDGETS_DATA_ACTIONS } from '../../../actions';
import { ControlSchemeModel } from '../../../models';
import { HubStorageService } from '../../../hub-storage.service';
import { IWidgetReadTaskFactory } from './i-widget-read-task-factory';
import { IWidgetsReadTasksFactory } from './i-widgets-read-tasks-factory';

export function createWidgetReadTasks(
scheme: ControlSchemeModel,
hubStorage: HubStorageService,
store: Store,
schemeStop$: Observable<unknown>,
widgetTaskFactory: IWidgetReadTaskFactory
widgetTaskFactory: IWidgetsReadTasksFactory
): Array<Observable<unknown>> {
const result: Array<Observable<unknown>> = [];
for (const widgetConfig of scheme.widgets) {
const readerTask = widgetTaskFactory.createReadTask(widgetConfig, store, hubStorage, schemeStop$);
const readerTasks = widgetTaskFactory.createReadTasks(scheme.widgets);
for (const task of readerTasks) {
const obs = new Observable((subscriber) => {
let initialValueReceived = false;
readerTask.subscribe((taskData) => {
task.subscribe((taskData) => {
if (!initialValueReceived) {
initialValueReceived = true;
subscriber.next(null);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Observable } from 'rxjs';
import { InjectionToken } from '@angular/core';

import { ControlSchemeWidgetsDataModel, WidgetConfigModel } from '../../../models';

export interface IWidgetsReadTasksFactory<TConfig extends WidgetConfigModel = WidgetConfigModel> {
createReadTasks(
configs: TConfig[]
): Array<Observable<{ widgetId: number; data: ControlSchemeWidgetsDataModel }>>;
}

export const WIDGET_READ_TASKS_FACTORY = new InjectionToken<IWidgetsReadTasksFactory>('WIDGET_READ_TASK_FACTORY');
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './pre-run-scheme.effect';
export * from './i-widget-read-task-factory';
export * from './i-widgets-read-tasks-factory';
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,26 @@ import { createPreRunSetAccelerationProfileTasks } from './create-pre-run-set-ac
import { createPreRunSetDecelerationProfileTasks } from './create-pre-run-set-deceleration-profile-tasks';
import { createWidgetReadTasks } from './create-widget-read-tasks';
import { HubServoCalibrationFacadeService } from '../../../hub-facades';
import { IWidgetReadTaskFactory, WIDGET_READ_TASK_FACTORY } from './i-widget-read-task-factory';
import { IWidgetsReadTasksFactory, WIDGET_READ_TASKS_FACTORY } from './i-widgets-read-tasks-factory';

export const PRE_RUN_SCHEME_EFFECT = createEffect((
actions: Actions = inject(Actions),
hubStorage: HubStorageService = inject(HubStorageService),
store: Store = inject(Store),
hubCalibrationFacade: HubServoCalibrationFacadeService = inject(HubServoCalibrationFacadeService),
appConfig: IAppConfig = inject(APP_CONFIG),
widgetReadTaskFactory: IWidgetReadTaskFactory = inject(WIDGET_READ_TASK_FACTORY)
widgetReadTaskFactory: IWidgetsReadTasksFactory = inject(WIDGET_READ_TASKS_FACTORY)
) => {
return actions.pipe(
ofType(CONTROL_SCHEME_ACTIONS.startScheme),
concatLatestFrom(({ name }) => store.select(CONTROL_SCHEME_SELECTORS.selectScheme(name))),
map(([ , scheme ]) => scheme),
filter((scheme): scheme is ControlSchemeModel => !!scheme),
switchMap((scheme) => {
const controlSchemeStopEvent$ = actions.pipe(
ofType(CONTROL_SCHEME_ACTIONS.stopScheme),
);
const combinedTasks = [
...createPreRunSetAccelerationProfileTasks(scheme, hubStorage),
...createPreRunSetDecelerationProfileTasks(scheme, hubStorage),
...createWidgetReadTasks(scheme, hubStorage, store, controlSchemeStopEvent$, widgetReadTaskFactory)
...createWidgetReadTasks(scheme, store, widgetReadTaskFactory)
];
// TODO: move to Bindings module
const calibrationServoTasks = createPreRunServoCalibrationTasks(scheme, hubCalibrationFacade, store, appConfig);
Expand Down
26 changes: 25 additions & 1 deletion modules/store/src/lib/migrations/v30-v31/v30-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ export type V31SetAngleBinding = V31Binding & { bindingType: ControlSchemeBindin

export type V31InputConfig = V31SetAngleBinding['inputs'][SetAngleBindingInputAction.SetAngle];

export const OLD_TITLE_WIDGET_TYPE = 1;

export type OldTiltWidgetConfigModel = {
widgetType: number;
hubId: string;
portId: number;
modeId: number;
valueChangeThreshold: number;
invertYaw: boolean;
invertPitch: boolean;
invertRoll: boolean;
id: number;
title: string;
width: number;
height: number;
};

export type V31WidgetConfigModel = ExtractArrayType<V31ControlSchemesEntitiesState['widgets']>;
export type V30WidgetConfigModel = V31WidgetConfigModel | OldTiltWidgetConfigModel;

export enum OldInputGain {
Linear,
Exponential,
Expand Down Expand Up @@ -60,7 +80,11 @@ export type V30Bindings = V30SpeedBinding
| V30TrainBinding
| V30GearboxBinding
| V30SetAngleBinding;
export type V30ControlSchemesEntitiesState = Omit<V31ControlSchemesEntitiesState, 'bindings'> & { bindings: V30Bindings[] };

export type V30ControlSchemesEntitiesState = Omit<V31ControlSchemesEntitiesState, 'bindings' | 'widgets'> & {
bindings: V30Bindings[];
widgets: V30WidgetConfigModel[];
};

export type V30Store = Override<V31Store, {
controlSchemes: Omit<V31Store['controlSchemes'], 'entities'> & EntityState<V30ControlSchemesEntitiesState>;
Expand Down
Loading

0 comments on commit 2c82500

Please sign in to comment.