summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-05-26 17:56:56 +0200
committerlonkaars <loek@pipeframe.xyz>2022-05-26 17:56:56 +0200
commite4b0a76f56e290b7b052b4d5dad7ebb710f12c98 (patch)
treeafc14712cc67ea1550b830056ca5055c568fec3e
parent6a1c9853402f623ef9eba76556a9a0213f04d3c8 (diff)
fix merge conflicts
-rw-r--r--robot/io.c68
-rw-r--r--robot/io.h64
-rw-r--r--robot/mode_scal.c18
-rw-r--r--robot/orangutan_shim.h1
-rw-r--r--shared/consts.h7
5 files changed, 75 insertions, 83 deletions
diff --git a/robot/io.c b/robot/io.c
index 5757ffd..f5fcffc 100644
--- a/robot/io.c
+++ b/robot/io.c
@@ -1,52 +1,30 @@
#include "io.h"
-#include <pololu/orangutan.h>
+#include "../shared/consts.h"
+#include "modes.h"
+#include "orangutan_shim.h"
-
-w2_io_all global;
+w2_io_all g_w2_io;
void w2_io_main() {
- global.button[0] = get_single_debounced_button_press(BUTTON_A);
- global.button[1] = get_single_debounced_button_press(BUTTON_B);
- global.button[2] = get_single_debounced_button_press(BUTTON_C);
- global.button[3] = get_single_debounced_button_press(TOP_BUTTON);
- global.button[4] = get_single_debounced_button_press(BOTTOM_BUTTON);
- unsigned int sensor_values[5];
- qtr_read(sensor_values, QTR_EMITTERS_ON);
- for(int i = 0; i <5; i++){
- global.qtrSensor[i] = sensor_values[i];
- }
- // TODO average voltage over mutiple samples sensor
- global.batteryLevel = analog_read(BATTERY_PIN);
- global.frontDetection = analog_read(FRONT_SENSOR_PIN);
- global.sideDetection = analog_read(SIDE_SENSOR_PIN);
+ g_w2_io.button[0].pressed = get_single_debounced_button_press(BUTTON_A);
+ g_w2_io.button[1].pressed = get_single_debounced_button_press(BUTTON_B);
+ g_w2_io.button[2].pressed = get_single_debounced_button_press(BUTTON_C);
+ g_w2_io.button[3].pressed = get_single_debounced_button_press(TOP_BUTTON);
+ g_w2_io.button[4].pressed = get_single_debounced_button_press(BOTTOM_BUTTON);
+ unsigned int sensor_values[5];
+ qtr_read(sensor_values, QTR_EMITTERS_ON);
+ for (int i = 0; i < 5; i++) {
+ g_w2_io.qtr[i].range = sensor_values[i];
+ }
+ // TODO average voltage over mutiple samples sensor
+ g_w2_io.battery.charge_level = analog_read(W2_BATTERY_PIN);
+ g_w2_io.front_distance.detection = analog_read(W2_FRONT_SENSOR_PIN);
+ g_w2_io.side_distance.detection = analog_read(W2_SIDE_SENSOR_PIN);
- set_motors(global.motor_left, global.motor_right);
- red_led(global.led_red);
- green_led(global.led_green);
- print_character(global.lcd);
+ set_motors(g_w2_io.motor_left.speed, g_w2_io.motor_right.speed);
+ red_led(g_w2_io.led_red.on);
+ green_led(g_w2_io.led_green.on);
+ print(g_w2_io.lcd.text);
};
-void w2_io_init(){
- pololu_3pi_init(2000):
-
- for(counter=0;counter<80;counter++)
- {
- if(counter < 20 || counter >= 60)
- {
- global.motor_left=40;
- global.motor_right=-40;
- }
- else
- {
- global.motor_left=-40;
- global.motor_right=40;
- }
-
- calibrate_
- line_sensors(IR_EMITTERS_ON);
-
- delay_ms(20);
- }
- global.motor_left=0;
- global.motor_right=0;
-} \ No newline at end of file
+void w2_io_init() { w2_modes_call(W2_M_SCAL); }
diff --git a/robot/io.h b/robot/io.h
index e262fa1..6c2d262 100644
--- a/robot/io.h
+++ b/robot/io.h
@@ -1,56 +1,46 @@
#pragma once
-#include <stdlib.h>
-#include <stdint.h>
#include <stdbool.h>
-#define FRONT_SENSOR_PIN 5
-#define SIDE_SENSOR_PIN 7
-#define BATTERY_PIN 6
-
-//inputs
+#include <stdint.h>
+#include <stdlib.h>
typedef struct {
- bool pressed;
-} w2_s_io_push;
+ bool pressed;
+} w2_s_i_push;
typedef struct {
- uint16_t range;
-
-} w2_s_io_contrast;
+ uint16_t range;
+} w2_s_i_contrast;
typedef struct {
- uint16_t detection;
-} w2_s_io_distance;
-
-//outputs
+ uint16_t detection;
+} w2_s_i_distance;
typedef struct {
- int speed;
-} w2_s_io_motor;
+ uint16_t charge_level;
+} w2_s_i_battery;
typedef struct {
- bool toggle;
-} w2_s_io_led;
+ int speed;
+} w2_s_o_motor;
typedef struct {
- char text[16];
-} w2_s_io_display;
-typedef struct {
- uint8_t charged;
-} w2_s_io_battery;
-
-//all i/o
+ bool on;
+} w2_s_o_led;
typedef struct {
- w2_s_i_push button[5];
- w2_s_i_contrast qtrSensor[5];
- w2_s_i_distance frontDetection;
- w2_s_i_distance sideDetection;
- w2_s_i_battery batteryLevel;
+ char text[17]; // 16 chars + '\0'
+} w2_s_o_display;
+typedef struct {
+ w2_s_i_push button[5];
+ w2_s_i_contrast qtr[5];
+ w2_s_i_distance front_distance;
+ w2_s_i_distance side_distance;
+ w2_s_i_battery battery;
- w2_s_o_motor motor_left;
- w2_s_o_motor motor_right;
- w2_s_o_led led_red;
- w2_s_o_led led_green;
- w2_s_o_display lcd;
+ w2_s_o_motor motor_left;
+ w2_s_o_motor motor_right;
+ w2_s_o_led led_red;
+ w2_s_o_led led_green;
+ w2_s_o_display lcd;
} w2_io_all;
diff --git a/robot/mode_scal.c b/robot/mode_scal.c
index e3a9c97..f3178d7 100644
--- a/robot/mode_scal.c
+++ b/robot/mode_scal.c
@@ -1,3 +1,19 @@
#include "mode_scal.h"
-void w2_mode_scal() {}
+void w2_mode_scal() {
+ // TODO ???
+ /* pololu_3pi_init(2000);
+ for (int counter = 0; counter < 80; counter++) {
+ if (counter < 20 || counter >= 60) {
+ g_w2_io.motor_left.speed = 40;
+ g_w2_io.motor_right.speed = -40;
+ } else {
+ g_w2_io.motor_left.speed = -40;
+ g_w2_io.motor_right.speed = 40;
+ }
+
+ calibrate_line_sensors(IR_EMITTERS_ON);
+
+ delay_ms(20); // TODO foei
+ } */
+}
diff --git a/robot/orangutan_shim.h b/robot/orangutan_shim.h
index cd624d0..10420bd 100644
--- a/robot/orangutan_shim.h
+++ b/robot/orangutan_shim.h
@@ -5,6 +5,7 @@
#else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
+#include <pololu/3pi.h>
#include <pololu/orangutan.h>
#pragma GCC diagnostic pop
#endif
diff --git a/shared/consts.h b/shared/consts.h
index 25ca94f..c65e50f 100644
--- a/shared/consts.h
+++ b/shared/consts.h
@@ -19,3 +19,10 @@
#define W2_EMA_WEIGHT (0.10)
/** size of mode history buffer */
#define W2_MODE_HISTORY_BUFFER_SIZE (4)
+
+/** front-facing distance sensor pinout */
+#define W2_FRONT_SENSOR_PIN 5
+/** battery voltage sensor pinout */
+#define W2_BATTERY_PIN 6
+/** side-facing distance sensor pinout */
+#define W2_SIDE_SENSOR_PIN 7 \ No newline at end of file