Analog_Sensor.c
· 2.9 KiB · C
Raw
#include <kipr/wombat.h>
// ============================================================
// ET SENSOR - DISTANCE
// ============================================================
// Drive forward until ET sensor reads an obstacle (analog > 2900)
void et_sensor_example() {
while (analog(1) <= 2900) {
motor(0, 50);
motor(3, 50);
}
ao();
msleep(100);
}
// ============================================================
// IR SENSOR / TOPHAT (Large or Small)
// ============================================================
// Find black: move forward until black detected, then back up off it
void find_black() {
// Move forward until black is detected
while (analog(1) <= 1580) {
printf("start loop move forward\n");
motor(0, 80);
motor(3, 80);
}
// Move backward until black is no longer detected
while (analog(1) >= 1580) {
printf("start loop move backward\n");
motor(0, -80);
motor(3, -80);
}
printf("start loop stops\n");
ao();
msleep(100);
}
// Follow the line (single sensor, basic)
void follow_line_basic() {
cmpc(0);
while (gmpc(0) < 40000) {
if (analog(1) < 3500) {
motor(0, 80);
motor(3, 5);
} else {
motor(0, 5);
motor(3, 80);
}
}
}
// Follow the line (single sensor, race speed with correction)
void follow_line_race() {
printf("follow the line 23.95\n");
int right = 0;
int left = 0;
cmpc(0);
while (gmpc(0) < 20000) {
if (analog(0) > 3750) {
motor(0, 25 - right);
motor(3, 100);
msleep(1);
right = right + 1;
left = left - 1;
msleep(1);
}
if (analog(0) < 3750) {
motor(3, 25 - left);
motor(0, 100);
msleep(1);
left = left + 1;
right = right - 1;
msleep(1);
}
printf("left %d and right %d\n", left, right);
}
}
// Follow the line (two sensors, with lever sensor stop)
void follow_line_two_sensors() {
int difference = 2000;
while (digital(0) == 0) { // while lever sensor is not pressed
if (analog(1) <= difference && analog(0) <= difference) {
// Both sensors on white: go forward
motor(0, 50);
motor(3, 50);
msleep(25);
printf("1\n");
} else if (analog(1) <= difference) {
// Sensor 1 on white: turn right
motor(0, -10);
motor(3, 50);
msleep(25);
printf("2\n");
} else if (analog(0) <= difference) {
// Sensor 0 on white: turn left
motor(0, 50);
motor(3, -10);
msleep(25);
printf("3\n");
} else {
// Both sensors on black: go forward
motor(0, 100);
motor(3, 100);
msleep(25);
printf("4\n");
}
}
}
| 1 | #include <kipr/wombat.h> |
| 2 | |
| 3 | // ============================================================ |
| 4 | // ET SENSOR - DISTANCE |
| 5 | // ============================================================ |
| 6 | // Drive forward until ET sensor reads an obstacle (analog > 2900) |
| 7 | void et_sensor_example() { |
| 8 | while (analog(1) <= 2900) { |
| 9 | motor(0, 50); |
| 10 | motor(3, 50); |
| 11 | } |
| 12 | ao(); |
| 13 | msleep(100); |
| 14 | } |
| 15 | |
| 16 | // ============================================================ |
| 17 | // IR SENSOR / TOPHAT (Large or Small) |
| 18 | // ============================================================ |
| 19 | |
| 20 | // Find black: move forward until black detected, then back up off it |
| 21 | void find_black() { |
| 22 | // Move forward until black is detected |
| 23 | while (analog(1) <= 1580) { |
| 24 | printf("start loop move forward\n"); |
| 25 | motor(0, 80); |
| 26 | motor(3, 80); |
| 27 | } |
| 28 | // Move backward until black is no longer detected |
| 29 | while (analog(1) >= 1580) { |
| 30 | printf("start loop move backward\n"); |
| 31 | motor(0, -80); |
| 32 | motor(3, -80); |
| 33 | } |
| 34 | printf("start loop stops\n"); |
| 35 | ao(); |
| 36 | msleep(100); |
| 37 | } |
| 38 | |
| 39 | // Follow the line (single sensor, basic) |
| 40 | void follow_line_basic() { |
| 41 | cmpc(0); |
| 42 | while (gmpc(0) < 40000) { |
| 43 | if (analog(1) < 3500) { |
| 44 | motor(0, 80); |
| 45 | motor(3, 5); |
| 46 | } else { |
| 47 | motor(0, 5); |
| 48 | motor(3, 80); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // Follow the line (single sensor, race speed with correction) |
| 54 | void follow_line_race() { |
| 55 | printf("follow the line 23.95\n"); |
| 56 | int right = 0; |
| 57 | int left = 0; |
| 58 | cmpc(0); |
| 59 | while (gmpc(0) < 20000) { |
| 60 | if (analog(0) > 3750) { |
| 61 | motor(0, 25 - right); |
| 62 | motor(3, 100); |
| 63 | msleep(1); |
| 64 | right = right + 1; |
| 65 | left = left - 1; |
| 66 | msleep(1); |
| 67 | } |
| 68 | if (analog(0) < 3750) { |
| 69 | motor(3, 25 - left); |
| 70 | motor(0, 100); |
| 71 | msleep(1); |
| 72 | left = left + 1; |
| 73 | right = right - 1; |
| 74 | msleep(1); |
| 75 | } |
| 76 | printf("left %d and right %d\n", left, right); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // Follow the line (two sensors, with lever sensor stop) |
| 81 | void follow_line_two_sensors() { |
| 82 | int difference = 2000; |
| 83 | while (digital(0) == 0) { // while lever sensor is not pressed |
| 84 | if (analog(1) <= difference && analog(0) <= difference) { |
| 85 | // Both sensors on white: go forward |
| 86 | motor(0, 50); |
| 87 | motor(3, 50); |
| 88 | msleep(25); |
| 89 | printf("1\n"); |
| 90 | } else if (analog(1) <= difference) { |
| 91 | // Sensor 1 on white: turn right |
| 92 | motor(0, -10); |
| 93 | motor(3, 50); |
| 94 | msleep(25); |
| 95 | printf("2\n"); |
| 96 | } else if (analog(0) <= difference) { |
| 97 | // Sensor 0 on white: turn left |
| 98 | motor(0, 50); |
| 99 | motor(3, -10); |
| 100 | msleep(25); |
| 101 | printf("3\n"); |
| 102 | } else { |
| 103 | // Both sensors on black: go forward |
| 104 | motor(0, 100); |
| 105 | motor(3, 100); |
| 106 | msleep(25); |
| 107 | printf("4\n"); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 |
Arm.c
· 1.4 KiB · C
Raw
#include <kipr/wombat.h>
// ============================================================
// ENABLE / DISABLE SERVOS
// ============================================================
void turn_arm_on() {
enable_servos();
}
void turn_arm_off() {
disable_servos();
}
// ============================================================
// SET START POSITION
// ============================================================
void set_start_position() {
set_servo_position(0, 734);
}
// ============================================================
// ARM ROTATION
// ============================================================
void rotate_up() {
set_servo_position(0, 724);
msleep(1000);
}
void rotate_down() {
set_servo_position(0, 1824);
msleep(1000);
}
// ============================================================
// CLAW
// ============================================================
void claw_open() {
set_servo_position(3, 724);
msleep(1000);
}
void claw_close() {
set_servo_position(3, 1933);
msleep(1000);
}
// ============================================================
// HELPER: RUN SERVO TO POSITION
// ============================================================
// Moves servo on 'port' to 'position', then stops all motors
void RunStart(int port, int position) {
enable_servos();
set_servo_position(port, position);
ao();
msleep(100);
}
| 1 | #include <kipr/wombat.h> |
| 2 | |
| 3 | // ============================================================ |
| 4 | // ENABLE / DISABLE SERVOS |
| 5 | // ============================================================ |
| 6 | void turn_arm_on() { |
| 7 | enable_servos(); |
| 8 | } |
| 9 | |
| 10 | void turn_arm_off() { |
| 11 | disable_servos(); |
| 12 | } |
| 13 | |
| 14 | // ============================================================ |
| 15 | // SET START POSITION |
| 16 | // ============================================================ |
| 17 | void set_start_position() { |
| 18 | set_servo_position(0, 734); |
| 19 | } |
| 20 | |
| 21 | // ============================================================ |
| 22 | // ARM ROTATION |
| 23 | // ============================================================ |
| 24 | void rotate_up() { |
| 25 | set_servo_position(0, 724); |
| 26 | msleep(1000); |
| 27 | } |
| 28 | |
| 29 | void rotate_down() { |
| 30 | set_servo_position(0, 1824); |
| 31 | msleep(1000); |
| 32 | } |
| 33 | |
| 34 | // ============================================================ |
| 35 | // CLAW |
| 36 | // ============================================================ |
| 37 | void claw_open() { |
| 38 | set_servo_position(3, 724); |
| 39 | msleep(1000); |
| 40 | } |
| 41 | |
| 42 | void claw_close() { |
| 43 | set_servo_position(3, 1933); |
| 44 | msleep(1000); |
| 45 | } |
| 46 | |
| 47 | // ============================================================ |
| 48 | // HELPER: RUN SERVO TO POSITION |
| 49 | // ============================================================ |
| 50 | // Moves servo on 'port' to 'position', then stops all motors |
| 51 | void RunStart(int port, int position) { |
| 52 | enable_servos(); |
| 53 | set_servo_position(port, position); |
| 54 | ao(); |
| 55 | msleep(100); |
| 56 | } |
| 57 |
Camera.c
· 304 B · C
Raw
#include <kipr/wombat.h>
// ============================================================
// CAMERA - FIND OBJECTS
// ============================================================
// No code has been added here yet.
//
// Reference: KIPR Camera Curriculum
// https://www.kipr.org/wombat-curriculum/camera
| 1 | #include <kipr/wombat.h> |
| 2 | |
| 3 | // ============================================================ |
| 4 | // CAMERA - FIND OBJECTS |
| 5 | // ============================================================ |
| 6 | // No code has been added here yet. |
| 7 | // |
| 8 | // Reference: KIPR Camera Curriculum |
| 9 | // https://www.kipr.org/wombat-curriculum/camera |
| 10 |
Digital_Sensor.c
· 1.1 KiB · C
Raw
#include <kipr/wombat.h>
// ============================================================
// TOUCH SENSOR (Lever, Small Touch, Large Touch)
// ============================================================
// Drive forward until touch sensor 0 is pressed,
// then drive backward until touch sensor 1 is pressed
void touch_sensor_example() {
while (digital(0) == 0) {
motor(0, 100);
motor(3, 100);
}
ao();
msleep(1000);
while (digital(1) == 0) {
motor(0, -100);
motor(3, -100);
}
ao();
msleep(1000);
}
// ============================================================
// WAIT FOR LIGHT
// ============================================================
void wait_for_light_example() {
wait_for_light(0);
}
// Wait for light with button confirmation
void wait_for_light_with_button() {
if (push_button() == 1) {
wait_for_light(0);
}
}
// ============================================================
// SHUT DOWN
// ============================================================
// Shuts down all motors after 119 seconds (just under 2 minutes)
void shutdown_example() {
shut_down_in(119);
}
| 1 | #include <kipr/wombat.h> |
| 2 | |
| 3 | // ============================================================ |
| 4 | // TOUCH SENSOR (Lever, Small Touch, Large Touch) |
| 5 | // ============================================================ |
| 6 | // Drive forward until touch sensor 0 is pressed, |
| 7 | // then drive backward until touch sensor 1 is pressed |
| 8 | void touch_sensor_example() { |
| 9 | while (digital(0) == 0) { |
| 10 | motor(0, 100); |
| 11 | motor(3, 100); |
| 12 | } |
| 13 | ao(); |
| 14 | msleep(1000); |
| 15 | |
| 16 | while (digital(1) == 0) { |
| 17 | motor(0, -100); |
| 18 | motor(3, -100); |
| 19 | } |
| 20 | ao(); |
| 21 | msleep(1000); |
| 22 | } |
| 23 | |
| 24 | // ============================================================ |
| 25 | // WAIT FOR LIGHT |
| 26 | // ============================================================ |
| 27 | void wait_for_light_example() { |
| 28 | wait_for_light(0); |
| 29 | } |
| 30 | |
| 31 | // Wait for light with button confirmation |
| 32 | void wait_for_light_with_button() { |
| 33 | if (push_button() == 1) { |
| 34 | wait_for_light(0); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | // ============================================================ |
| 39 | // SHUT DOWN |
| 40 | // ============================================================ |
| 41 | // Shuts down all motors after 119 seconds (just under 2 minutes) |
| 42 | void shutdown_example() { |
| 43 | shut_down_in(119); |
| 44 | } |
| 45 |
Drive.c
· 1.8 KiB · C
Raw
#include <kipr/wombat.h>
// ============================================================
// PAUSE
// ============================================================
// Stop all motors and wait 2 seconds
void pause_example() {
ao();
msleep(2000);
}
// ============================================================
// FORWARD
// ============================================================
void forward_example() {
motor(0, 100);
motor(3, 100);
msleep(250);
}
// Forward using MAV (Motor Absolute Velocity)
void Move(int l_power, int r_power, int time) {
mav(0, l_power);
mav(3, r_power);
msleep(time);
ao();
sleep(100);
}
// ============================================================
// BACKWARD
// ============================================================
void backward_example() {
motor(0, -100);
motor(3, -100);
msleep(250);
}
// ============================================================
// TURN 90 DEGREES RIGHT
// ============================================================
void turn_right_90() {
motor(0, 0);
motor(3, 100);
msleep(1500);
}
// ============================================================
// TURN 90 DEGREES LEFT
// ============================================================
void turn_left_90() {
motor(0, 100);
motor(3, 0);
msleep(1500);
}
// ============================================================
// MOTOR POSITION COUNTER
// ============================================================
// Counts "ticks" - one complete wheel rotation
// Motors have approximately 1820 ticks per revolution
void motor_position_counter_example() {
clear_motor_position_counter(3);
while (get_motor_position_counter(3) < 4000) {
motor(3, 50);
motor(0, 50);
}
ao();
}
| 1 | #include <kipr/wombat.h> |
| 2 | |
| 3 | // ============================================================ |
| 4 | // PAUSE |
| 5 | // ============================================================ |
| 6 | // Stop all motors and wait 2 seconds |
| 7 | void pause_example() { |
| 8 | ao(); |
| 9 | msleep(2000); |
| 10 | } |
| 11 | |
| 12 | // ============================================================ |
| 13 | // FORWARD |
| 14 | // ============================================================ |
| 15 | void forward_example() { |
| 16 | motor(0, 100); |
| 17 | motor(3, 100); |
| 18 | msleep(250); |
| 19 | } |
| 20 | |
| 21 | // Forward using MAV (Motor Absolute Velocity) |
| 22 | void Move(int l_power, int r_power, int time) { |
| 23 | mav(0, l_power); |
| 24 | mav(3, r_power); |
| 25 | msleep(time); |
| 26 | ao(); |
| 27 | sleep(100); |
| 28 | } |
| 29 | |
| 30 | // ============================================================ |
| 31 | // BACKWARD |
| 32 | // ============================================================ |
| 33 | void backward_example() { |
| 34 | motor(0, -100); |
| 35 | motor(3, -100); |
| 36 | msleep(250); |
| 37 | } |
| 38 | |
| 39 | // ============================================================ |
| 40 | // TURN 90 DEGREES RIGHT |
| 41 | // ============================================================ |
| 42 | void turn_right_90() { |
| 43 | motor(0, 0); |
| 44 | motor(3, 100); |
| 45 | msleep(1500); |
| 46 | } |
| 47 | |
| 48 | // ============================================================ |
| 49 | // TURN 90 DEGREES LEFT |
| 50 | // ============================================================ |
| 51 | void turn_left_90() { |
| 52 | motor(0, 100); |
| 53 | motor(3, 0); |
| 54 | msleep(1500); |
| 55 | } |
| 56 | |
| 57 | // ============================================================ |
| 58 | // MOTOR POSITION COUNTER |
| 59 | // ============================================================ |
| 60 | // Counts "ticks" - one complete wheel rotation |
| 61 | // Motors have approximately 1820 ticks per revolution |
| 62 | void motor_position_counter_example() { |
| 63 | clear_motor_position_counter(3); |
| 64 | while (get_motor_position_counter(3) < 4000) { |
| 65 | motor(3, 50); |
| 66 | motor(0, 50); |
| 67 | } |
| 68 | ao(); |
| 69 | } |
| 70 |
Mecanum_Drive.c
· 3.3 KiB · C
Raw
#include <kipr/wombat.h>
// ============================================================
// BACKWARD
// ============================================================
void backward() {
motor(0, -100);
motor(1, -100);
motor(2, -100);
motor(3, -100);
msleep(3000);
}
// ============================================================
// FORWARD
// ============================================================
void forward() {
motor(1, 100);
motor(2, 100);
motor(3, 100);
msleep(3000);
}
// ============================================================
// LEFT DIAGONAL
// ============================================================
// ⚠️ NOTE: This function is named turn_left_90 but implements
// a LEFT DIAGONAL movement, not a 90-degree turn. Rename before
// using in competition code.
void turn_left_90_LEFT_DIAGONAL() {
cmpc(1);
while (gmpc(1) < 1350) {
motor(0, 0);
motor(1, 100);
motor(2, 0);
motor(3, 100);
}
ao();
}
// ============================================================
// LEFT SIDEWAYS
// ============================================================
// ⚠️ NOTE: This function is named turn_left_90 but implements
// a LEFT SIDEWAYS (strafe) movement. Rename before using in
// competition code.
void turn_left_90_LEFT_SIDEWAYS() {
cmpc(0);
while (gmpc(0) < 1350) {
motor(0, 100);
motor(1, -100);
motor(2, 100);
motor(3, -100);
}
ao();
}
// ============================================================
// RIGHT DIAGONAL
// ============================================================
// ⚠️ NOTE: This function is named turn_left_90 but implements
// a RIGHT DIAGONAL movement. Rename before using in competition
// code.
void turn_left_90_RIGHT_DIAGONAL() {
cmpc(0);
while (gmpc(0) < 1350) {
motor(0, 100);
motor(1, 0);
motor(2, 100);
motor(3, 0);
}
ao();
}
// ============================================================
// RIGHT SIDEWAYS
// ============================================================
// ⚠️ NOTE: This function is named turn_left_90 but implements
// a RIGHT SIDEWAYS (strafe) movement. Rename before using in
// competition code.
void turn_left_90_RIGHT_SIDEWAYS() {
cmpc(0);
while (gmpc(0) < 1350) {
motor(0, -100);
motor(1, 100);
motor(2, -100);
motor(3, 100);
}
ao();
}
// ============================================================
// MOTOR POSITION COUNTER (FORWARD WITH MPC)
// ============================================================
// ⚠️ NOTE: This snippet has structural issues — the forward()
// function is defined inside turn_left_90() and the code is
// missing closing braces. Needs a full rewrite before use.
// Preserved here as-is for reference only.
/*
void turn_left_90_MPC_BROKEN() {
cmpc(0);
while (gmpc(0) < 1350) {
motor(0, 100);
motor(1, -100);
motor(2, 100);
motor(3, -100);
ao();
}
void forward() { // <-- function defined inside function: NOT valid C
cmpc(0);
while (gmpc(0) < 2000) {
motor(0, 100);
motor(1, 100);
motor(2, 100);
motor(3, 100);
msleep(3000);
ao();
// missing closing braces
*/
| 1 | #include <kipr/wombat.h> |
| 2 | |
| 3 | // ============================================================ |
| 4 | // BACKWARD |
| 5 | // ============================================================ |
| 6 | void backward() { |
| 7 | motor(0, -100); |
| 8 | motor(1, -100); |
| 9 | motor(2, -100); |
| 10 | motor(3, -100); |
| 11 | msleep(3000); |
| 12 | } |
| 13 | |
| 14 | // ============================================================ |
| 15 | // FORWARD |
| 16 | // ============================================================ |
| 17 | void forward() { |
| 18 | motor(1, 100); |
| 19 | motor(2, 100); |
| 20 | motor(3, 100); |
| 21 | msleep(3000); |
| 22 | } |
| 23 | |
| 24 | // ============================================================ |
| 25 | // LEFT DIAGONAL |
| 26 | // ============================================================ |
| 27 | // ⚠️ NOTE: This function is named turn_left_90 but implements |
| 28 | // a LEFT DIAGONAL movement, not a 90-degree turn. Rename before |
| 29 | // using in competition code. |
| 30 | void turn_left_90_LEFT_DIAGONAL() { |
| 31 | cmpc(1); |
| 32 | while (gmpc(1) < 1350) { |
| 33 | motor(0, 0); |
| 34 | motor(1, 100); |
| 35 | motor(2, 0); |
| 36 | motor(3, 100); |
| 37 | } |
| 38 | ao(); |
| 39 | } |
| 40 | |
| 41 | // ============================================================ |
| 42 | // LEFT SIDEWAYS |
| 43 | // ============================================================ |
| 44 | // ⚠️ NOTE: This function is named turn_left_90 but implements |
| 45 | // a LEFT SIDEWAYS (strafe) movement. Rename before using in |
| 46 | // competition code. |
| 47 | void turn_left_90_LEFT_SIDEWAYS() { |
| 48 | cmpc(0); |
| 49 | while (gmpc(0) < 1350) { |
| 50 | motor(0, 100); |
| 51 | motor(1, -100); |
| 52 | motor(2, 100); |
| 53 | motor(3, -100); |
| 54 | } |
| 55 | ao(); |
| 56 | } |
| 57 | |
| 58 | // ============================================================ |
| 59 | // RIGHT DIAGONAL |
| 60 | // ============================================================ |
| 61 | // ⚠️ NOTE: This function is named turn_left_90 but implements |
| 62 | // a RIGHT DIAGONAL movement. Rename before using in competition |
| 63 | // code. |
| 64 | void turn_left_90_RIGHT_DIAGONAL() { |
| 65 | cmpc(0); |
| 66 | while (gmpc(0) < 1350) { |
| 67 | motor(0, 100); |
| 68 | motor(1, 0); |
| 69 | motor(2, 100); |
| 70 | motor(3, 0); |
| 71 | } |
| 72 | ao(); |
| 73 | } |
| 74 | |
| 75 | // ============================================================ |
| 76 | // RIGHT SIDEWAYS |
| 77 | // ============================================================ |
| 78 | // ⚠️ NOTE: This function is named turn_left_90 but implements |
| 79 | // a RIGHT SIDEWAYS (strafe) movement. Rename before using in |
| 80 | // competition code. |
| 81 | void turn_left_90_RIGHT_SIDEWAYS() { |
| 82 | cmpc(0); |
| 83 | while (gmpc(0) < 1350) { |
| 84 | motor(0, -100); |
| 85 | motor(1, 100); |
| 86 | motor(2, -100); |
| 87 | motor(3, 100); |
| 88 | } |
| 89 | ao(); |
| 90 | } |
| 91 | |
| 92 | // ============================================================ |
| 93 | // MOTOR POSITION COUNTER (FORWARD WITH MPC) |
| 94 | // ============================================================ |
| 95 | // ⚠️ NOTE: This snippet has structural issues — the forward() |
| 96 | // function is defined inside turn_left_90() and the code is |
| 97 | // missing closing braces. Needs a full rewrite before use. |
| 98 | // Preserved here as-is for reference only. |
| 99 | /* |
| 100 | void turn_left_90_MPC_BROKEN() { |
| 101 | cmpc(0); |
| 102 | while (gmpc(0) < 1350) { |
| 103 | motor(0, 100); |
| 104 | motor(1, -100); |
| 105 | motor(2, 100); |
| 106 | motor(3, -100); |
| 107 | ao(); |
| 108 | } |
| 109 | void forward() { // <-- function defined inside function: NOT valid C |
| 110 | cmpc(0); |
| 111 | while (gmpc(0) < 2000) { |
| 112 | motor(0, 100); |
| 113 | motor(1, 100); |
| 114 | motor(2, 100); |
| 115 | motor(3, 100); |
| 116 | msleep(3000); |
| 117 | ao(); |
| 118 | // missing closing braces |
| 119 | */ |
| 120 |
Test_Program.c
· 835 B · C
Raw
// Test program: verifies all motors and servos are functioning.
// Run this on the robot before competition to check hardware.
#include <kipr/wombat.h>
void test_servo(int port) {
printf("testing servo %d\n", port);
printf("\tup 2 seconds\n");
enable_servo(port);
enable_servos();
set_servo_position(port, 0);
msleep(2000);
set_servo_position(port, 2047);
msleep(2000);
disable_servo(port);
disable_servos();
}
void test_motor(int port) {
printf("testing motor %d\n", port);
printf("\tforward 2 seconds\n");
motor(port, 100);
msleep(2000);
printf("\tbackward 2 seconds\n");
motor(port, -100);
msleep(2000);
ao();
}
int main() {
test_motor(0);
test_motor(1);
test_motor(2);
test_motor(3);
test_servo(0);
test_servo(1);
return 0;
}
| 1 | // Test program: verifies all motors and servos are functioning. |
| 2 | // Run this on the robot before competition to check hardware. |
| 3 | |
| 4 | #include <kipr/wombat.h> |
| 5 | |
| 6 | void test_servo(int port) { |
| 7 | printf("testing servo %d\n", port); |
| 8 | printf("\tup 2 seconds\n"); |
| 9 | enable_servo(port); |
| 10 | enable_servos(); |
| 11 | set_servo_position(port, 0); |
| 12 | msleep(2000); |
| 13 | set_servo_position(port, 2047); |
| 14 | msleep(2000); |
| 15 | disable_servo(port); |
| 16 | disable_servos(); |
| 17 | } |
| 18 | |
| 19 | void test_motor(int port) { |
| 20 | printf("testing motor %d\n", port); |
| 21 | printf("\tforward 2 seconds\n"); |
| 22 | motor(port, 100); |
| 23 | msleep(2000); |
| 24 | printf("\tbackward 2 seconds\n"); |
| 25 | motor(port, -100); |
| 26 | msleep(2000); |
| 27 | ao(); |
| 28 | } |
| 29 | |
| 30 | int main() { |
| 31 | test_motor(0); |
| 32 | test_motor(1); |
| 33 | test_motor(2); |
| 34 | test_motor(3); |
| 35 | test_servo(0); |
| 36 | test_servo(1); |
| 37 | return 0; |
| 38 | } |
| 39 |
Comments
No comments yet.
Log in to leave a comment.