Take the 2-minute tour ×
LEGO® Answers is a question and answer site for LEGO® and building block enthusiasts. It's 100% free, no registration required.

When turning the motors, how precise is the speed parameter? I am programming in the NXC language (standard firmware) and wishing to know how many decimal points will be taken, if any, and whether the input speed will be truncated, rounded or neither.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

From the page you linked to we can see that the NXC OnFwd method has the following parameters:

void OnFwd (byte outputs, char pwr)

The power or speed parameter is listed as a char type, and looking around elsewhere on the site we find the definition of the char to be:

In NXC the char type is a signed 8-bit value. This type can store values from SCHAR_MIN to SCHAR_MAX.

This means it can hold an integer value between -128 and 127.

It cannot take any decimal values.

I assume that a char was used over an int as they only need to support values between -100 and 100 in this method.

share|improve this answer
1  
Thanks, for some reason I didn't connect value to integral value, but looking at the int and float description it's quite obvious! When I use a decimal value as a parameter there is no compiler or runtime error; I believe C would just truncate a floating point number to an integer, ao I presume it would be the same in NXT for float to char? –  lpd Mar 15 '12 at 10:21
    
I guess so - I can't say I've tried, but yes, there's possibly some implicit conversions going on. –  Zhaph - Ben Duguid Mar 15 '12 at 10:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.