uni

Thing1's amazing uni repo
Log | Files | Refs

commit 1574d8b44b5706242007b46cec47e0de96045ab2
parent 9365cbb259690f19e6ba337f108a9a8d658df65a
Author: thing1 <thing1@seacrossedlovers.xyz>
Date:   Sun,  9 Nov 2025 22:29:56 +0000

robot time

Diffstat:
ACS12020/robot/action/Makefile | 10++++++++++
ACS12020/robot/action/action.ino | 20++++++++++++++++++++
ACS12020/robot/action/actions.h | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ACS12020/robot/action/instructions.h | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ACS12020/robot/action/util.h | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ACS18120/07.11.25.md | 17+++++++++++++++++
AMP10610/06.11.25.md | 5+++++
APH16210/06.11.25.md | 6++++++
8 files changed, 270 insertions(+), 0 deletions(-)

diff --git a/CS12020/robot/action/Makefile b/CS12020/robot/action/Makefile @@ -0,0 +1,10 @@ +all: compile upload + +upload: compile + arduino-cli upload --fqbn arduino:avr:uno . -p /dev/ttyACM0 + +compile: action.ino + arduino-cli compile --fqbn arduino:avr:uno . + +monitor: + arduino-cli monitor -p /dev/ttyACM0 diff --git a/CS12020/robot/action/action.ino b/CS12020/robot/action/action.ino @@ -0,0 +1,20 @@ +#include <Servo.h> +#include "actions.h" + +void +setup() { + setupRobot(); + + action a1 = { {isButtonAPressed, isButtonBPressed}, moveFWD, NOR}; + + action as[] = {a1}; + + while (1) { + for (int i = 0; i < SIZE(as); i++) + runAction(&as[i]); + } + + delay(20000); +} + +void loop() {} diff --git a/CS12020/robot/action/actions.h b/CS12020/robot/action/actions.h @@ -0,0 +1,79 @@ +#include <Servo.h> +#include "instructions.h" + +#define MAXACTIONS 2 + +enum triggerGates { + AND, + OR, + NOT, + XOR, + + XNOR, + NAND, + NOR, +}; + +typedef struct action { + volatile bool (*triggers[MAXACTIONS])(void); + void (*action)(void); + int triggerGate; +} action; + +bool +isButtonAPressed() { + return !digitalRead(BUTTONA); +} + +bool +isButtonBPressed() { + return !digitalRead(BUTTONB); +} + + +void +moveFWD(void) { + stepMove(FWD); +} + +void +moveBWD(void) { + stepMove(BWD); +} + +void +stepLFT(void) { + stepTurn(LFT); +} + +void +stepRGT(void) { + stepTurn(RGT); +} + +bool +shouldAction(action *a) { + switch (a->triggerGate) { + case AND: + return a->triggers[0]() && a->triggers[1](); + case OR: + return a->triggers[0]() || a->triggers[1](); + case XOR: + return a->triggers[0]() ^ a->triggers[1](); + case NOT: + return !a->triggers[0](); + + case NAND: + return !(a->triggers[0]() && a->triggers[1]()); + case NOR: + return !(a->triggers[0]() || a->triggers[1]()); + case XNOR: + return !(a->triggers[0]() ^ a->triggers[1]()); + } +} + +void +runAction(action *a) { + if (shouldAction(a)) + a->action(); +} diff --git a/CS12020/robot/action/instructions.h b/CS12020/robot/action/instructions.h @@ -0,0 +1,60 @@ +#include <Servo.h> +#include "util.h" + +enum DIRECTIONS { + FWD = 1, + BWD = -1, + LFT = -2, + RGT = 2 +}; + +typedef struct instructions { + int dir, unit; + struct instructions *next; +} instructions; + +void +stepMove(int dir) { + servoA.write(SERVOA_ZERO + (40 * dir)); + servoB.write(SERVOA_ZERO - (40 * dir)); + delay(10); + servoA.write(SERVOA_ZERO); + servoB.write(SERVOA_ZERO); +} + +void +stepTurn(int dir) { + servoA.write(SERVOA_ZERO + (10 * dir)); + servoB.write(SERVOA_ZERO - (10 * -dir)); + delay(10); + servoA.write(SERVOA_ZERO); + servoB.write(SERVOA_ZERO); +} + +void +rotate(int x) { + int dir = (x < 0) ? -1 : 1; + x = (x < 0) ? -x : x; + + int y = (int)(1.666666 * (float)x); + + for (int i = 0; i < y; i++) + stepTurn(dir); +} + +void +runInstructions(instructions *ins) { + switch (ins->dir) { + case FWD: + case BWD: + for (int i = 0; i < ins->unit; i++) + stepMove(ins->dir); + break; + case LFT: + case RGT: + rotate(ins->unit * (ins->dir / 2)); + break; + } + if (ins->next) + runInstructions(ins->next); +} diff --git a/CS12020/robot/action/util.h b/CS12020/robot/action/util.h @@ -0,0 +1,73 @@ +#define GREEN_LED 7 +#define YELLOW_LED 12 +#define RED_LED 13 + +#define BUTTONA 4 +#define BUTTONB 2 + +#define SERVOA_PIN 6 +#define SERVOB_PIN 5 + +#define SERVOA_ZERO 96 +#define SERVOB_ZERO 96 + +#define SIZE(arr) (sizeof(arr) / sizeof(arr[0])) + +Servo servoA; +Servo servoB; + +void +setupRobot() { + Serial.begin(9600); + pinMode(GREEN_LED, OUTPUT); + pinMode(YELLOW_LED, OUTPUT); + pinMode(RED_LED, OUTPUT); + pinMode(BUTTONA, INPUT); + pinMode(BUTTONB, INPUT); + pinMode(SERVOA_PIN, OUTPUT); + pinMode(SERVOB_PIN, OUTPUT); + servoA.attach(SERVOA_PIN); + servoB.attach(SERVOB_PIN); + servoA.write(SERVOA_ZERO); + servoB.write(SERVOB_ZERO); +} + +void +setLEDs(int g, int y, int r) { + digitalWrite(GREEN_LED, g); + digitalWrite(YELLOW_LED, y); + digitalWrite(RED_LED, r); +} + +void +waitButton(int pin, int state) { + while (digitalRead(pin) == state) ; +} + +void +debounce(int pin) { + waitButton(pin, LOW); + delay(20); + waitButton(pin, HIGH); + delay(20); +} + +void +SEprintf(const char *fmt, ...) { + static char sbuf[64] = { 0 }; + va_list ap; + + va_start(ap, fmt); + vsnprintf(sbuf, 64, fmt, ap); + va_end(ap); + + Serial.print(sbuf); +} + +int +readint() { + while (!Serial.available()) ; + int i = Serial.parseInt(); + SEprintf("\n"); + return i; +} diff --git a/CS18120/07.11.25.md b/CS18120/07.11.25.md @@ -0,0 +1,17 @@ +07/11/25 +======== + +word +---- + +- word exists +- templates +- stuff +- headings + +latex +----- + +- very cool +- better +- why use anything else diff --git a/MP10610/06.11.25.md b/MP10610/06.11.25.md @@ -0,0 +1,5 @@ +06/11/25 +======== + +- see FIG1 for finding intergration by parts from the product rule +- see FIG2 for a worked example diff --git a/PH16210/06.11.25.md b/PH16210/06.11.25.md @@ -0,0 +1,6 @@ +25/11/25 +======== + +- see FIG1 for a first order example + - only works when the function can be written P(x) / Q(y) +