Skip to content

Commit

Permalink
writing to output for servo, wip because unexpected 270 degree range
Browse files Browse the repository at this point in the history
  • Loading branch information
bacalj committed Mar 28, 2024
1 parent d3ce4ca commit 3103bc4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/models/stores/serial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,20 @@ export class SerialDevice {
}

public writeToOutForBBGripper(n:number, liveOutputType: string){
const gripperVer = NodeLiveOutputTypes.find(o => o.name === liveOutputType);
if (this.hasPort() && gripperVer?.angleBase){
const outputConfig = NodeLiveOutputTypes.find(o => o.name === liveOutputType);

Check warning on line 165 in src/models/stores/serial.ts

View check run for this annotation

Codecov / codecov/patch

src/models/stores/serial.ts#L165

Added line #L165 was not covered by tests
if (this.hasPort() && outputConfig?.angleBase !== undefined){
const percent = n / 100;
const openTo = Math.round(gripperVer.angleBase - (percent * gripperVer.sweep));
const openTo = Math.round(outputConfig.angleBase - (percent * outputConfig.sweep));

Check warning on line 168 in src/models/stores/serial.ts

View check run for this annotation

Codecov / codecov/patch

src/models/stores/serial.ts#L168

Added line #L168 was not covered by tests
this.writer.write(`${openTo.toString()}\n`);
}
}

public writeToOutForServo(n:number, liveOutputType: string){
const outputConfig = NodeLiveOutputTypes.find(o => o.name === liveOutputType);

Check warning on line 174 in src/models/stores/serial.ts

View check run for this annotation

Codecov / codecov/patch

src/models/stores/serial.ts#L173-L174

Added lines #L173 - L174 were not covered by tests
if (this.hasPort() && outputConfig?.angleBase !== undefined){
const constrainedAngle = Math.min(180, Math.max(0, n));
this.writer.write(`${constrainedAngle.toString()}\n`);

Check warning on line 177 in src/models/stores/serial.ts

View check run for this annotation

Codecov / codecov/patch

src/models/stores/serial.ts#L176-L177

Added lines #L176 - L177 were not covered by tests
}
}
}

10 changes: 8 additions & 2 deletions src/plugins/dataflow/nodes/utilities/update-utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getHubSelect, getNodeValueWithType } from "./live-output-utilities";
import { NumControl } from "../controls/num-control";
import { SensorSelectControl } from "../controls/sensor-select-control";
import { NodeChannelInfo } from "../../model/utilities/channel";
import { kMaxNodeValues, NodeGeneratorTypes, NodeTimerInfo, NodeValue } from "../../model/utilities/node";
import { kGripperOutputTypes, kMaxNodeValues, kServoOutputTypes, NodeGeneratorTypes, NodeTimerInfo, NodeValue } from "../../model/utilities/node";

Check warning on line 9 in src/plugins/dataflow/nodes/utilities/update-utilities.ts

View workflow job for this annotation

GitHub Actions / Build

This line has a length of 146. Maximum allowed is 120

Check warning on line 9 in src/plugins/dataflow/nodes/utilities/update-utilities.ts

View workflow job for this annotation

GitHub Actions / S3 Deploy

This line has a length of 146. Maximum allowed is 120
import { findOutputVariable, simulatedHubName } from "../../model/utilities/simulated-output";
import { SerialDevice } from "../../../../models/stores/serial";

Expand All @@ -29,8 +29,14 @@ export function sendDataToSerialDevice(n: Node, serialDevice: SerialDevice) {
const { deviceFamily } = serialDevice;

if (deviceFamily === "arduino" && isNumberOutput){
serialDevice.writeToOutForBBGripper(val, outType);
if (kGripperOutputTypes.includes(outType)){
serialDevice.writeToOutForBBGripper(val, outType);

Check warning on line 33 in src/plugins/dataflow/nodes/utilities/update-utilities.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/dataflow/nodes/utilities/update-utilities.ts#L33

Added line #L33 was not covered by tests
}
if (kServoOutputTypes.includes(outType)){
serialDevice.writeToOutForServo(val, outType);

Check warning on line 36 in src/plugins/dataflow/nodes/utilities/update-utilities.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/dataflow/nodes/utilities/update-utilities.ts#L36

Added line #L36 was not covered by tests
}
}

if (deviceFamily === "microbit"){
const hubSelect = getHubSelect(n);
if (hubSelect.getChannels()){
Expand Down

0 comments on commit 3103bc4

Please sign in to comment.