Skip to content

Commit

Permalink
fix: re-map the motor speeds for nano based robots (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoesbergen authored Dec 24, 2024
1 parent a081043 commit ec94da4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dist",
"media"
],
"version": "3.3.1",
"version": "3.3.2",
"description": "Leaphy custom Blockly blocks and arduino code generator",
"name": "@leaphy-robotics/leaphy-blocks"
}
12 changes: 10 additions & 2 deletions src/generators/arduino/leaphy_original.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ function getCodeGenerators(arduino: Arduino) {

arduino.forBlock["leaphy_original_set_motor"] = function (block) {
const dropdown_Type = block.getFieldValue("MOTOR_TYPE");
const speed =
let speed =
arduino.valueToCode(block, "MOTOR_SPEED", arduino.ORDER_ATOMIC) ||
"100";
// Map the speed to a range of 150 - 255 to compensate for low PWM signal voltage
if (parseInt(speed) > 0) {
speed = `map(${speed}, 0, 255, 150, 255)`;
}
arduino.addInclude(
"include_leaphy_original",
'#include "Leaphyoriginal1.h"',
Expand Down Expand Up @@ -75,7 +79,7 @@ function getCodeGenerators(arduino: Arduino) {
let direction = block.getFieldValue(
"MOTOR_DIRECTION",
) as MotorDirection;
const speed =
let speed =
arduino.valueToCode(block, "MOTOR_SPEED", arduino.ORDER_ATOMIC) ||
"100";
arduino.addInclude(
Expand All @@ -85,6 +89,10 @@ function getCodeGenerators(arduino: Arduino) {

// Set different motor pins for nano robots
if (arduino.robotType.includes("nano")) {
// Map the speed to a range of 150 - 255 to compensate for low PWM signal voltage
if (parseInt(speed) > 0) {
speed = `map(${speed}, 0, 255, 150, 255)`;
}
const directionMap: Record<MotorDirection, number> = {
[MotorDirection.FORWARD]: 2,
[MotorDirection.BACKWARD]: 1,
Expand Down

0 comments on commit ec94da4

Please sign in to comment.