commit 5aed5d6e4e377e1a93b021e72b7575b32167a895
parent b22cd9412c2a552b39bd8559c016b82d111ee4c5
Author: thing1 <thing1@seacrossedlovers.xyz>
Date: Thu, 27 Nov 2025 13:06:47 +0000
robot basically done, lecture too
Diffstat:
8 files changed, 63 insertions(+), 148 deletions(-)
diff --git a/CS12020/24.11.25.md b/CS12020/24.11.25.md
@@ -0,0 +1,3 @@
+24/11/25
+========
+
diff --git a/CS12020/robot/line/2 b/CS12020/robot/line/2
@@ -1,134 +0,0 @@
-#include "helper.h"
-
-#define DEBUG
-
-#ifdef DEBUG
-#define DBG(expr) expr;
-#else
-#define DBG(expr)
-#endif
-
-typedef struct state {
- bool left, mid, right;
- int rawleft, rawmid, rawright;
- short prevDir;
- long timeStamp;
-} state;
-
-state *
-getState() {
- static state s;
- s.left = !isLDRBright(LDRA);
- s.mid = !isLDRBright(LDRB);
- s.right = !isLDRBright(LDRC);
- s.rawleft = analogRead(LDRA);
- s.rawmid =
- s.rawright =
-
- setLEDs(s.left, s.mid, s.right);
- return &s;
-}
-
-void
-stepAvoidanceBehave(state *s) {
- DBG({Serial.println("avoid");});
-}
-
-
-void
-stepAttractionBehave(state *s) {
- DBG({Serial.println("avoid");});
-
- /*
- if (s->rawleft > s->rawright + 300)
- stepTurn(LFT);
-
- else if (s->rawright > s->rawleft + 300)
- stepTurn(RGT);
- else
- stepMove(FWD);
- */
-}
-
-void
-runBehave(void (*stepBehave)(state *)) {
- while (true) {
- state *s = getState();
- stepBehave(s);
- }
-}
-
-void
-checkBarcode(state *s) {
- long t = millis();
- if (s->timeStamp > 500) {
- /* long barcode */
- if ((t - s->timeStamp) > 3000)
- runBehave(&stepAvoidanceBehave);
-
- /* short barcode */
- else if ((t - s->timeStamp) > 800)
- runBehave(&stepAttractionBehave);
- }
- s->timeStamp = t;
-}
-
-void
-move(state *s) {
- /* small adjustments */
- if (s->right && s->mid)
- stepTurn(LFT);
- else if (s->left && s->mid)
- stepTurn(RGT);
- /* large adjustments */
- else if (s->right) {
- s->prevDir = LFT;
- stepTurn(RGT);
- } else if (s->left) {
- s->prevDir = RGT;
- stepTurn(LFT);
- /* drive straight, nominal */
- } else if (s->mid) {
- for (int i = 0; i < 20; i++)
- stepMove(FWD);
- } else {
- /* try to recover from not being on the line by moving in the prevDir */
- while (!s->mid) {
- getState();
- stepTurn(s->prevDir);
- }
- }
-}
-
-void
-setup() {
- delay(3000);
- setupRobot();
-
- /* because this is static, I can modify these values to set defaults */
- state *s = getState();
- s->prevDir = BWD;
- s->timeStamp = 0;
-
- LDRA_SWITCH = readuint16(6);
- LDRB_SWITCH = readuint16(10);
- LDRC_SWITCH = readuint16(14);
-}
-
-void
-loop() {
- state *s = getState();
-
- /* do nothing while there is an obstacle */
- while (isObstacle())
- return;
-
- if (s->right && s->left && s->mid) {
- checkBarcode(s);
- /* run through the barcode */
- for (int i = 0; i < 20; i++)
- stepMove(FWD);
- }
- /* don't do any turns when on a the barcode, go straight */
- else move(s);
-}
diff --git a/CS12020/robot/line/TODO b/CS12020/robot/line/TODO
@@ -0,0 +1,4 @@
+- make a funciton called flash LED
+ - this should set a global var (for each led) to the time since last flash, and if it is past a threshhold, it should turn the led on otherwise it should turn it off
+- make a more extensive calibration tool, that completes all tests and fills in the eeprom accordingly
+- report
+\ No newline at end of file
diff --git a/CS12020/robot/line/helper.h b/CS12020/robot/line/helper.h
@@ -18,6 +18,8 @@
#define SERVOA_ZERO 96
#define SERVOB_ZERO 96
+#define SPEED 5
+
#define ANALOG_MAX 1023
#define IRTRANSMITTER 3
@@ -25,12 +27,12 @@
#define IRFREQ 38000
+#define SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
+
uint16_t LDRA_SWITCH = 0;
uint16_t LDRB_SWITCH = 0;
uint16_t LDRC_SWITCH = 0;
-#define SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
-
enum DIRECTIONS {
FWD = 1,
BWD = -1,
@@ -131,8 +133,8 @@ waitButton(int pin, int state) {
void
stepMove(int dir) {
- servoA.write(SERVOA_ZERO + (6 * dir));
- servoB.write(SERVOB_ZERO - (6 * dir));
+ servoA.write(SERVOA_ZERO + (SPEED * dir));
+ servoB.write(SERVOB_ZERO - (SPEED * dir));
delay(10);
servoA.write(SERVOA_ZERO);
servoB.write(SERVOB_ZERO);
@@ -140,8 +142,8 @@ stepMove(int dir) {
void
stepTurn(int dir) {
- servoA.write(SERVOA_ZERO + (10 * dir));
- servoB.write(SERVOB_ZERO - (10 * -dir));
+ servoA.write(SERVOA_ZERO + (SPEED * dir));
+ servoB.write(SERVOB_ZERO - (SPEED * -dir));
delay(10);
servoA.write(SERVOA_ZERO);
servoB.write(SERVOB_ZERO);
diff --git a/CS12020/robot/line/line.ino b/CS12020/robot/line/line.ino
@@ -31,17 +31,36 @@ getState() {
void
stepAvoidanceBehave(state *s) {
- DBG({Serial.println("avoid");});
+ /* should flash red */
+ DBG({
+ /* WARNING this causes the program to stutter when left on,
+ not too bad for debugging but very bad for general use! */
+ SEprintf("Avoid: %d, %d, %d\n", s->rawleft, s->rawmid, s->rawright);
+ });
+
+ /* left is noticably larger */
+ if (s->rawleft > s->rawright + 300)
+ stepTurn(RGT);
+ /* right is noticably larger */
+ else if (s->rawright > s->rawleft + 300)
+ stepTurn(LFT);
+ else
+ stepMove(FWD);
}
void
stepAttractionBehave(state *s) {
- DBG({Serial.println("avoid");});
-
- if (s->rawleft > s->rawright + 300)
+ /* should flash green */
+ DBG({
+ SEprintf("Attract: %d, %d, %d\n", s->rawleft, s->rawmid, s->rawright);
+ });
+
+ /* left is noticably larger */
+ if (s->rawleft > s->rawright + 60)
stepTurn(LFT);
- else if (s->rawright > s->rawleft + 300)
+ /* right is noticably larger */
+ else if (s->rawright > s->rawleft + 60)
stepTurn(RGT);
else
stepMove(FWD);
@@ -77,6 +96,7 @@ move(state *s) {
stepTurn(LFT);
else if (s->left && s->mid)
stepTurn(RGT);
+
/* large adjustments */
else if (s->right) {
s->prevDir = LFT;
@@ -84,12 +104,14 @@ move(state *s) {
} else if (s->left) {
s->prevDir = RGT;
stepTurn(LFT);
+
/* drive straight, nominal */
} else if (s->mid) {
for (int i = 0; i < 20; i++)
stepMove(FWD);
} else {
- /* try to recover from not being on the line by moving in the prevDir */
+ /* try to recover from not being on the line by moving in the prevDir
+ only updated on large turns */
while (!s->mid) {
getState();
stepTurn(s->prevDir);
@@ -116,9 +138,9 @@ void
loop() {
state *s = getState();
- /* do nothing while there is an obstacle */
+ /* do nothing while there is an obstacle, should flash orange */
while (isObstacle())
- return;
+ return;
if (s->right && s->left && s->mid) {
checkBarcode(s);
diff --git a/CS18120/26.11.25.md b/CS18120/26.11.25.md
@@ -0,0 +1,2 @@
+26/11/25
+========
diff --git a/MP10610/25.11.25.md b/MP10610/25.11.25.md
@@ -0,0 +1,12 @@
+25/11/25
+========
+
+- to sketch a curve
+ - you need to find the derivative
+ - then find the critical points (when f'(x) = 0)
+ - sub in the critical points and the start and end points to the original function
+ - use these to sketch the graph
+- on a concave curve f'(x) will get larger as x rises, or smaller if the curve is in the other way
+ - f''(x) > 0 for all values on x on the curve is the graph is concave upward
+ - f''(x) < 0 for all values on x on the curve is the graph is concave downward
+ - it will be 0 for points of inflection
diff --git a/PH16210/27.11.25.md b/PH16210/27.11.25.md
@@ -0,0 +1,2 @@
+27/11/25
+========
+\ No newline at end of file