Recent Changes - Search:




Mega Plan



Behavior API The home folder for behaviors is flockbot/behaviors. The programs here are all presently created using the C API, which is referenced below. Future work will provide APIs in other languages, however, at present, only the C language API has been written.

Makefile The behaviors directory has a Makefile that is powerful enough to make all of the samples in the directory. When creating a new behavior, the easiest way is to determine which sample has the components that you are going to use (API, OpenCV, Barcode) and copy that, creating a new entry. For example, if you wanted to create a program that does blob-tracking with OpenCV and drives around to follow it, you would create a new Makefile rule following the example from OpenCV Sample. Let's suppose you want your new project to use a source file called blob_track.cpp, so you would copy the opencv_sample rule and create a new blob_track rule, as shown below:

opencv_sample: opencv_sample.cpp
	$(CPP) $(CPFLAGS) $(API) $(CVLIBS) $(VISION_INCLUDES) -o $@ $^ -pthread 

blob_track: blob_track.cpp
	$(CPP) $(CPFLAGS) $(API) $(CVLIBS) $(VISION_INCLUDES) -o $@ $^ -pthread 

To make your project, you would just to back to the command line and type in 'make blob_track'. Do not modify any of the sample project code or any of the sample project entries in the Makefile.


Camera Related Functions

camera_forward()Sets the Camera to Face Forwards
camera_up()Raises the Camera Servo by 10 tics
camera_down()Lowers the Camera Servo by 10 tics
camera_set(uint8_t position)Sets the Camera Servo (0 to 180).

'Example Camera Command'

camera_set(75); // Aimed slightly down
camera_forward(); // Reset to forward

Gripper Related Functions

claw_open()Opens the Claw
claw_close()Closes the Claw
claw_grip_can()Closes the Claw on a Can
claw_set(uint8_t setting)Takes values from 0-30 (0 is fully closed).

'Example Gripper Command'

claw_set(15); // Open the claw halfway

LCD Related Functions

lcd_clear()Clears the LCD
lcd_set_cursor(int row,int col)Sets the cursor to a given position. 1-indexed (Top-Left is (1,1)).
lcd_write(char *message)Writes message to the LCD, starting at the cursor position.

'Example LCD Command'

char output[17] = {0};
lcd_set_cursor(2,1); // Set to the first character position of the bottom row
snprintf(output, 17, "Ball at %02d,%02d", ball_x, ball_y);

Movement Functions

robot_stop()Stops the Robot
move_robot(int8_t speed)Positive speed is forward, negative for reverse, ranging from -100 to 100.
move_distance(int8_t speed, int16_t distance)Distance is in cm, speed ranges from -100 to 100.
move_distance_wait(int8_t speed, int16_t distance)Blocking call. Distance is in cm, speed ranges from -100 to 100
move_wheels(int8_t speed_left, int8_t speed_right)Positive values are forward. Speeds range from -100 to 100
rotate_robot(int8_t speed)Rotates on center. Speeds range from -100 to 100
turn_robot(int8_t speed, int16_t degrees)Degrees must be positive. Control direction with speed, from -100 to 100
turn_robot_wait(int8_t speed, int16_t degrees)Blocking call. Degrees must be positive. Control direction with speed, from -100 to 100
arc_robot(int8_t speed, int8_t distance, int16_t degrees)Speed from -100 to 100, Distance in cm to center of arc, Degrees to arc
arc_robot_wait(int8_t speed, int8_t distance, int16_t degrees)Blocking. Speed from -100 to 100, Distance in cm to center of arc, Degrees to arc
wait_for_high_bump()Blocking. Waits until the high bump is hit
wait_for_low_bump()Blocking. Waits until the low bump is hit

'Example Movement Functions'

move_distance_wait(30, 150);
lcd_write("Moved 150cm Fwd");
while(get_ir(2) == -1) {
  turn_robot_wait(45, 90); // Turn 90 degrees while nothing on the forward IR
move_robot(10); // Slowly drive forward.

Robot/Motion Status Functions

start_sensors()Subscribe to the sensor messages. No sensor data will arrive before this is called.
stop_sensors()Unsubscribe from sensor messages.
reset_integrator()Resets the internal integrator. Call before first use of integrator data.
int8_t is_last_motion_complete()1 if the last prolonged motion completed, 0 otherwise
int8_t get_low_bump()1 for depressed, 0 for relaxed
int8_t get_high_bump()1 for depressed, 0 for relaxed
int16_t get_ir(ir)Returns dist in cm (0-RF, 1-R, 2-F, 3-L, 4-LF)
int16_t get_avg_ir(ir)Returns avg dist in cm (0-RF, 1-R, 2-F, 3-L, 4-LF) of last X packets (or 32767 if >50% show nothing)
int16_t get_robot_id()Returns the flockbot ID number
int16_t *get_ir_data()Returns a pointer to an array containing all of the IR values. FREE AFTER USE.
float get_angle()Gets the angle since the position of last reset_integrator(). Left increases. Returns float in RADIANS
float get_distance()Returns the total distance traveled in cm since reset_integrator().
float *get_pos()Returns an array representing the [X,Y] coordinates, in cm of the robot, where (0,0) is where the last reset_integrator() was called. FREE AFTER USE
int16_t *get_ww_tics()Returns an array representing the [Left,Right] WW tics. This zeros out when the robot stops, so it's only useful in motion. FREE AFTER USE
float get_battery()Returns the voltage of the battery. In volts.
print_sensor_data()Function to print all sensor data in an ASCII interface

'Example Status Functions'

while(get_battery() > 7.00) {
  move_distance_wait(50, 200); // Floor it for 200cm
  turn_robot_wait(50, 180);  // Turn around.

Timing/Blocking Functions

sleep(seconds)Seconds are measured in 1000 millisecond blocks
usleep(microseconds)Sleeps for up to 1000000 microseconds

Ravens Barcode Library API Functions (-lbarcode)

barcode_configure( num_digits, barcodes_per_pass, config_kept_passes, skip_pixel_width, min_bar_width, allowed_skew, threshold_value, camera_width, camera_height)Sets the number of digits to read in each barcode, the max barcodes
to track, the amount of historical passes to store, and the number
of pixels to skip between passes (e.g. skip_width=3 would scan the
first, fourth, seventh, etc. rows and columns in the image).
The majority of these setting impact the speed of the scan.
barcode_frame_wait()block until the next frame is processed
barcode_get_cur_xy(id)Returns an int[2] size array containing [x,y] values for barcode <id>,
if the id requested was seen in the last pass.
The calling behavior needs to free the array when finished with it.
barcode_get_last_xy(id)Returns an int[2] size array containing [x,y] values for
the last time barcode <id> was seen.
The calling behavior needs to free the array when finished with it.
barcode_get_barcodes()Returns an int[num_barcodes+2][num_digits+4] array.
Array[0] is an int containing the number of detected barcodes (X).
Array[1] is an int containing the number of digits in each barcodes (num_digits).
Array[i][num_digits-1] 0-(num_digits-1) contains the digits in the barcode
Array[i][num_digits+0-4] the next four integers contain barcode top_left_x, top_left_y, bottom_right_x, bottom_right_y, direction
The rest are the digits detected, up to num_digits.
The calling behavior needs to free the array when finished with it.
Edit - History - Print - Recent Changes - Search
Page last modified on September 07, 2015, at 02:49 PM