Functions
- imap(x, in_min, in_max, out_min, out_max)
Maps an integer value in the range [in_min, in_max] to interval [out_min, out_max] Analogous to arduino map function that uses long int numeric types. If the input parameters are non-integer numerics, they will be converted to a Python int type at whatever resolution is available by the Python implementation being used.
- Parameters
x – input numeric value to map
in_min – lower bound of input range
in_max – upper bound of input range
out_min – lower bound of output range
out_max – upper bound of output range
- Returns
bounded value
- Return type
Note: The input is not bounded. Use the constrain(…) function to bound it first if required
A typical use of this function with robotic control would be to take a value in decimal range of [0,100] and map into [0,255] ie. ([0,FF] hex) before sending it to a motor controller.
- fmap(x, in_min, in_max, out_min, out_max)
Maps a float value in the range [in_min, in_max] to interval [out_min, out_max]
- Parameters
x – input numeric value to map
in_min – lower bound of input range
in_max – upper bound of input range
out_min – lower bound of output range
out_max – upper bound of output range
- Returns
bounded value
- Return type
- constrain(x, xmin, xmax)
Bounds a numeric value to range [xmin, xmax]
- Parameters
x – input numeric value
xmin – lower bound
xmax – upper bound
- Returns
bounded value
- Return type
- rad2deg(rad)
Converts an angle in radians to degrees
- Parameters
rad – input angle in radians
- Returns
angle in degrees
- Return type
- deg2rad(deg)
Converts an angle in degrees to radians
- Parameters
deg – input angle in degrees
- Returns
angle in radians
- Return type
- bound2pi(angle)
Bounds an angle to (+/-) pi radians
- Parameters
angle – angle in radians
- Returns
bounded angle in radians
- Return type
- bound2piDeg(angle)
Bounds an angle to (+/-) 180 degrees
- Parameters
angle – angle in degrees
- Returns
bounded angle in degrees
- Return type
- boundTo2pi(angle)
Bounds an angle into one circular rotation of 2 pi radians (360 degrees). So even if the input angle is spinning perpertually either counter-clockwise in the positive direction or clockwise in the negative direction the output angle is contained into only one equivalent full circular rotation of 2 pi radians (360 degrees)
- Parameters
angle – angle in radians
- Returns
bounded angle in radians
- Return type
- radPerSecToRpm(rps)
Converts angular velocity in radians per second to RPM (revolutions per minute)
- Parameters
rps – angular velocity in radians per second
- Returns
angular velocity in revolutions per second
- Return type
- rpmToRadPerSec(rpm)
Converts angular velocity in RPM (revolutions per minute) to radians per second
- Parameters
rpm – angular velocity in RPM
- Returns
angular velocity radians per second
- Return type
- degPerSecToRadPerSec(dps)
Converts angular rotational rate in degrees per second to radians per second
- Parameters
dps – angular rotational rate in degrees per second
- Returns
angular rotational rate in radians per second
- Return type
- radPerSecToDegPerSec(rps)
Converts angular rotational rate in radians per second to degrees per second
- Parameters
rps – angular rotational rate in radians per second
- Returns
angular rotational rate in degrees per second
- Return type
- mps2kmph(mps)
Converts meters per second to kmph
- Parameters
mps – rate in meters per second
- Returns
rate in kilometers per hour
- Return type
- mps2mph(mps)
Converts meters per second to mph
- Parameters
mps – rate in meters per second
- Returns
rate in miles per hour
- Return type
- getDistance(x0, y0, x1, y1)
Usual 2-space euclidian distance
- Parameters
x0 – start pos x
y0 – start pos y
x1 – end pos x
y1 – end pos y
- Returns
distance
- Return type
- getDistanceFromTo(x0, y0, x1, y1)
Same as getDistance(…) just more verbose
- getPositionAt(x0, y0, d, theta)
Returns position (x1,y1) that is d distance away from (x0,y0) at relative angle theta
Useful for getting the position of a remote object when using ranging sensors For example, IR sensors. The ranging distance is returned from a known sensor mounted at angle theta relative to robot’s frame forward heading when the robot is at current position (x0,y0)
- Parameters
x0 – start pos x
y0 – start pos y
d – distance from some current position (x0,y0) to remote point
theta – angle (deg) relative to current heading at position (x0,y0) to remote point
- Returns
(x1,y1): tuple of remote position coordinates
- Return type
Note that the robots current position (x0,y0) and the position of the remote object at range d returned as (x1,y1) are in the same coordinate frame. There are no frame transforms between, for instance, the robots frame and a world frame. But, the angle theta, the direction that a ranging sensor would point at, is in the robots frame relative to 0 degrees that is assumed to be the robots front, center and forward heading on the robot itself in a right-handed coordinate system. So for instance, theta = 0 degrees is easting, theta = 90 degrees is pointing north and theta = -90 is due south. Also, theta is not to be confused with typically notated phi for robots heading if its pose is (x0,y0,phi) in a world frame or whatever frame it is configured to operate and move in.
To have the remote position coordinates at range returned in the robot frame then keep (x0,y0) = (0,0). In other words, keep the robots current position, irregardless of its mobile position (and heading) in world coordinate space, at its physical frame center!
To get the romote position coordinates at range from the robot for a particular sensor returned in the world coordinate frame then have (x0,y0) set to the robots current position in world coordinates and set theta equal to theta the sensor angle on the robot frame, plus phi the robot’s heading in the world frame. Eg. theta = phi + theta_sensor. Since the robots heading could be unpredictable, use a roboutils function to bound it. Eg. theta = bound2piDeg(phi+theta_sensor)
- getPosAt(x0, y0, d, theta)
Short-hand for getPositionAt(…)
- getAngleFromTo(x0, y0, x1, y1, <deg360>)
Returns angle (in degrees) of line segment from (x0,y0) to (x1,y1)
Uses normal trig conventions for signed angles of rotation: positive angle are to left (counter-clockwise) negative angles are to right (clockwise)
- Parameters
x0 – start pos x
y0 – start pos y
x1 – end pos x
y1 – end pos y
deg360 – = False (default) to bound angle to 180 degrees = True to bound in full rotation of 360 degrees
- Returns
angle in degrees
- Return type