-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All files use SerialTools instead of using the Serial object directly.
- Loading branch information
1 parent
615a629
commit 23d1730
Showing
9 changed files
with
91 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,13 @@ | ||
#include "IController.h" | ||
|
||
class LightController : public IController { | ||
private: | ||
uint8_t lights_ = 45; | ||
public: | ||
LightController(uint8_t lights) : lights_(lights) { | ||
pinMode(lights_, OUTPUT); | ||
digitalWrite(lights_, HIGH); | ||
LightController() { | ||
pinMode(LIGHTS_PIN, OUTPUT); | ||
digitalWrite(LIGHTS_PIN, HIGH); | ||
} | ||
void execute() { | ||
while(!Serial.available()); | ||
digitalWrite(lights_, !Serial.read()); | ||
digitalWrite(LIGHTS_PIN, !SerialTools::readByte()); | ||
} | ||
void kill() { | ||
//digitalWrite(LIGHTS, HIGH); | ||
} | ||
}; | ||
void kill() { } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,30 @@ | ||
#include <Servo.h> | ||
#include "IController.h" | ||
|
||
uint16_t readShort() { | ||
while(Serial.available() < 2) {} | ||
return Serial.read() << 8 | Serial.read(); | ||
} | ||
|
||
class ThrustController : public IController { | ||
private: | ||
const uint16_t IDLE = 1500; | ||
const uint16_t IDLE = 1500; | ||
const uint16_t FORWARD = 2000; | ||
const uint16_t REVERSE = 1000; | ||
int16_t tunningOffset; | ||
Servo servo_; | ||
public: | ||
ThrustController(uint8_t servoPin) { | ||
init(servoPin, 0); | ||
} | ||
|
||
ThrustController(uint8_t servoPin, int16_t offset) { | ||
init(servoPin, offset); | ||
} | ||
|
||
void init(uint8_t servoPin, int16_t offset) { | ||
tunningOffset = offset; | ||
servo_.attach(servoPin); | ||
servo_.writeMicroseconds(IDLE); | ||
} | ||
|
||
void execute() { | ||
uint16_t val = readShort(); | ||
uint16_t val = SerialTools::readUShort(); | ||
servo_.writeMicroseconds(getBoundedThrottle(val)); | ||
} | ||
|
||
void kill() { | ||
servo_.writeMicroseconds(getBoundedThrottle(IDLE)); | ||
servo_.writeMicroseconds(IDLE); | ||
} | ||
|
||
uint16_t getBoundedThrottle(uint16_t value) { | ||
uint16_t fVal = value + tunningOffset; | ||
if(fVal > FORWARD) | ||
return FORWARD; | ||
else if(fVal < REVERSE) | ||
return REVERSE; | ||
else | ||
return fVal; | ||
if(value > FORWARD) return FORWARD; | ||
else if(value < REVERSE) return REVERSE; | ||
else return value; | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,25 @@ | ||
#include "IController.h" | ||
|
||
#define R1 30000.0 | ||
#define R2 7500.0 | ||
|
||
class VoltageController : public IController { | ||
private: | ||
uint8_t volt_; | ||
|
||
const double R1 = 30000.0; | ||
const double R2 = 7500.0; | ||
public: | ||
VoltageController(uint8_t volt) : volt_(volt) { | ||
pinMode(volt_, INPUT); | ||
VoltageController() { | ||
pinMode(VOLT_PIN, INPUT); | ||
} | ||
|
||
void execute() { | ||
int value = analogRead(volt_); | ||
int value = analogRead(VOLT_PIN); | ||
/* | ||
* Measured Values for Calibration | ||
* P1 = (11.32, 700); P2 = (8.38, 517) | ||
* | ||
* Solve for the linear function: x = (y-b)/m | ||
* voltage = (2.94 * value + 13.56) / 183 | ||
*/ | ||
Serial.println((2.94 * value + 13.56) / 183); | ||
*/ | ||
SerialTools::writeDouble((2.94 * value + 13.56) / 183); | ||
} | ||
|
||
void kill() { | ||
|
||
} | ||
}; | ||
|
||
void kill() { } | ||
}; |