Commit 03ac5a1d authored by Jonathan Glück's avatar Jonathan Glück

New MKII update with comments on changes made in the library

parent 68c939e9
......@@ -37,7 +37,7 @@
#define SERVO_MIN_POSITION 10 // minimum servo position
#define SERVO_SET_1TICK_POSITION_DELAY_MS 3 // minimum duration of time between two servo steps
//----- PE- Barrier -----
//----- PE- barrier -----
#define H_LEFT_BARRIER_PIN 34
#define H_RIGHT_BARRIER_PIN 35
#define TURN 20
......@@ -47,7 +47,11 @@
#define DISTANCE_BETWEEN_WHEELS_MM 112
#define SCOPE_OF_ONE_TURN_MM PI*DISTANCE_BETWEEN_WHEELS_MM
#define TICKS_OF_ONE_TURN SCOPE_OF_ONE_TURN_MM/DISTANCE_PER_TICK_MM
#define TICKS_OF_ONE_DEGREE TICKS_OF_ONE_TURN/360
#define TICKS_OF_ONE_DEGREE 0.0889 //TICKS_OF_ONE_TURN/360
//----- Infrared sensor -----
#define H_INFRARED_SENSOR_LEFT 36
#define H_INFRARED_SENSOR_RIGHT 39
//----- Ultrasonic sensor -----
#define H_US_TRIG_PIN 21
......@@ -84,11 +88,16 @@ static volatile unsigned int left_step_stopcount=0;
static volatile unsigned int right_step_counter=0;
static volatile unsigned int right_step_stopcount=0;
static volatile bool syncstop= 0;
static volatile bool _drive;
static volatile bool obstacle_stop= false;
static volatile bool obstacle_left_side= false;
static volatile bool obstacle_right_side= false;
static volatile bool coderracer_activ = false;
static volatile bool right_button_pressed =false;
static volatile unsigned int right_button_count=0;
static volatile unsigned long left_button_last_pressed_at_ms = millis();
static volatile unsigned long right_button_last_pressed_at_ms = millis();
void global_stop_driving();
enum ledstate {
LEDOFF,
......@@ -120,6 +129,8 @@ class CodeRacerMKII {
uint8_t _servo_pin;
uint8_t _barrier_pin_left;
uint8_t _barrier_pin_right;
uint8_t _infrared_sensor_left;
uint8_t _infrared_sensor_right;
uint8_t _us_trigger_pin;
uint8_t _us_echo_pin;
uint8_t _drive_left_frwd_bkwrd_pin;
......@@ -160,7 +171,7 @@ class CodeRacerMKII {
unsigned long _servo_look_around_at_ms;
unsigned long _min_distance_cm;
bool _drive;
unsigned long _drive_set_at_ms;
bool _servo_sweep;
bool _coderracer_activ;
......@@ -172,6 +183,8 @@ class CodeRacerMKII {
static void _count_steps_right();
static void _set_button_state_left();
static void _set_button_state_right();
static void _stop_obstacle_left();
static void _stop_obstacle_right();
void _analog_write(uint8_t pin, uint8_t speed);
unsigned long _servo_set_position(uint8_t position);
......@@ -189,7 +202,7 @@ class CodeRacerMKII {
CodeRacerMKII();
CodeRacerMKII(uint8_t button_pin_left, uint8_t button_pin_right, uint8_t servo_pin,
uint8_t barrier_pin_left, uint8_t barrier_pin_right,
uint8_t barrier_pin_left, uint8_t barrier_pin_right, uint8_t infrared_sensor_left, uint8_t infrared_sensor_right,
uint8_t us_trigger_pin, uint8_t us_echo_pin,
uint8_t drive_left_frwd_bkwrd_pin, uint8_t drive_left_enable_pin,
uint8_t drive_right_frwd_bkwrd_pin, uint8_t drive_right_enable_pin,
......@@ -214,8 +227,12 @@ class CodeRacerMKII {
unsigned long turn_left_for_ms();
unsigned long turn_right_for_ms();
bool right_button_state();
bool is_obstacle_on_the_left();
bool is_obstacle_on_the_right();
unsigned int button_count();
unsigned int show_distance_mm();
unsigned int show_left_stepcounter();
unsigned int show_right_stepcounter();
// higher level {code}racer services
......@@ -262,6 +279,7 @@ class CodeRacerMKII {
void set_drive_left_state(drivestate state);
void set_drive_right_state(drivestate state);
void set_syncstop(bool state);
void set_obstacle_stop(bool state);
void set_drive_state(drivestate state, uint8_t fwrdbackpin, uint8_t enable_pin);
void set_drives_speed_left_right(uint8_t speedleft, uint8_t speedright);
void set_drive_left_speed(uint8_t speed);
......@@ -276,6 +294,10 @@ class CodeRacerMKII {
void drive_distance_mm(unsigned int leftdistance, unsigned int rightdistance);
void drive_distance_left_mm(int distance_mm);
void drive_distance_right_mm(int distance_mm);
bool obstacle_check_left_right();
bool obstacle_check_right();
bool obstacle_check_left();
bool obstacle_check (uint8_t sensorpin);
// Ultrasonic sensor
unsigned long usonic_measure_cm();
......
......@@ -15,6 +15,10 @@ drehrichtung drehung = links;
unsigned int anzahl_drehung = 0;
CodeRacerMKII coderacer;
int aabstand[160];
void filladistance();
int adegree[160];
int ispeed=1;
//---- Hier startet der Code zum Einstellen aller wichtigen Dinge. Setup() wird einmal ausgeführt. ----
void setup() {
// Monitor
......@@ -32,21 +36,39 @@ void setup() {
anzahl_drehung = 0;
drehung = links;
coderacer.set_syncstop(true);
coderacer.set_obstacle_stop(false);
coderacer.speed_settings(135, 135);
}
//---- Hier startet unsere endlose Schleife - die immer wieder von vorn angefangen wird, wenn wir am Ende angekommen sind. Da ist unser "Fahr"Code drin, der den CodeRacer steuert
void loop() {
void loop()
{
bool started = false;
while(coderacer.start_stop()== 1)
{
delay(2000);
coderacer.speed_settings(130, 130);
coderacer.turn_degree(180);
while(true== coderacer.is_driving())
{};
coderacer.turn_degree(-180);
delay(5000);
if(false == started)
{
started = true;
delay(1000);
}
unsigned int stepsprevl, stepsprevr ;
for(unsigned int v= 80;v<=255;v=v+10)
{
coderacer.speed_settings(v, v);
stepsprevl = coderacer.show_left_stepcounter();
stepsprevr = coderacer.show_right_stepcounter();
coderacer.drive_ticks_left(2000, true);
while (1== coderacer.is_driving()){}
Serial.printf("v=%i links*(2000)=%i rechts=%i\n",v, coderacer.show_left_stepcounter() - stepsprevl , coderacer.show_right_stepcounter() - stepsprevr);
}
}
}
//Serial.printf("links %i\n", coderacer.show_left_stepcounter());
//Serial.printf("rechts %i\n", coderacer.show_right_stepcounter());
//Serial.printf("%i\n", coderacer.show_distance_mm());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment