Skip to content

Commit

Permalink
Initial worked
Browse files Browse the repository at this point in the history
  • Loading branch information
TexnoMann committed Mar 24, 2024
1 parent 414472b commit b99dfd2
Show file tree
Hide file tree
Showing 31 changed files with 551 additions and 428 deletions.
43 changes: 0 additions & 43 deletions include/carClassTest.h

This file was deleted.

21 changes: 0 additions & 21 deletions include/encoderClassTest.h

This file was deleted.

58 changes: 0 additions & 58 deletions include/finalSystem.h

This file was deleted.

19 changes: 0 additions & 19 deletions include/motorClassTest.h

This file was deleted.

File renamed without changes.
44 changes: 44 additions & 0 deletions include/tests/carClassTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <PinChangeInterrupt.h>
#include "Car.h"
#include "config.h"

Matrix<3> desiredCarVelocity;
Matrix<3> feedbackCarPose;

unsigned long wheelPeriod = UPDATE_STATE_DT_MS; // millis
Car car(WHEELBASE_LENGTH / 2, WHEELBASE_WIDTH / 2, OMNIWHEEL_DIAMETER / 2, UPDATE_STATE_DT_MS, &desiredCarVelocity, &feedbackCarPose);
void updateW1A() { car.wheels[0]->triggerA(); }
void updateW1B() { car.wheels[0]->triggerB(); }
void updateW2A() { car.wheels[1]->triggerA(); }
void updateW2B() { car.wheels[1]->triggerB(); }
void updateW3A() { car.wheels[2]->triggerA(); }
void updateW3B() { car.wheels[2]->triggerB(); }
void updateW4A() { car.wheels[3]->triggerA(); }
void updateW4B() { car.wheels[3]->triggerB(); }

void setup()
{
attachPCINT(digitalPinToPCINT(car.wheels[0]->getEncPinA()), updateW1A, RISING);
attachPCINT(digitalPinToPCINT(car.wheels[0]->getEncPinB()), updateW1B, RISING);
attachInterrupt(digitalPinToInterrupt(car.wheels[1]->getEncPinA()), updateW2A, RISING);
attachInterrupt(digitalPinToInterrupt(car.wheels[1]->getEncPinB()), updateW2B, RISING);
attachPCINT(digitalPinToPCINT(car.wheels[2]->getEncPinA()), updateW3A, RISING);
attachPCINT(digitalPinToPCINT(car.wheels[2]->getEncPinB()), updateW3B, RISING);
attachInterrupt(digitalPinToInterrupt(car.wheels[3]->getEncPinA()), updateW4A, RISING);
attachInterrupt(digitalPinToInterrupt(car.wheels[3]->getEncPinB()), updateW4B, RISING);

Serial.begin(38400);
Serial.setTimeout(100);
}

void loop()
{
// t x y
car.setDesiredVelocity(0, 0.1, 0); // 5, 1, 1
auto t1 = millis();
car.update();
auto t2 = millis();
Serial.print("Time for car update: ");
Serial.println(t2-t1);
// delay(1000);
}
29 changes: 29 additions & 0 deletions include/tests/encoderClassTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <PinChangeInterrupt.h>
#include "Encoder.h"
#include "config.h"

int pinA = ENC_MOTOR2_PINA;
int pinB = ENC_MOTOR2_PINB;
Encoder encoder(pinA, pinB, false);
void triggerA() { encoder.triggerA(); }
void triggerB() { encoder.triggerB(); }

void setup() {
encoder.reset();
if(digitalPinToInterrupt(pinA) == -1){
attachPCINT(digitalPinToPCINT(pinA), triggerA, RISING);
} else{
attachInterrupt(digitalPinToInterrupt(pinA), triggerA, RISING);
}
if(digitalPinToInterrupt(pinB) == -1){
attachPCINT(digitalPinToPCINT(pinB), triggerB, RISING);
} else{
attachInterrupt(digitalPinToInterrupt(pinB), triggerB, RISING);
}

Serial.begin(38400);
}

void loop() {
Serial.println("Position " + (String)encoder.getAngle()+" Ticks " + (String)encoder.getTicks());
}
18 changes: 11 additions & 7 deletions include/encoderTest.h → include/tests/encoderTest.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <PinChangeInterrupt.h>
#include "config.h"
// #include "Arduino.h"

const int pinA = 18;
const int pinB = 19;
const int pinA = ENC_MOTOR3_PINA;
const int pinB = ENC_MOTOR3_PINB;

volatile long position = 0;

Expand Down Expand Up @@ -33,12 +34,15 @@ void triggerB() {
void setup() {
pinMode(pinA, INPUT_PULLUP);
pinMode(pinB, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(pinA), triggerA, RISING);
attachInterrupt(digitalPinToInterrupt(pinB), triggerB, RISING);
// attachPCINT(digitalPinToPCINT(pinA), triggerA, RISING);
// attachPCINT(digitalPinToPCINT(pinB), triggerB, RISING);

Serial.begin(115200);
// attachInterrupt(digitalPinToInterrupt(pinA), triggerA, RISING);
// attachInterrupt(digitalPinToInterrupt(pinB), triggerB, RISING);

// Use program interrupt
attachPCINT(digitalPinToPCINT(pinA), triggerA, RISING);
attachPCINT(digitalPinToPCINT(pinB), triggerB, RISING);

Serial.begin(38400);
}

void loop() {}
59 changes: 59 additions & 0 deletions include/tests/finalSystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <PinChangeInterrupt.h>
#include <Thread.h>
#include "Car.h"
#include "SerialTransceiver.h"
#include "config.h"

Matrix<3> desiredCarVelocity;
Matrix<3> feedbackCarPose;

Car car(WHEELBASE_LENGTH / 2, WHEELBASE_WIDTH / 2, OMNIWHEEL_DIAMETER / 2, UPDATE_STATE_DT_MS, &desiredCarVelocity, &feedbackCarPose);
void updateW1A() { car.wheels[0]->triggerA(); }
void updateW1B() { car.wheels[0]->triggerB(); }
void updateW2A() { car.wheels[1]->triggerA(); }
void updateW2B() { car.wheels[1]->triggerB(); }
void updateW3A() { car.wheels[2]->triggerA(); }
void updateW3B() { car.wheels[2]->triggerB(); }
void updateW4A() { car.wheels[3]->triggerA(); }
void updateW4B() { car.wheels[3]->triggerB(); }

SerialTransceiver transceiver(&desiredCarVelocity, &feedbackCarPose);

Thread carThread = Thread();
Thread serialThread = Thread();

void updateCar() { car.update(); }
void talkSerial() { transceiver.talk(); }

void setup()
{
attachPCINT(digitalPinToPCINT(car.wheels[0]->getEncPinA()), updateW1A, RISING);
attachPCINT(digitalPinToPCINT(car.wheels[0]->getEncPinB()), updateW1B, RISING);
attachInterrupt(digitalPinToInterrupt(car.wheels[1]->getEncPinA()), updateW2A, RISING);
attachInterrupt(digitalPinToInterrupt(car.wheels[1]->getEncPinB()), updateW2B, RISING);
attachPCINT(digitalPinToPCINT(car.wheels[2]->getEncPinA()), updateW3A, RISING);
attachPCINT(digitalPinToPCINT(car.wheels[2]->getEncPinB()), updateW3B, RISING);
attachInterrupt(digitalPinToInterrupt(car.wheels[3]->getEncPinA()), updateW4A, RISING);
attachInterrupt(digitalPinToInterrupt(car.wheels[3]->getEncPinB()), updateW4B, RISING);

desiredCarVelocity.Fill(0);
feedbackCarPose.Fill(0);

Serial.begin(38400);
Serial.setTimeout(100);

carThread.onRun(updateCar);
serialThread.onRun(talkSerial);
}

void loop()
{
if (carThread.shouldRun())
{
carThread.run();
}
if (serialThread.shouldRun())
{
serialThread.run();
}
}
File renamed without changes.
19 changes: 19 additions & 0 deletions include/tests/motorClassTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <Arduino.h>
#include "Motor.h"

unsigned long period = 500;
int voltageValues[] = {50, 0, 60, 0, 69, 0, 70, 0, 71, 0, 80, 0, 200, 0, -255, 255, 0};
int arrayLength = sizeof(voltageValues) / sizeof(int);
Motor motor(1);

void setup() {
Serial.begin(38400);
}

void loop() {
unsigned long step = millis() / period;
if (step < arrayLength) {
motor.setValue(voltageValues[step]);
Serial.println("Value = " + (String)voltageValues[step]);
}
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit b99dfd2

Please sign in to comment.