<commit_before>#include "defines.h"
#include "motor_api.h"
#include "distance_sensor_api.h"

Motor motor_conveyor, motor_feeder;
Ultra_Sound_Sensor distance_sensor;

int32_t distance_to_wall;

void setup()
{
    Serial.begin(9600);

    motor_init(&motor_conveyor, 0.36, MOTOR_CONVEYOR_PIN, 
        MOTOR_CONVEYOR_INT_PIN, motor_conveyor_interrupt);
    motor_init(&motor_feeder, 1.0, MOTOR_FEEDER_PIN, MOTOR_FEEDER_INT_PIN, 
        motor_feeder_interrupt);
    distance_sensor_init(&distance_sensor, RANGE_TRIG, RANGE_ECHO);
    
    distance_to_wall = calibrate_ultra_sound_sensor();
    delay(1000);
    Serial.print("Distance to wall: ");
    Serial.println(distance_to_wall);
    delay(2500);
    motor_turn(&motor_conveyor);
    feed_ball();
}

void loop()
{
    int32_t test_dist = distance_sensor_double_take(); //distance_sensor_measure_distance(&distance_sensor);
    //Serial.println(test_dist);

    if(test_dist + 10 < distance_to_wall)
    {
        Serial.print("Log: ");
        Serial.println(millis());
    }

    static uint32_t time = millis();
    if (time + 5000 < millis())
    {
        feed_ball();
        time = millis();
    }

    return;
    uint32_t pos = motor_get_degrees(&motor_conveyor);
    // Change TARGET1 for delay before requesting image
    while(pos + 225 > motor_get_degrees(&motor_conveyor)) {}
    Serial.print("Command:");
    Serial.print(2);
    Serial.println("end");
    // Change TARGET2 for delay after requesting image
    while(pos + 720 > motor_get_degrees(&motor_conveyor)) {}
    feed_ball();
}

void motor_conveyor_interrupt()
{
    motor_update_degrees(&motor_conveyor);
}

void motor_feeder_interrupt()
{
    motor_update_degrees(&motor_feeder);
}

void feed_ball() 
{
  static int16_t deg = 90;
  
    motor_turn_to_degree(&motor_feeder, deg);

    deg += 90;
    if (deg == 360) 
        deg = 0;
}

int32_t calibrate_ultra_sound_sensor()
{<commit_msg>mi-test: changed timer<commit_after>#include "defines.h"
#include "motor_api.h"
#include "distance_sensor_api.h"

Motor motor_conveyor, motor_feeder;
Ultra_Sound_Sensor distance_sensor;

int32_t distance_to_wall;

void setup()
{
    Serial.begin(9600);

    motor_init(&motor_conveyor, 0.36, MOTOR_CONVEYOR_PIN, 
        MOTOR_CONVEYOR_INT_PIN, motor_conveyor_interrupt);
    motor_init(&motor_feeder, 1.0, MOTOR_FEEDER_PIN, MOTOR_FEEDER_INT_PIN, 
        motor_feeder_interrupt);
    distance_sensor_init(&distance_sensor, RANGE_TRIG, RANGE_ECHO);
    
    distance_to_wall = calibrate_ultra_sound_sensor();
    delay(1000);
    Serial.print("Distance to wall: ");
    Serial.println(distance_to_wall);
    delay(2500);
    motor_turn(&motor_conveyor);
    feed_ball();
}

void loop()
{
    //int32_t test_dist = distance_sensor_double_take(); //distance_sensor_measure_distance(&distance_sensor);
    //Serial.println(test_dist);

/*
    if(test_dist + 10 < distance_to_wall)
    {
        Serial.print("Log: ");
        Serial.println(millis());
    }

    static uint32_t time = millis();
    if (time + 5000 < millis())
    {
        feed_ball();
        time = millis();
    }

    return;
    */

    uint32_t pos = motor_get_degrees(&motor_conveyor);
    // Change TARGET1 for delay before requesting image
    while(pos + 270 > motor_get_degrees(&motor_conveyor)) {}
    Serial.print("Command:");
    Serial.print(2);
    Serial.println("end");
    // Change TARGET2 for delay after requesting image
    while(pos + 720 > motor_get_degrees(&motor_conveyor)) {}
    feed_ball();
}

void motor_conveyor_interrupt()
{
    motor_update_degrees(&motor_conveyor);
}

void motor_feeder_interrupt()
{
    motor_update_degrees(&motor_feeder);
}

void feed_ball() 
{
  static int16_t deg = 90;
  
    motor_turn_to_degree(&motor_feeder, deg);

    deg += 90;
    if (deg == 360) 
        deg = 0;
}

int32_t calibrate_ultra_sound_sensor()
{
{'fraction_non_alphanumeric': 0.11825726141078838, 'fraction_numerical': 0.026970954356846474, 'mean_word_length': 3.791304347826087, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4866258', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1372, 'n_words': 228}