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

Tachomotor & Absolutemotor #153

Open
firien opened this issue Mar 16, 2022 · 0 comments
Open

Tachomotor & Absolutemotor #153

firien opened this issue Mar 16, 2022 · 0 comments

Comments

@firien
Copy link
Contributor

firien commented Mar 16, 2022

I ran into trouble controlling a Technic Large Motor; while struggling to reset zero angle, and absolutely rotate to a desired angle, i found:


I do not think Tachomotor rotateByDegrees should allow a negative number for degrees as writeUInt32LE will yield unexpected results.

message.writeUInt32LE(degrees, 4);


I am not sure what normalizeAngle does, but it contains a bunch of math that eventually just cancels out.

export const normalizeAngle = (angle: number) => {

const normalizeAngle = (angle) => {
  if (angle >= 180) {
      return angle - (360 * ((angle + 180) / 360));
  } else if (angle < -180) {
      return angle + (360 * ((180 - angle) / 360));
  }
  return angle;
};

// remove (360 / 360) from equation
const normalizeAngle1 = (angle) => {
  if (angle >= 180) {
      return angle - (((angle + 180)));
  } else if (angle < -180) {
      return angle + (((180 - angle)));
  }
  return angle;
};

// remove (angle - angle) from equation
const normalizeAngle2 = (angle) => {
  if (angle >= 180) {
      return -180;
  } else if (angle < -180) {
      return 180;
  }
  return angle;
};

for (let a = -400; a < 400; a = a + 10) {
  console.log([a, normalizeAngle(a), normalizeAngle1(a), normalizeAngle2(a) ])
}

Would you consider opening up Discussions?. I am looking for help using the Technic Large Motor to steer the off road buggy - but don't want to clutter up Issues with non-bugs.


I used this library to make a web page to control kid's duplo train a few years ago, and it's still kicking. Just updated your lib from 1.x => 8.x. So thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant