DISCLAIMER: This library is provided 'AS IS'. See license.txt
for details.
IMPORTANT: Please note that this library requires Adafruit PWM driver library to be properly installed in your libraries
folder. Adafruit PWM library is currently not provided with AP_Utils and has to be installed separately!
This library allows even less Arduino-experienced users to program their ArduPod. The main part of this library is lower-level servo and sensor control, plus a higher-level API in Arduino style that allows for easy ArduPod control. The following is a list of currently implemented features and their description, see ./examples/
for details on their usage.
-
AP_Utils(void)
Default constructor, used to create AP_utils object, ie.
AP_Utils ardupod;
-
begin(int *offsets)
This method performs initial setup, similarly to calling
Serial.begin(9600);
you have to callardupod.begin(offsets);
before calling any other methods. Theoffsets
is an integer array with 16 members. This is to calibrate all the servos to the middle position. Seeexamples/calibration.ino
for details.Note: It is necessary to adjust few settings in
AP_Utils.h
according to the physical boundaries of the servos used. On lines 19 and 20, both variables have to be adjusted so that the servos won't get damaged. The easiest approach to this is to set theSERVOMIN
value higher andSERVOMAX
lower and uploading theexamples/servo_test.ino
. The servo will try to move back and forth from one end to the other. If the servo isn't reaching the physical limit, adjust the settings back towards their former value a bit, then upload again and oserve the differnce. Repeat this process until the servo is moving to both its limits while not stepping over them! Setting theSERVOMAX
too high (orSERVOMIN
too low) might destroy your servo!Also in
AP_Utils.h
, on line 12 ther is an option for debug mode. When uncommented, debug data will be sent to the serial port. It is highly recommended to not use this option unless absolutely necessary, as it will slow down everything else considerably. -
moveServo(uint8_t servo, int deg. bool smooth = true, float speed = 2.5)
Move servo number
servo
(numbering consistent with Adafruit PWM Shield from 0 to 15) to positiondeg
(where 0 and 180 degrees are the servos physical boundaries). Ifsmooth
is set totrue
, then the movement will be smooth. Thespeed
arguement is optional and defines the speed at which the servo will move, with higher value meaning slower movement. The value for this can vary for each servo type, most common values are from 2.0 to 5.0. -
reset(int *offsets)
Reset all servos to their middle position with supplied offsets. See
examples/calibration.ino
for details. -
traceLeg(uint8_t leg, float phi, float z, int resolution)
This method calculates a path for specified
leg
to follow, wherephi
andz
are the leg ending positions andresolution
is the path resolution. Note that this function itself won't move the leg, it will only return the path as an array ofpointLeg
structures. -
setLegs(pointLeg *legs, uint8_t *numLegs, uint8_t total, bool smooth = true, float speed = 2.5)
Move the
legs
whose numbers are specified in arraynumLegs
(the total number of moving legs has to be supplied by thetotal
argument). This function will effectively move legs to the positions specified bylegs
, while driving all of them at once. Seeexamples/walk.ino
for details.Note: It is NOT possible to achieve the same effect by using multiple calls to
moveServo
, as this function will only move one servo at a time! -
stretch(void)
Raise and lower all the legs. This can be useful when one of the legs gets stuck. -
step(int direction)
ArduPod will take a single step in the given direction. Supported directions areFORWARD
,BACKWARD
,LEFT
andRIGHT
. Note thatLEFT
andRIGHT
will turn the robot one step (approx. 30 degrees). -
walk(int direction)
Each time this function is called, Ardupod will walk one step in the given direction. Unlike thestep
function however, legs will not be reset to the default position, allowing for continous movement by calling this function again. Supported directions areFORWARD
,BACKWARD
,LEFT
andRIGHT
. Note thatLEFT
andRIGHT
will turn the robot on the spot. -
sr04(uint8_t trig, uint8_t echo, int unit)
Take a single measurement with HC-SR04 rangefinder.
trig
andecho
are numbers of Arduino pins to which the SR04 TRIG and ECHO pins are connected. The result will be returned as a floating point number with unit specified byunit
: currently supported constants areMM
for millimters,CM
for centimiters, andM
for meters. -
sr04_average(uint8_t trig, uint8_t echo, int unit, int samples, int time)
Take muber of measurements specified by
samples
overtime
milliseconds. The result will be an average of these measurements returned as floating point number with the specified unit. -
sr04_median(uint8_t trig, uint8_t echo, int unit, int samples, int time)
Similar to the above, however, this method returns median of all the measurements. This function is recommended over
sr04_average
as it's result are much less prone to be affected by exceedingly wrong measurements.