Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radio Control Support #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
94 changes: 66 additions & 28 deletions firmware/Components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ void Seaking::arm()
{
disable();
delay(500);
disable();
delay(500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we disable twice here? We could just wait 1s after the first disable, right?

Or is this a typo?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a typo. I removed it before, but it must have got back in somehow.


velocity(1.0);
enable();
Expand All @@ -75,7 +77,7 @@ void Swordfish::arm()
{
disable();
delay(500);

velocity(1.0);
enable();
delay(5000);
Expand All @@ -84,6 +86,18 @@ void Swordfish::arm()
delay(3000);
}

//Default Dynamite arming routine
//Sets 1500 to neutral (0 velocity) and 2000 to high (1.0 velocity)
void Dynamite::arm()
{
disable();
delay(500);

velocity(0.0);
enable();
delay(2000);
}

AnalogSensor::AnalogSensor(int channel)
: Sensor(channel), scale_(1.0f), offset_(0.0f) {}

Expand Down Expand Up @@ -218,14 +232,14 @@ void ES2::loop()
// Enable +12V output.
pinMode(board::SENSOR[channel_].PWR_ENABLE, OUTPUT);
digitalWrite(board::SENSOR[channel_].PWR_ENABLE, HIGH);

// Read response from sensor.
delay(250);

// Turn off +12V output.
pinMode(board::SENSOR[channel_].PWR_ENABLE, OUTPUT);
digitalWrite(board::SENSOR[channel_].PWR_ENABLE, LOW);

// Wait a while for next sensor reading.
delay(1750);
}
Expand All @@ -234,18 +248,18 @@ void ES2::onSerial()
{
// TODO: verify checksum.
char c = SERIAL_PORTS[channel_]->read();
if (c == '\0') {
if (c == '\0') {
return;
}
}
else if (c != '\r' && c != '\n' && recv_index_ < DEFAULT_BUFFER_SIZE)
{
recv_buffer_[recv_index_] = c;
++recv_index_;
}
else if (recv_index_ > 0)
{
{
recv_buffer_[recv_index_] = '\0';

if (recv_index_ > 6) // Only send data strings
{
char output_str[DEFAULT_BUFFER_SIZE+3];
Expand All @@ -272,7 +286,7 @@ AtlasSensor::AtlasSensor(int channel)
{
// Start up serial port.
SERIAL_PORTS[channel]->begin(38400);

// Tell the sensor to output continuously.
SERIAL_PORTS[channel_]->print("C\r");
}
Expand All @@ -291,9 +305,9 @@ void AtlasSensor::onSerial()
++recv_index_;
}
else if (recv_index_ > 0)
{
{
recv_buffer_[recv_index_] = '\0';

char output_str[DEFAULT_BUFFER_SIZE+3];
snprintf(output_str, DEFAULT_BUFFER_SIZE,
"{"
Expand All @@ -304,10 +318,10 @@ void AtlasSensor::onSerial()
"}",
channel_,
recv_buffer_
);
);
send(output_str);

memset(recv_buffer_, 0, recv_index_);
memset(recv_buffer_, 0, recv_index_);
recv_index_ = 0;
}
}
Expand All @@ -334,7 +348,7 @@ Hds5::Hds5(int channel)
// Select RS485 (deselect RS232)
pinMode(board::SENSOR[channel].RS485_232, OUTPUT);
digitalWrite(board::SENSOR[channel].RS485_232, HIGH);

// Start up serial port
SERIAL_PORTS[channel]->begin(4800);
}
Expand All @@ -353,9 +367,9 @@ void Hds5::onSerial()
++recv_index_;
}
else if (recv_index_ > 0)
{
{
recv_buffer_[recv_index_] = '\0';

char output_str[DEFAULT_BUFFER_SIZE+3];
snprintf(output_str, DEFAULT_BUFFER_SIZE,
"{"
Expand All @@ -366,9 +380,9 @@ void Hds5::onSerial()
"}",
channel_,
recv_buffer_
);
);
send(output_str);

memset(recv_buffer_, 0, recv_index_);
recv_index_ = 0;
}
Expand All @@ -381,14 +395,14 @@ Winch::Winch(int channel, uint8_t address)
, desired_position_(0)
, desired_velocity_(0)
, desired_acceleration_(12000)
{
{
// Enable +12V output.
pinMode(board::SENSOR[channel].PWR_ENABLE, OUTPUT);
digitalWrite(board::SENSOR[channel].PWR_ENABLE, HIGH);

// TODO: specifically enable e-stop line.
// (Right now it is just pulled up by default.)

// Start up Roboclaw.
roboclaw_.begin(38400);
}
Expand All @@ -404,20 +418,20 @@ bool Winch::set(char* param, char* value)
if (!strncmp("p", param, 2))
{
uint32_t pos = atol(value);

position(pos);
return true;
}
else if (!strncmp("v", param, 2))
{
int32_t vel = atol(value);

velocity(vel);
return true;
return true;
}
else if (!strncmp("reset", param, 6))
{

reset();
return true;
}
Expand All @@ -444,10 +458,10 @@ void Winch::velocity(int32_t vel)
{
desired_velocity_ = vel;
roboclaw_.SetM1VelocityPID(addr, Kd, Kp, Ki, Qpps);
roboclaw_.SpeedAccelDistanceM1(addr,
desired_acceleration_,
roboclaw_.SpeedAccelDistanceM1(addr,
desired_acceleration_,
desired_velocity_,
desired_position_);
desired_position_);
}

uint32_t Winch::encoder(bool *valid)
Expand All @@ -456,3 +470,27 @@ uint32_t Winch::encoder(bool *valid)
return enc1;
}

//Cosntruct RC "sensor" by calling RC_Controller
RC::RC(int channel)
: Sensor(channel),
RC_Controller(board::SENSOR[channel].GPIO[board::RX_NEG],
board::SENSOR[channel].GPIO[board::TX_NEG],
board::SENSOR[channel].GPIO[board::RX_POS])
{
// Disable RSxxx receiver
pinMode(board::SENSOR[channel].RX_DISABLE, OUTPUT);
digitalWrite(board::SENSOR[channel].RX_DISABLE, HIGH);

// Disable TSxxx transmitter
pinMode(board::SENSOR[channel].TX_ENABLE, OUTPUT);
digitalWrite(board::SENSOR[channel].TX_ENABLE, LOW);


}

char * RC::name()
{
return "RC_Controller";
}


20 changes: 19 additions & 1 deletion firmware/Components.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "Platypus.h"
#include "RoboClaw.h"
#include "RC.h"

namespace platypus
{
Expand Down Expand Up @@ -36,6 +37,13 @@ namespace platypus
void arm();
};

class Dynamite : public Motor
{
public:
Dynamite(int channel) : Motor(channel) {}
void arm();
};

class AnalogSensor : public Sensor
{
public:
Expand Down Expand Up @@ -69,7 +77,7 @@ namespace platypus

private:
Servo servo_;
Servo servo_legacy_; // TODO: remove this once we only have v3+ boards
Servo servo_legacy_;
float position_;
};

Expand Down Expand Up @@ -138,6 +146,16 @@ namespace platypus
int32_t desired_velocity_;
uint32_t desired_acceleration_;
};

class RC : public Sensor, public RC_Controller
{
public:
RC(int channel);
char *name();



};
}

#endif //COMPONENTS_H
4 changes: 4 additions & 0 deletions firmware/Platypus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ void Motor::velocity(float velocity)
if (velocity < -1.0) {
velocity = -1.0;
}

//Clip velocity to prevent high current cut-out
velocity *= 0.6;

velocity_ = velocity;

float command = (velocity * 500) + 1500;
Expand Down
Loading