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

refactor(control schemes): add multiple inputs support for a binding #205

Merged
merged 1 commit into from
Aug 21, 2023
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<ng-container *ngIf="form">
<app-controller-select [operationMode]="linearHubIoOperationMode"
[inputFormGroup]="form.controls.input"
[title]="'controlScheme.bindingGenericInputTitle' | transloco "
[inputFormGroup]="form.controls.inputs.controls.accelerate"
[title]="'controlScheme.linearInput' | transloco "
></app-controller-select>

<ng-container *ngIf="form.controls.input.valid">
<ng-container *ngIf="form.controls.inputs.valid">
<app-binding-input-gain-select *ngIf="isInputGainConfigurable"
[control]="form.controls.input.controls.gain"
[control]="form.controls.inputs.controls.accelerate.controls.gain"
></app-binding-input-gain-select>

<app-slider-control [min]="0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { BindingInputGainSelectComponent } from '../control-axial-output-modifie
ToggleControlComponent,
BindingControlSelectControllerComponent,
TranslocoModule,
BindingInputGainSelectComponent
BindingInputGainSelectComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush
})
Expand All @@ -40,24 +40,25 @@ export class BindingLinearEditComponent implements IBindingsDetailsEditComponent
}

public get isToggleable(): boolean {
const inputType = this.form?.controls.input.controls.inputType.value;
const inputType = this.form?.controls.inputs.controls.accelerate.controls.inputType.value;
return inputType === ControllerInputType.Button || inputType === ControllerInputType.ButtonGroup;
}

public get isInputGainConfigurable(): boolean {
return this.form?.controls.input.controls.inputType.value === ControllerInputType.Axis
|| this.form?.controls.input.controls.inputType.value === ControllerInputType.Trigger;
return this.form?.controls.inputs.controls.accelerate.controls.inputType.value === ControllerInputType.Axis
|| this.form?.controls.inputs.controls.accelerate.controls.inputType.value === ControllerInputType.Trigger;
}

