Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/rov/rov_pca9685/include/pca9685/ServoDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ struct ServoBase {
};

struct Servo : ServoBase {
uint16_t us_minimum;
uint16_t us_maximum;
uint16_t us_minimum = 1000;
uint16_t us_maximum = 2000;
};

struct ContinuousServo : ServoBase {
uint16_t us_minimum;
uint16_t us_maximum;
uint16_t us_minimum = 1000;
uint16_t us_maximum = 2000;
};

class ServoDriver {
Expand All @@ -46,4 +46,4 @@ class ServoDriver {
std::map<uint8_t, ContinuousServo> continuous_servos;
};

#endif
#endif
2 changes: 1 addition & 1 deletion src/rov/rov_pca9685/src/PCA9685.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void PCA9685::reset() {
}

void PCA9685::setFrequency(uint16_t frequency) {
static const uint16_t NUM_COUNTS = 4096; // scaling factor since clock sucks balls lol
static const uint16_t NUM_COUNTS = 3932; // scaling factor since clock sucks balls lol
static const uint16_t MIN_FREQUENCY = 24; // Hz
static const uint16_t MAX_FREQUENCY = 1526; // Hz
// if given frequency is not valid, do nothing
Expand Down
24 changes: 21 additions & 3 deletions src/rov/rov_pca9685/src/ServoDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#include <iostream>
#include <rclcpp/rclcpp.hpp>

#define NUM_COUNTS 4177
#define BUS_DEV 1
#define ADDRESS 0x41
#define ADDRESS 0x5e

static int f2imap(float value, float from_min, float from_max, int to_min, int to_max){
int val = ((value - from_min) * ((to_max - to_min) / (from_max - from_min)) + to_min);
Expand All @@ -29,12 +28,14 @@ void ServoDriver::registerServo(uint8_t channel, ServoType type) {
case ServoType::POSITIONAL:
servos[channel] = Servo();
RCLCPP_INFO(rclcpp::get_logger("ServoDriver"), "Registered positional servo on channel %d", channel);
setUSBounds(channel, 1000, 2000);
setAngle(channel, 90.0f);
break;

case ServoType::CONTINUOUS:
continuous_servos[channel] = ContinuousServo();
RCLCPP_INFO(rclcpp::get_logger("ServoDriver"), "Registered continuous servo on channel %d", channel);
setUSBounds(channel, 1000, 2000);
setThrottle(channel, 0.0f);
break;
}
Expand All @@ -57,6 +58,23 @@ void ServoDriver::setThrottle(uint8_t channel, float throttle) {
driver_board.setUS(channel, f2imap(throttle, -1.0, 1.0, s->us_minimum, s->us_maximum));
}

void ServoDriver::setDuty(uint8_t channel, float duty) {
driver_board.setDuty(channel, duty);
}

void ServoDriver::setUS(uint8_t channel, uint16_t us) {
driver_board.setUS(channel, us);
}

void ServoDriver::setThrottle(uint8_t channel, float throttle) {
if (!continuous_servos.count(channel)) {
RCLCPP_WARN(rclcpp::get_logger("ServoDriver"), "Attempted to set throttle on non-continuous servo");
return;
}
ContinuousServo* s = &continuous_servos[channel];
driver_board.setUS(channel, f2imap(throttle, -1.0, 1.0, s->us_minimum, s->us_maximum));
}

void ServoDriver::setAngle(uint8_t channel, float angle) {
if (!servos.count(channel)) {
RCLCPP_WARN(rclcpp::get_logger("ServoDriver"), "Attempted to set angle on continuous servo");
Expand Down Expand Up @@ -88,4 +106,4 @@ void ServoDriver::setOutput(uint8_t channel, float angle_or_throttle) {
return;
}
RCLCPP_WARN(rclcpp::get_logger("ServoDriver"), "Attempted to set the output of an unregistered servo");
}
}
4 changes: 2 additions & 2 deletions src/rov/rov_pca9685/src/main_interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
for(int i=0; i<16; i++) {
servoDriver.registerServo(i, ServoType::CONTINUOUS);
isContinuous[i]=true;
servoDriver.setUSBounds(i, 1100, 1900);
servoDriver.setUSBounds(i, 1000, 2000);
}
} else {
// load non continuous servo defaults
Expand Down Expand Up @@ -119,4 +119,4 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
std::cout << "substr threw out of range exception\n";
}
}
}
}
8 changes: 0 additions & 8 deletions worlds_driverstation_setup.bash

This file was deleted.

Loading