WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

core.h

This file is always included by the system file (SYS/*.h) that you use.
It defines some standard macros and datatypes and also provides the main entry point for your program.

 

Function

 


Never returns main(void)

This is the main entry point of your program and it will help to set up your program ready for use.

int16_t interpolate(int16_t value, int16_t minVal, int16_t maxVal, int16_t minRtn, int16_t maxRtn)

This will interpolate a value from one range of values into its equivalent in another range of signed numbers by using the following parameters:-
value - The value from range 1
minVal,MaxVal - specify the start and end of range 1
minRtn,maxRtn - specify the start and end of range 2
The function will convert 'value' into its equivalent in range 2.
Mathematically it will return:
minRtn+((value-minVal)*(maxRtn-minRtn)/(maxVal-minVal))
Example: assume that you have a value in a variable called 'theValue' that stores a value in the range 0 to 2048 and you want to convert this into the range -512 to +512 and store the new value into a variable called 'newValue'. Then you could write:-
int16_t newValue = interpolate(theValue, 0, 2048, -512, 512);
Here are some examples of what would be returned:-
Note that no range checking is performed. So if theValue contained twice the input limit then it will return twice the output limit. ie if theValue=4096 then the returned value will be 1024.
If you want to limit the values to make sure they are within a given range then use the CLAMP command in libdefs.h. For example:-
uint16_t newValue = interpolate(theValue, 0, 2048, -512, 512);
newValue = CLAMP(newValue,-512,512); // limit the answer to be in the range -512 to 512

uint16_t interpolateU(int16_t value, int16_t minVal, int16_t maxVal, uint16_t minRtn, uint16_t maxRtn)

This will interpolate a value from one range of values into its equivalent in another range of unsigned numbers by using the following parameters:-
value - The value from range 1
minVal,MaxVal - specify the start and end of range 1
minRtn,maxRtn - specify the start and end of range 2
The function will convert 'value' into its equivalent in range 2.
Mathematically it will return:
minRtn+((value-minVal)*(maxRtn-minRtn)/(maxVal-minVal))
Example: assume that you have a value in a variable called 'theValue' that stores a value in the range 0 to 2048 and you want to convert this into the range 300 to 800 and store the new value into a variable called 'newValue'. Then you could write:-
uint16_t newValue = interpolate(theValue, 0, 2048, 300, 800);
Note that no range checking is performed. So if theValue contained twice the input limit then it will return twice the output limit. ie if theValue=4096 then the returned value will be 1600.
If you want to limit the values to make sure they are within a given range then use the CLAMP command in libdefs.h. For example:-
uint16_t newValue = interpolate(theValue, 0, 2048, 300, 800);
newValue = CLAMP(newValue,300,800); // limit the answer to be in the range 300 to 800

uint32_t isqrt(uint32_t x)

Performs a fast square root function on a whole number - returning the nearest whole number answer and without requiring the floating point library.

Valid XHTML 1.0 Transitional