public setForm(
outputBinding: LinearBindingForm
): void {
const accelerateControls = outputBinding.controls.inputs.controls.accelerate.controls;
if (outputBinding !== this.form) {
this.form = outputBinding;
merge(
outputBinding.controls.input.controls.controllerId.valueChanges,
outputBinding.controls.input.controls.inputId.valueChanges,
outputBinding.controls.input.controls.inputType.valueChanges,
accelerateControls.controllerId.valueChanges,
accelerateControls.inputId.valueChanges,
accelerateControls.inputType.valueChanges,
).subscribe(() => {
this.cd.markForCheck();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<ng-container *ngIf="form">
<app-controller-select [operationMode]="servoOperationMode"
[inputFormGroup]="form.controls.input"
[title]="'controlScheme.bindingGenericInputTitle' | transloco "
[inputFormGroup]="form.controls.inputs.controls.servo"
[title]="'controlScheme.servoInput' | transloco "
></app-controller-select>

<ng-container *ngIf="form.controls.input.valid">
<ng-container *ngIf="form.controls.inputs.valid">
<app-binding-input-gain-select *ngIf="isInputGainConfigurable"
[control]="form.controls.input.controls.gain"
[control]="form.controls.inputs.controls.servo.controls.gain"
></app-binding-input-gain-select>

<button mat-raised-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export class BindingServoEditComponent implements IBindingsDetailsEditComponent<
}

public get isInputGainConfigurable(): boolean {
return this.form?.controls.input.controls.inputType.value === ControllerInputType.Axis
|| this.form?.controls.input.controls.inputType.value === ControllerInputType.Trigger;
return this.form?.controls.inputs.controls.servo.controls.inputType.value === ControllerInputType.Axis
|| this.form?.controls.inputs.controls.servo.controls.inputType.value === ControllerInputType.Trigger;
}

public get canCalibrate$(): Observable<boolean> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<ng-container *ngIf="form">
<app-controller-select [operationMode]="setAngleHubIoOperationMode"
[inputFormGroup]="form.controls.input"
[title]="'controlScheme.bindingGenericInputTitle' | transloco "
[inputFormGroup]="form.controls.inputs.controls.setAngle"
[title]="'controlScheme.setAngleInput' | transloco "
></app-controller-select>

<ng-container *ngIf="form.controls.input.valid">
<ng-container *ngIf="form.controls.inputs.valid">
<app-binding-control-num-input [translocoTitle]="'controlScheme.setAngleOutputConfigurationAngle'"
[control]="form.controls.angle"
[min]="motorLimits.minRawAngle"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<ng-container *ngIf="form">
<app-controller-select [operationMode]="stepperHubIoOperationMode"
[inputFormGroup]="form.controls.input"
[title]="'controlScheme.bindingGenericInputTitle' | transloco "
[inputFormGroup]="form.controls.inputs.controls.step"
[title]="'controlScheme.stepperInput' | transloco "
></app-controller-select>

<ng-container *ngIf="form.controls.input.valid">
<ng-container *ngIf="form.controls.inputs.valid">
<app-binding-control-num-input [translocoTitle]="'controlScheme.stepperOutputConfigurationDegree'"
[control]="form.controls.degree"
[min]="minStepperDegree"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
<ng-container *ngIf="inputFormGroup">
<div *ngIf="inputFormGroup.valid; else assignControl"
class="control-info">
<div class="control-info">
<mat-icon [fontIcon]="'gamepad'"></mat-icon>
<mat-label class="title">
{{ title }}:
{{ title }}
</mat-label>
<app-full-controller-input-name class="control-info__control-name"
[inputData]="controllerData"
></app-full-controller-input-name>
<ng-container *ngIf="inputFormGroup.valid; else controllerIsNotAssigned">
<app-full-controller-input-name class="control-info__control-name"
[inputData]="controllerData"
></app-full-controller-input-name>

<button mat-raised-button
(click)="onBind()"
>
{{ 'controlScheme.bindToAnotherInputButtonTitle' | transloco }}
</button>
<button mat-raised-button
(click)="onBind()"
>
{{ 'controlScheme.bindToAnotherInputButtonTitle' | transloco }}
</button>
</ng-container>
<ng-template #controllerIsNotAssigned>
<span class="control-info__control-name">
{{ 'controlScheme.bindingInputIsNotAssigned' | transloco }}
</span>

<button class="assign-control"
mat-raised-button
(click)="onBind()"
>
{{ 'controlScheme.bindingAssignControlButtonTitle' | transloco }}
</button>
</ng-template>
</div>
</ng-container>

<ng-template #assignControl>
<button class="assign-control"
mat-raised-button
(click)="onBind()"
>
{{ 'controlScheme.bindingAssignControlButtonTitle' | transloco }}
</button>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

.title {
font-weight: 500;
margin-right: 10px;
margin: 0 10px;
}

.control-info {
Expand All @@ -16,7 +16,3 @@
flex-grow: 1;
}
}

.assign-control {
width: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input } from '@a
import { NgIf } from '@angular/common';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { TranslocoModule } from '@ngneat/transloco';
import { MatInputModule } from '@angular/material/input';
import { MatIconModule } from '@angular/material/icon';
import { ControlSchemeInput, ControllerInputModel } from '@app/store';
import { HubIoOperationMode, ToFormGroup } from '@app/shared';

Expand All @@ -21,9 +21,9 @@ import { FullControllerInputNameComponent } from '../../full-controller-input-na
MatDialogModule,
FullControllerInputNameComponent,
MatButtonModule,
MatIconModule,
TranslocoModule,
MatInputModule
MatInputModule,
MatIconModule
],
changeDetection: ChangeDetectionStrategy.OnPush
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export class LinearOutputControlFormBuilderService {
public build(): LinearBindingForm {
return this.formBuilder.group({
id: this.commonFormControlBuilder.schemeIdControl(),
input: this.commonFormControlBuilder.inputFormGroup(),
inputs: this.formBuilder.group({
accelerate: this.commonFormControlBuilder.inputFormGroup()
}),
hubId: this.commonFormControlBuilder.hubIdControl(),
portId: this.commonFormControlBuilder.portIdControl(),
maxSpeed: this.commonFormControlBuilder.speedControl(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export class ServoOutputControlFormBuilderService {
public build(): ServoBindingForm {
return this.formBuilder.group({
id: this.commonFormControlBuilder.schemeIdControl(),
input: this.commonFormControlBuilder.inputFormGroup(),
inputs: this.formBuilder.group({
servo: this.commonFormControlBuilder.inputFormGroup()
}),
hubId: this.commonFormControlBuilder.hubIdControl(),
portId: this.commonFormControlBuilder.portIdControl(),
range: this.formBuilder.control<number>(MOTOR_LIMITS.maxServoDegreesRange, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export class SetAngleOutputControlFormBuilderService {
public build(): SetAngleBindingForm {
return this.formBuilder.group({
id: this.commonFormControlBuilder.schemeIdControl(),
input: this.commonFormControlBuilder.inputFormGroup(),
inputs: this.formBuilder.group({
setAngle: this.commonFormControlBuilder.inputFormGroup()
}),
hubId: this.commonFormControlBuilder.hubIdControl(),
portId: this.commonFormControlBuilder.portIdControl(),
angle: this.formBuilder.control<number>(0, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export class StepperOutputControlFormBuilderService {
public build(): StepperBindingForm {
return this.formBuilder.group({
id: this.commonFormControlBuilder.schemeIdControl(),
input: this.commonFormControlBuilder.inputFormGroup(),
inputs: this.formBuilder.group({
step: this.commonFormControlBuilder.inputFormGroup()
}),
hubId: this.commonFormControlBuilder.hubIdControl(),
portId: this.commonFormControlBuilder.portIdControl(),
degree: this.formBuilder.control<number>(this.defaultStepDegree, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MatListModule } from '@angular/material/list';
import { EllipsisTitleDirective, HubIoOperationMode, IoOperationTypeToL10nKeyPipe } from '@app/shared';

import { BindingTreeNodeViewModel } from './binding-tree-node-view-model';
import { SINGLE_INPUT_TREE_NODE_VIEW_MODEL_SELECTOR } from './single-input-tree-node-view-model.selector';
import { INPUT_TREE_NODE_VIEW_MODEL_SELECTOR } from './input-tree-node-view-model.selector';
import { FullControllerInputNameComponent } from '../../../full-controller-input-name';
import { BindingViewUrlPipe } from './binding-view-url.pipe';
import { ControlSchemeViewBindingTreeNodeData } from '../../types';
Expand Down Expand Up @@ -76,9 +76,9 @@ export class BindingTreeNodeComponent {
case HubIoOperationMode.SetAngle:
case HubIoOperationMode.Servo:
case HubIoOperationMode.Linear:
return this.store.select(SINGLE_INPUT_TREE_NODE_VIEW_MODEL_SELECTOR(
return this.store.select(INPUT_TREE_NODE_VIEW_MODEL_SELECTOR(
treeNodeData.controlSchemeId,
treeNodeData.binding.input,
treeNodeData.binding.inputs,
treeNodeData.binding.operationMode,
treeNodeData.binding.id,
treeNodeData.isActive,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createSelector } from '@ngrx/store';
import { Dictionary } from '@ngrx/entity';
import { CONTROLLER_CONNECTION_SELECTORS, ControlSchemeInput, ControlSchemeInputsRecord, ControllerConnectionModel } from '@app/store';
import { HubIoOperationMode } from '@app/shared';

import { BindingTreeNodeRecord, BindingTreeNodeViewModel } from './binding-tree-node-view-model';

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const INPUT_TREE_NODE_VIEW_MODEL_SELECTOR = (
controlSchemeId: string,
inputs: ControlSchemeInputsRecord,
operationMode: HubIoOperationMode,
bindingId: string,
isActive: boolean,
ioHasNoRequiredCapabilities: boolean
) => createSelector(
CONTROLLER_CONNECTION_SELECTORS.selectEntities,
(controllerConnectionEntities: Dictionary<ControllerConnectionModel>): BindingTreeNodeViewModel => {
return {
controlSchemeId,
bindingId,
isActive,
ioHasNoRequiredCapabilities,
operationMode,
controlData: Object.values(inputs).map((input: ControlSchemeInput): BindingTreeNodeRecord => {
return {
input,
isControllerConnected: !!controllerConnectionEntities[input.controllerId]
};
})
};
}
);

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export const CONTROL_SCHEME_VIEW_SELECTORS = {
(
viewTree,
runningState,
controllerEntities: Dictionary<ControllerConnectionModel>
controllerConnectionEntities: Dictionary<ControllerConnectionModel>
): boolean => {
let allHubAreConnected = true;
let allIosAreConnected = true;
Expand All @@ -222,7 +222,11 @@ export const CONTROL_SCHEME_VIEW_SELECTORS = {
hubNode.children.forEach((ioNode) => {
allIosAreConnected = allIosAreConnected && ioNode.isConnected;
allIosTypesMatches = allIosTypesMatches && ioNode.children.every((c) => !c.ioHasNoRequiredCapabilities);
allControllersConnected = allControllersConnected && ioNode.children.some((c) => !!controllerEntities[c.binding.input.controllerId]);
ioNode.children.forEach((c) => {
Object.values(c.binding.inputs).forEach((input) => {
allControllersConnected = allControllersConnected && !!controllerConnectionEntities[input.controllerId];
});
});
hasBindings = hasBindings || ioNode.children.length > 0;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export class ServoTaskBuilder extends BaseTaskBuilder {
return null;
}

const inputRecord = inputsState[controllerInputIdFn(binding.input)];
const inputValue = calcInputGain(inputRecord?.value ?? 0, binding.input.gain);
const servoInput = inputsState[controllerInputIdFn(binding.inputs.servo)];
const servoInputValue = calcInputGain(servoInput?.value ?? 0, binding.inputs.servo.gain);

const translationPaths = getTranslationArcs(motorEncoderOffset, binding.aposCenter);
const resultingCenter = translationPaths.cw < translationPaths.ccw ? translationPaths.cw : -translationPaths.ccw;

const arcSize = binding.range;
const arcPosition = inputValue * arcSize / 2 * (binding.invert ? -1 : 1);
const arcPosition = servoInputValue * arcSize / 2 * (binding.invert ? -1 : 1);

const targetAngle = arcPosition + resultingCenter;
const minAngle = resultingCenter - arcSize / 2;
Expand All @@ -43,7 +43,7 @@ export class ServoTaskBuilder extends BaseTaskBuilder {
useAccelerationProfile: binding.useAccelerationProfile,
useDecelerationProfile: binding.useDecelerationProfile,
};
return { payload, inputTimestamp: inputRecord?.timestamp ?? Date.now() };
return { payload, inputTimestamp: servoInput?.timestamp ?? Date.now() };
}

protected buildCleanupPayload(
Expand Down
Loading
Loading