Skip to content

Commit

Permalink
fix: proper titles for input gain controls
Browse files Browse the repository at this point in the history
* input gain for "brake" input of Speed binding
  • Loading branch information
nvsukhanov committed Mar 8, 2024
1 parent 7f90f35 commit fa53520
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 29 deletions.
6 changes: 4 additions & 2 deletions modules/bindings/src/lib/common/common-form-mapper.service.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { Injectable } from '@angular/core';
import { ControlSchemeInput } from '@app/store';
import { ControlSchemeInput, InputGain } from '@app/store';

import { InputFormGroup } from './input-form-group';
import { isInputGainApplicable } from './is-input-gain-applicable';

@Injectable({ providedIn: 'root' })
export class CommonFormMapperService {
public mapInputFormToSchemeInput(
form: InputFormGroup
): ControlSchemeInput {
const formValue = form.getRawValue();
const gain = isInputGainApplicable(formValue.inputType) ? formValue.gain : InputGain.Linear;
const result: ControlSchemeInput = {
controllerId: formValue.controllerId,
inputId: formValue.inputId,
inputType: formValue.inputType,
gain: formValue.gain,
gain,
inputDirection: formValue.inputDirection
};
if (formValue.portId !== null) {
Expand Down
1 change: 1 addition & 0 deletions modules/bindings/src/lib/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './is-directional-input-activated';
export * from './extract-direction-aware-input-value';
export * from './calculate-task-hash';
export * from './is-triggered-input-activated';
export * from './is-input-gain-applicable';
8 changes: 8 additions & 0 deletions modules/bindings/src/lib/common/is-input-gain-applicable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ControllerInputType } from '@app/controller-profiles';

export function isInputGainApplicable(
inputType: ControllerInputType
): boolean {
return inputType === ControllerInputType.Axis
|| inputType === ControllerInputType.Trigger;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
<lib-cs-binding-control-select-controller [data]="servoCwBindingComponentData"></lib-cs-binding-control-select-controller>

@if (isCwInputGainConfigurable) {
<lib-cs-binding-control-select-input-gain [control]="form.controls.inputs.controls[inputActions.Cw].controls.gain"
<lib-cs-binding-control-select-input-gain [translocoTitle]="'controlScheme.servoBinding.cwActionInputGainTitle'"
[control]="form.controls.inputs.controls[inputActions.Cw].controls.gain"
></lib-cs-binding-control-select-input-gain>
}

<lib-cs-binding-control-select-controller [data]="servoCcwBindingComponentData"></lib-cs-binding-control-select-controller>

@if (isCcwInputGainConfigurable) {
<lib-cs-binding-control-select-input-gain [control]="form.controls.inputs.controls[inputActions.Ccw].controls.gain"
<lib-cs-binding-control-select-input-gain [translocoTitle]="'controlScheme.servoBinding.ccwActionInputGainTitle'"
[control]="form.controls.inputs.controls[inputActions.Ccw].controls.gain"
></lib-cs-binding-control-select-input-gain>
}

Expand Down
14 changes: 6 additions & 8 deletions modules/bindings/src/lib/servo/servo-binding-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { MatInputModule } from '@angular/material/input';
import { ReactiveFormsModule } from '@angular/forms';
import { concatLatestFrom } from '@ngrx/effects';
import { AsyncPipe } from '@angular/common';
import { ControllerInputType } from '@app/controller-profiles';
import { ControlSchemeBindingType, ValidationErrorsL10nMap, ValidationMessagesDirective } from '@app/shared-misc';
import { HideOnSmallScreenDirective, ToggleControlComponent } from '@app/shared-ui';
import {
Expand All @@ -33,7 +32,8 @@ import {
BindingControlSelectInputGainComponent,
BindingControlSpeedInputComponent,
BindingEditSectionComponent,
BindingEditSectionsContainerComponent
BindingEditSectionsContainerComponent,
isInputGainApplicable
} from '../common';
import { IBindingsDetailsEditComponent } from '../i-bindings-details-edit-component';
import { BINDING_SERVO_EDIT_SELECTORS } from './binding-servo-edit.selectors';
Expand Down Expand Up @@ -116,15 +116,13 @@ export class ServoBindingEditComponent implements IBindingsDetailsEditComponent<
}

public get isCwInputGainConfigurable(): boolean {
const servoInput = this.form?.controls.inputs.controls[ServoBindingInputAction.Cw];
return servoInput?.controls.inputType.value === ControllerInputType.Axis
|| servoInput?.controls.inputType.value === ControllerInputType.Trigger;
const cwInput = this.form?.controls.inputs.controls[ServoBindingInputAction.Cw];
return cwInput ? isInputGainApplicable(cwInput.controls.inputType.value) : false;
}

public get isCcwInputGainConfigurable(): boolean {
const servoInput = this.form?.controls.inputs.controls[ServoBindingInputAction.Ccw];
return servoInput?.controls.inputType.value === ControllerInputType.Axis
|| servoInput?.controls.inputType.value === ControllerInputType.Trigger;
const ccwInput = this.form?.controls.inputs.controls[ServoBindingInputAction.Ccw];
return ccwInput ? isInputGainApplicable(ccwInput.controls.inputType.value) : false;
}

public get canCalibrate$(): Observable<boolean> {
Expand Down
14 changes: 10 additions & 4 deletions modules/bindings/src/lib/speed/speed-binding-edit.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,28 @@
>
<lib-cs-binding-control-select-controller [data]="forwardsControlBindingComponentData"></lib-cs-binding-control-select-controller>

@if (isForwardInputGainConfigurable) {
<lib-cs-binding-control-select-input-gain [translocoTitle]="'controlScheme.speedBinding.accelerationInputGainTitle'"
@if (isForwardsInputGainConfigurable) {
<lib-cs-binding-control-select-input-gain [translocoTitle]="'controlScheme.speedBinding.forwardsInputGainTitle'"
[control]="form.controls.inputs.controls[inputActions.Forwards].controls.gain"
></lib-cs-binding-control-select-input-gain>
}

<lib-cs-binding-control-select-controller [data]="backwardsControlBindingComponentData"></lib-cs-binding-control-select-controller>

@if (isBackwardInputGainConfigurable) {
<lib-cs-binding-control-select-input-gain [translocoTitle]="'controlScheme.speedBinding.accelerationInputGainTitle'"
@if (isBackwardsInputGainConfigurable) {
<lib-cs-binding-control-select-input-gain [translocoTitle]="'controlScheme.speedBinding.backwardsInputGainTitle'"
[control]="form.controls.inputs.controls[inputActions.Backwards].controls.gain"
></lib-cs-binding-control-select-input-gain>
}

<lib-cs-binding-control-select-controller [data]="brakeControlBindingComponentData"></lib-cs-binding-control-select-controller>

@if (isBrakeInputGainConfigurable) {
<lib-cs-binding-control-select-input-gain [translocoTitle]="'controlScheme.speedBinding.brakeInputGainTitle'"
[control]="form.controls.inputs.controls[inputActions.Brake].controls.gain"
></lib-cs-binding-control-select-input-gain>
}

<mat-error [libValidationMessages]="form.controls.inputs"
[immediatelyShowMessages]="true"
[l10nMap]="validationErrorsMap"
Expand Down
22 changes: 14 additions & 8 deletions modules/bindings/src/lib/speed/speed-binding-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { merge } from 'rxjs';
import { TranslocoPipe } from '@ngneat/transloco';
import { MatDividerModule } from '@angular/material/divider';
import { MatError } from '@angular/material/form-field';
import { ControllerInputType } from '@app/controller-profiles';
import { ControlSchemeBindingType, ValidationErrorsL10nMap, ValidationMessagesDirective } from '@app/shared-misc';
import { HideOnSmallScreenDirective, ToggleControlComponent } from '@app/shared-ui';
import { SpeedBindingInputAction } from '@app/store';
Expand All @@ -18,7 +17,8 @@ import {
BindingControlSpeedInputComponent,
BindingEditSectionComponent,
BindingEditSectionsContainerComponent,
OptionalInputFormGroup
OptionalInputFormGroup,
isInputGainApplicable
} from '../common';
import { SpeedBindingForm } from './speed-binding-form';
import { NO_INPUTS_SET_SPEED_ERROR } from './speed-binding-form-builder.service';
Expand Down Expand Up @@ -78,6 +78,10 @@ export class SpeedBindingEditComponent implements IBindingsDetailsEditComponent<
return this.form?.controls.inputs.controls[SpeedBindingInputAction.Backwards];
}

private get brakeControl(): OptionalInputFormGroup | undefined {
return this.form?.controls.inputs.controls[SpeedBindingInputAction.Brake];
}

public get forwardsControlBindingComponentData(): BindingControlSelectControllerComponentData<ControlSchemeBindingType.Speed> | null {
return this._forwardsControlBindingComponentData;
}
Expand All @@ -90,14 +94,16 @@ export class SpeedBindingEditComponent implements IBindingsDetailsEditComponent<
return this._brakeControlBindingComponentData;
}

public get isForwardInputGainConfigurable(): boolean {
return this.forwardsControl?.controls.inputType.value === ControllerInputType.Axis
|| this.forwardsControl?.controls.inputType.value === ControllerInputType.Trigger;
public get isForwardsInputGainConfigurable(): boolean {
return this.forwardsControl ? isInputGainApplicable(this.forwardsControl.controls.inputType.value) : false;
}

public get isBackwardsInputGainConfigurable(): boolean {
return this.backwardsControl ? isInputGainApplicable(this.backwardsControl.controls.inputType.value) : false;
}

public get isBackwardInputGainConfigurable(): boolean {
return this.backwardsControl?.controls.inputType.value === ControllerInputType.Axis
|| this.backwardsControl?.controls.inputType.value === ControllerInputType.Trigger;
public get isBrakeInputGainConfigurable(): boolean {
return this.brakeControl ? isInputGainApplicable(this.brakeControl.controls.inputType.value) : false;
}

public setForm(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ export class SpeedBindingTaskPayloadBuilderService implements ITaskPayloadBuilde
binding.inputs[SpeedBindingInputAction.Backwards]?.gain ?? InputGain.Linear
);

const brakeInputWithGain = calcInputGain(brakeInput, binding.inputs[SpeedBindingInputAction.Brake]?.gain ?? InputGain.Linear);

const payload: SpeedTaskPayload = {
bindingType: ControlSchemeBindingType.Speed,
speed: snapSpeed(clampSpeed(Math.abs(forwardsSpeed) - Math.abs(backwardsSpeed))),
brakeFactor: Math.round(Math.abs(brakeInput) * binding.maxSpeed),
brakeFactor: Math.round(Math.abs(brakeInputWithGain) * binding.maxSpeed),
power: binding.power,
useAccelerationProfile: binding.useAccelerationProfile,
useDecelerationProfile: binding.useDecelerationProfile
Expand Down
1 change: 1 addition & 0 deletions modules/shared/ui/src/lib/changelog/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const CHANGELOG: Changelog = [
'changelog.1-2-3.featRaiseServoMotorRangeLimit',
'changelog.1-2-3.featSeparateControlsForForwardAndBackwardSpeed',
'changelog.1-2-3.featAxialAwarenessForSpeedBrakeControl',
'changelog.1-2-3.featInputGainForBrakeInputOfSpeedBinding',
'changelog.1-2-3.featBetterL10nForTrainAndGearbox',
'changelog.1-2-3.changeStepperNegativeValuesRemoved',
'changelog.1-2-3.featAcquireWakeLockWhenAtLeastOneHubIsConnected',
Expand Down
9 changes: 7 additions & 2 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@
"backwardsInput": "Backwards",
"brakeInput": "Brake",
"missingInputs": "At least one of the inputs must be assigned",
"accelerationInputGainTitle": "Acceleration input gain",
"forwardsInputGainTitle": "'Forwards' input gain",
"backwardsInputGainTitle": "'Backwards' input gain",
"brakeInputGainTitle": "'Brake' input gain",
"outputSpeed": "Max speed",
"taskSummary": "Speed: { speed }%",
"brakeTaskSummary": "Brake"
Expand All @@ -279,6 +281,8 @@
"taskSummary": "Servo: { angle }°",
"cwAction": "Clockwise",
"ccwAction": "Counter-clockwise",
"cwActionInputGainTitle": "'Clockwise' input gain",
"ccwActionInputGainTitle": "'Counter-clockwise' input gain",
"missingInputs": "At least one of the inputs must be assigned"
},
"stepperBinding": {
Expand Down Expand Up @@ -755,7 +759,8 @@
"featBetterL10nForTrainAndGearbox": "Better localization for 'Train' and 'Gearbox' controls",
"featSeparateControlsForCwCcwStepper": "Separate controls for clockwise and counter-clockwise stepper inputs",
"changeStepperNegativeValuesRemoved": "Only positive values are allowed for step angle in 'Stepper' binding. Use counter-clockwise controller input for negative values",
"featAcquireWakeLockWhenAtLeastOneHubIsConnected": "Acquire Wake Lock when at least one hub is connected"
"featAcquireWakeLockWhenAtLeastOneHubIsConnected": "Acquire Wake Lock when at least one hub is connected",
"featInputGainForBrakeInputOfSpeedBinding": "Input gain for 'Brake' input of 'Speed' binding"
}
}
}
9 changes: 7 additions & 2 deletions src/assets/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@
"backwardsInput": "Назад",
"brakeInput": "Тормоз",
"missingInputs": "Нужно назначить хотя-бы один контроллер",
"accelerationInputGainTitle": "Усиление ввода ускорения",
"forwardsInputGainTitle": "Усиление ввода 'Вперед'",
"backwardsInputGainTitle": "Усиление ввода 'Назад'",
"brakeInputGainTitle": "Усиление ввода 'Тормоз'",
"outputSpeed": "Макс. скорость",
"taskSummary": "Скорость: { speed }%",
"brakeTaskSummary": "Тормоз"
Expand All @@ -279,6 +281,8 @@
"taskSummary": "Сервопривод: { angle }°",
"cwAction": "По часовой",
"ccwAction": "Против часовой",
"cwActionInputGainTitle": "Усиление ввода 'По часовой'",
"ccwActionInputGainTitle": "Усиление ввода 'Против часовой'",
"missingInputs": "Нужно назначить хотя-бы один контроллер"
},
"stepperBinding": {
Expand Down Expand Up @@ -755,7 +759,8 @@
"featBetterL10nForTrainAndGearbox": "Улучшена локализация для типов привязок 'Поезд' и 'Коробка передач'",
"featSeparateControlsForCwCcwStepper": "Возможность назначить разные контроллеры для шагов по- и против часовой для привязок 'Шаговый двигатель'",
"changeStepperNegativeValuesRemoved": "Запрещены отрицательные значения для величины шага в привязке 'Шаговый двигатель'. Для установки обратного направления используйте контроль 'Против часовой'",
"featAcquireWakeLockWhenAtLeastOneHubIsConnected": "Получение Wake Lock, когда подключен хотя бы один хаб"
"featAcquireWakeLockWhenAtLeastOneHubIsConnected": "Получение Wake Lock, когда подключен хотя бы один хаб",
"featInputGainForBrakeInputOfSpeedBinding": "Управление коэффициентом усиления ввода для контроля 'Тормоз' в типе привязки 'Скорость'"
}
}
}

0 comments on commit fa53520

Please sign in to comment.