summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter de Kok <p.j.s.d.kok@gmail.com>2015-06-12 10:01:58 +0200
committerPeter de Kok <p.j.s.d.kok@gmail.com>2015-06-12 10:01:58 +0200
commitac96b44c6ad1b2c7557e0539dfd569f66b9f5631 (patch)
treea3487579a5cc252c22f061a71da57fdd4f5f9600
parent56a80aab7c1ca010c51dc7e6460efd3d39b453fc (diff)
parent5f926a60d2c80ed00665d6a09690b90ce531d8a2 (diff)
downloadcode-ac96b44c6ad1b2c7557e0539dfd569f66b9f5631.tar.gz
Merge branch 'master' of git.lekensteyn.nl:tue/5XIB0-Venus/code
-rw-r--r--.gitignore1
-rw-r--r--Venus_Skeleton/Makefile43
-rw-r--r--Venus_Skeleton/Venus_Skeleton.ino55
-rw-r--r--Venus_Skeleton/calibration_wall-e.h6
-rw-r--r--Venus_Skeleton/comm.h19
-rw-r--r--Venus_Skeleton/comm.ino (renamed from Venus_Skeleton/comm.cpp)0
-rw-r--r--Venus_Skeleton/dataTypes.h5
7 files changed, 74 insertions, 55 deletions
diff --git a/.gitignore b/.gitignore
index 4fe7862..492658d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
.*.sw?
__pycache__/
*.py[oc]
+bin/
diff --git a/Venus_Skeleton/Makefile b/Venus_Skeleton/Makefile
index c2c5198..f150b58 100644
--- a/Venus_Skeleton/Makefile
+++ b/Venus_Skeleton/Makefile
@@ -1,35 +1,16 @@
-#CC = /usr/share/arduino/hardware/tools/avr/bin/avr-gcc
-CC = avr-gcc
-WFLAGS = -Wall -Wextra -Wno-attributes
-WFLAGS += -fdiagnostics-color=auto
-EXTRA_CFLAGS = $(shell cat .syntastic_c_config) -O2 $(CFLAGS)
-MY_SOURCES = Venus_Skeleton.ino comm.cpp
-MY_OBJECTS = $(patsubst %.cpp,%.o,$(patsubst %.ino,%.o,$(MY_SOURCES)))
-LIBS_SOURCES = $(wildcard libs/*/*.cpp)
-LIBS_OBJECTS = $(patsubst %.cpp,%.o,$(LIBS_SOURCES))
-SOURCES = $(MY_SOURCES) $(LIBS_SOURCES)
-OBJECTS = $(MY_OBJECTS) $(LIBS_OBJECTS)
-PROGRAM ?= main
+PROJECT = Venus_Skeleton
+ARDUINO_MODEL = uno
+#PORT = /dev/ttyACM*
+ARDUINO = 163
+#ARDUINO_DIR = /usr/share/arduino
+#ARDUINO_VARIANT = $(ARDUINO_DIR)/hardware/arduino/avr/variants/standard
-_V_0 = @
-_V = $(_V_$(V))
+ARDUINO_LIBS = Serial Servo Wire
+USER_LIBDIR = ./libs
+USER_LIBS = HMC5883L IRremote TrueRandom
-.PHONY: main clean check
-check:
- rm -f $(MY_OBJECTS)
- $(MAKE) $(MY_OBJECTS)
-# Note: does not compile due to link errors.
-$(PROGRAM): $(OBJECTS)
- $(_V)$(CC) $(WFLAGS) $(EXTRA_CFLAGS) $(OBJECTS) -o $@
+CEXTRA = -fdiagnostics-color=auto
+#CEXTRA += -Wall -Wextra -Wno-attributes
-clean:
- $(_V)rm -f $(PROGRAM) $(OBJECTS)
-
-# Not my code...
-libs/%.o: libs/%.cpp
- $(_V)$(CC) -w $(EXTRA_CFLAGS) -c -o $@ $<
-%.o: %.cpp
- $(_V)$(CC) $(WFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
-%.o: %.ino
- $(_V)$(CC) $(WFLAGS) $(EXTRA_CFLAGS) -c -x c++ -o $@ $<
+include ~/Arduino/arduino-makefile/Makefile
diff --git a/Venus_Skeleton/Venus_Skeleton.ino b/Venus_Skeleton/Venus_Skeleton.ino
index f766a75..82ebc3d 100644
--- a/Venus_Skeleton/Venus_Skeleton.ino
+++ b/Venus_Skeleton/Venus_Skeleton.ino
@@ -16,14 +16,6 @@
// 2 Error: Sensor Obstacle detection on the turret
// 3 Error: Sensor IR Line detection
-#define DEBUG true
-
-#ifdef DEBUG
-#define DEBUG_PRINT(str) Serial.print(str)
-#else
-#define DEBUG_PRINT(str) do { } while (0)
-#endif
-
#include <Servo.h>
#include <HMC5883L.h>
#include <Wire.h>
@@ -43,6 +35,24 @@
#include "calibration_wall-e.h"
//#include "calibration.eve.h"
+#include "comm.h"
+
+// set 0 to disable debugging
+// set 1 for debugging with Serial.print (default)
+// set 2 for debugging over RPi serial
+#ifndef DEBUG
+# define DEBUG 1
+#endif
+
+#if DEBUG == 1
+# define DEBUG_PRINT(str) Serial.print(str)
+#elif DEBUG == 2
+# define DEBUG_PRINT(str) serial_print_debug(str)
+#else
+# define DEBUG_PRINT(str) do { } while (0)
+#endif
+
+
// *****************
// ** DEFINITIONS **
@@ -93,10 +103,10 @@ int currValDirection = 0;
int currValDirectionDegree = 0;
// Timers
-long timerMovementStart = 0;
-long timerMovementStop = 0;
-long timerInitialSequence = 0;
-long timerTurret = 0;
+unsigned long timerMovementStart = 0;
+unsigned long timerMovementStop = 0;
+//unsigned long timerInitialSequence = 0; // TODO unused?
+unsigned long timerTurret = 0;
// Counters
int counterInit = 0;
@@ -264,20 +274,17 @@ float sensMagnetometer() {
return(north); // Returns angle difference
}
void sensCompass() {
- int degree = -1;
- float reading[NUM_COMPASS_CHECKS];
+ int degree;
float readingtotal = 0;
+ // take multiple samples and use the average
for(int i = 0; i < NUM_COMPASS_CHECKS; i++){
readingtotal += sensMagnetometer();
}
- readingtotal /= NUM_COMPASS_CHECKS;
-
- if (readingtotal >= 0 && readingtotal <= 360)
- degree = (int) readingtotal;
-
- if (data.compass != degree) {
+ // if compass reading is sane, save it.
+ degree = readingtotal / NUM_COMPASS_CHECKS;
+ if (degree >= 0 && degree <= 360 && data.compass != degree) {
data.compass = degree;
// mark as changed
dataToPiChangedBits |= CHANGED_SENS_COMPASS;
@@ -404,6 +411,7 @@ int sensIRRemote() {
}
return LabFound;
}
+
void sensBeaconTurret() {
// BE AWARE, LOCALISATION OF OBSTACLE IS y DISTANCE FROM CENTER OF ROBOT
// (creates triangle with centerOfRobot, centerOfSensor and Obstacle as its corners)
@@ -456,9 +464,9 @@ void stopAllServos() {
timerMovementStop = 0;
}
-bool moveTurnTo(int direction) {
+void moveTurnTo(int direction) {
if (direction == 0 || direction == NUM_DIRECTIONS) {
- return true;
+ return;
}
// Make sure turret doesn't move
@@ -777,7 +785,8 @@ void checkSample() {
}
}
-bool confirmSample(int turretVal) {
+void confirmSample(int turretVal) {
+ // TODO use turretVal
if (!counterSampleConfirm) {
stopAllServos();
// Turret direction in degrees calculated from forward. (negative is left, positive is right)
diff --git a/Venus_Skeleton/calibration_wall-e.h b/Venus_Skeleton/calibration_wall-e.h
index 16e0ebe..c859a84 100644
--- a/Venus_Skeleton/calibration_wall-e.h
+++ b/Venus_Skeleton/calibration_wall-e.h
@@ -1,3 +1,5 @@
+#ifndef CALIBRATION_WALL_E_H
+#define CALIBRATION_WALL_E_H
// WALLY configuration file
#define calObstacleTurretMaxDist 50
@@ -27,4 +29,6 @@
#define CAL_TURRET_TO_CENTER_DIST 6
-#define CAL_SAMPLE_TURRET_MAX_DIST 27 \ No newline at end of file
+#define CAL_SAMPLE_TURRET_MAX_DIST 27
+
+#endif /* !CALIBRATION_WALL_E_H */
diff --git a/Venus_Skeleton/comm.h b/Venus_Skeleton/comm.h
index 7f3b43c..bca5aab 100644
--- a/Venus_Skeleton/comm.h
+++ b/Venus_Skeleton/comm.h
@@ -1,3 +1,6 @@
+#ifndef COMM_H
+#define COMM_H
+
typedef enum {
RESET1 = 0x81,
RESET2 = 0x82,
@@ -26,3 +29,19 @@ extern serial_state_t serial_state;
void handle_serial(data_t *data, int changedBits);
void serial_print_debug(const char *str);
+
+/* simple wrappers for Serial.print compatibility */
+static inline void serial_print_debug(String str) {
+ serial_print_debug(str.c_str());
+}
+static inline void serial_print_debug(int n) {
+ serial_print_debug(String(n));
+}
+static inline void serial_print_debug(long n) {
+ serial_print_debug(String(n));
+}
+static inline void serial_print_debug(float n) {
+ serial_print_debug(String(n));
+}
+
+#endif /* !COMM_H */
diff --git a/Venus_Skeleton/comm.cpp b/Venus_Skeleton/comm.ino
index d60138e..d60138e 100644
--- a/Venus_Skeleton/comm.cpp
+++ b/Venus_Skeleton/comm.ino
diff --git a/Venus_Skeleton/dataTypes.h b/Venus_Skeleton/dataTypes.h
index f19eaf5..2f2aa69 100644
--- a/Venus_Skeleton/dataTypes.h
+++ b/Venus_Skeleton/dataTypes.h
@@ -1,3 +1,6 @@
+#ifndef DATATYPES_H
+#define DATATYPES_H
+
// ****************
// ** Data types **
// ****************
@@ -63,3 +66,5 @@ typedef enum {
OPMODE_LABSEQUENCE,
OPMODE_ERROR
} opmode_t;
+
+#endif /* !DATATYPES_H */