Skip to content

RobotControl::motorsWritePct bug #1478

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

Closed
bkmartinjr opened this issue Jun 21, 2013 · 3 comments
Closed

RobotControl::motorsWritePct bug #1478

bkmartinjr opened this issue Jun 21, 2013 · 3 comments
Labels
Board: Arduino Robot Applies only to the Arduino Robot Component: Core Related to the code for the standard Arduino API

Comments

@bkmartinjr
Copy link

Version 1.0.5 of the IDE. RobotControl::motorsWritePct() has an arithmetic error when computing the left/right motor speed.

Both the left/right values need to be divided by 100.

Old code:

    int16_t speedLeft=255*speedLeftPct;
    int16_t speedRight=255*speedRightPct;

I believe it should read:

    int16_t speedLeft=255*speedLeftPct / 100;
    int16_t speedRight=255*speedRightPct / 100;
@lestofante
Copy link

100.0, or you are teuncating the decimal part. Also some parentesis should
help readibility
Il giorno 21/giu/2013 22:07, "bkmartinjr" [email protected] ha
scritto:

Version 1.0.5 of the IDE. RobotControl::motorsWritePct() has an arithmetic
error when computing the left/right motor speed.

Both the left/right values need to be divided by 100.

Old code:

int16_t speedLeft=255*speedLeftPct;
int16_t speedRight=255*speedRightPct;

I believe it should read:

int16_t speedLeft=255*speedLeftPct / 100;
int16_t speedRight=255*speedRightPct / 100;


Reply to this email directly or view it on GitHubhttps://github.com//issues/1478
.

@bkmartinjr
Copy link
Author

The function input parameters (speedLeftPct and speedRightPct) are both integer type, with presumed value [0-100]. I don't believe the original implementer wanted floating point arithmetic, for efficiency's sake. So there should be no decimal in the constant (i.e., the constant should be 100, not 100. ) and my original patch is correct.

I leave it up to the integrator to decide if quotes really help, given the standard C precedence rules. I wouldn't re-order the expression due to loss of precision.

Caveat: this seems to be an undocumented function (not listed in the arduino.cc reference page for Robot library). So my assumptions about the correct function behavior may be incorrect.

X-Y added a commit to X-Y/Arduino that referenced this issue Feb 12, 2014
@cmaglie
Copy link
Member

cmaglie commented Feb 21, 2014

Fixed in 1.5.6 with X-Y@53adddc

@cmaglie cmaglie closed this as completed Feb 21, 2014
oriregev added a commit to oriregev/Arduino that referenced this issue Feb 27, 2014
* 'master' of https://github.com/arduino/Arduino:
  Corrected repeated 'less' in checkName's message
  Removed unused code, fixed indentation.
  Local (user installed) libraries have priority over system libraries
  Update README.md
  Added license for Client, IPAddressm and Server (master branch)
  Added license for Arduino.h, binary.h and main.cpp (master branch)
  Added some friendly messages for Arduino Robot include errors on old sketches
  Revert "Changed pins definition in variants from constants to #defines."
  Fixed issue arduino#1478, arduino#1599, arduino#1709, motors being opposite, updated turning algorithm
  If 2 libs have same .h file, use the lib with same dir name
  WiFi Shield examples: added the firmware version check
  Updated Listfiles SD example
  Rename README.mkdn to README.md
  Update and rename readme.txt to README.mkdn
  Update readme.txt
  Minor changes to Communication Examples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Board: Arduino Robot Applies only to the Arduino Robot Component: Core Related to the code for the standard Arduino API
Projects
None yet
Development

No branches or pull requests

3 participants