Skip to content

Commit

Permalink
Merge pull request #920 from wolfmanjm/upstreamedge
Browse files Browse the repository at this point in the history
add designator to motordriver messages
  • Loading branch information
wolfmanjm committed Apr 29, 2016
2 parents 88e84b2 + 63b7731 commit b6c3b76
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
25 changes: 13 additions & 12 deletions src/modules/utils/motordrivercontrol/MotorDriverControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,24 @@ void MotorDriverControl::on_module_loaded()

bool MotorDriverControl::config_module(uint16_t cs)
{
spi_cs_pin.from_string(THEKERNEL->config->value( motor_driver_control_checksum, cs, spi_cs_pin_checksum)->by_default("nc")->as_string())->as_output();
if(!spi_cs_pin.connected()) {
THEKERNEL->streams->printf("MotorDriverControl ERROR: chip select not defined\n");
return false; // if not defined then we can't use this instance
}
spi_cs_pin.set(1);

std::string str= THEKERNEL->config->value( motor_driver_control_checksum, cs, designator_checksum)->by_default("")->as_string();
if(str.empty()) {
THEKERNEL->streams->printf("MotorDriverControl ERROR: designator not defined\n");
return false; // designator required
}
designator= str[0];

spi_cs_pin.from_string(THEKERNEL->config->value( motor_driver_control_checksum, cs, spi_cs_pin_checksum)->by_default("nc")->as_string())->as_output();
if(!spi_cs_pin.connected()) {
THEKERNEL->streams->printf("MotorDriverControl %c ERROR: chip select not defined\n", designator);
return false; // if not defined then we can't use this instance
}
spi_cs_pin.set(1);


str= THEKERNEL->config->value( motor_driver_control_checksum, cs, chip_checksum)->by_default("")->as_string();
if(str.empty()) {
THEKERNEL->streams->printf("MotorDriverControl ERROR: chip type not defined\n");
THEKERNEL->streams->printf("MotorDriverControl %c ERROR: chip type not defined\n", designator);
return false; // chip type required
}

Expand All @@ -96,14 +97,14 @@ bool MotorDriverControl::config_module(uint16_t cs)

if(str == "DRV8711") {
chip= DRV8711;
drv8711= new DRV8711DRV(std::bind( &MotorDriverControl::sendSPI, this, _1, _2, _3));
drv8711= new DRV8711DRV(std::bind( &MotorDriverControl::sendSPI, this, _1, _2, _3), designator);

}else if(str == "TMC2660") {
chip= TMC2660;
tmc26x= new TMC26X(std::bind( &MotorDriverControl::sendSPI, this, _1, _2, _3));
tmc26x= new TMC26X(std::bind( &MotorDriverControl::sendSPI, this, _1, _2, _3), designator);

}else{
THEKERNEL->streams->printf("MotorDriverControl ERROR: Unknown chip type: %s\n", str.c_str());
THEKERNEL->streams->printf("MotorDriverControl %c ERROR: Unknown chip type: %s\n", designator, str.c_str());
return false;
}

Expand All @@ -118,7 +119,7 @@ bool MotorDriverControl::config_module(uint16_t cs)
} else if(spi_channel == 1) {
mosi = P0_9; miso = P0_8; sclk = P0_7;
} else {
THEKERNEL->streams->printf("MotorDriverControl ERROR: Unknown SPI Channel: %d\n", spi_channel);
THEKERNEL->streams->printf("MotorDriverControl %c ERROR: Unknown SPI Channel: %d\n", designator, spi_channel);
return false;
}

Expand Down
14 changes: 7 additions & 7 deletions src/modules/utils/motordrivercontrol/drivers/DRV8711/drv8711.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define REGWRITE 0x00
#define REGREAD 0x80

DRV8711DRV::DRV8711DRV(std::function<int(uint8_t *b, int cnt, uint8_t *r)> spi) : spi(spi)
DRV8711DRV::DRV8711DRV(std::function<int(uint8_t *b, int cnt, uint8_t *r)> spi, char d) : spi(spi), designator(d)
{
error_reported.reset();
}
Expand Down Expand Up @@ -216,7 +216,7 @@ void DRV8711DRV::dump_status(StreamOutput *stream)
DRIVE_Register_t R_DRIVE_REG;
STATUS_Register_t R_STATUS_REG;

stream->printf("Register Dump:\n");
stream->printf("designator: %c, Register Dump:\n", designator);

// Read CTRL Register
R_CTRL_REG.raw= ReadRegister(G_CTRL_REG.Address);
Expand Down Expand Up @@ -332,7 +332,7 @@ bool DRV8711DRV::check_alarm()
R_STATUS_REG.raw= ReadRegister(G_STATUS_REG.Address);

if(R_STATUS_REG.OTS) {
if(!error_reported.test(0)) THEKERNEL->streams->printf("ERROR: Overtemperature shutdown\n");
if(!error_reported.test(0)) THEKERNEL->streams->printf("%c, ERROR: Overtemperature shutdown\n", designator);
error= true;
error_reported.set(0);
}else{
Expand All @@ -341,7 +341,7 @@ bool DRV8711DRV::check_alarm()


if(R_STATUS_REG.AOCP) {
if(!error_reported.test(1)) THEKERNEL->streams->printf("ERROR: Channel A over current shutdown\n");
if(!error_reported.test(1)) THEKERNEL->streams->printf("%c, ERROR: Channel A over current shutdown\n", designator);
error= true;
error_reported.set(1);
}else{
Expand All @@ -350,15 +350,15 @@ bool DRV8711DRV::check_alarm()


if(R_STATUS_REG.BOCP) {
if(!error_reported.test(2)) THEKERNEL->streams->printf("ERROR: Channel B over current shutdown\n");
if(!error_reported.test(2)) THEKERNEL->streams->printf("%c, ERROR: Channel B over current shutdown\n", designator);
error= true;
error_reported.set(2);
}else{
error_reported.reset(2);
}

if(R_STATUS_REG.APDF) {
if(!error_reported.test(3)) THEKERNEL->streams->printf("ERROR: Channel A predriver fault\n");
if(!error_reported.test(3)) THEKERNEL->streams->printf("%c, ERROR: Channel A predriver fault\n", designator);
error= true;
error_reported.set(3);
}else{
Expand All @@ -367,7 +367,7 @@ bool DRV8711DRV::check_alarm()


if(R_STATUS_REG.BPDF) {
if(!error_reported.test(4)) THEKERNEL->streams->printf("ERROR: Channel B predriver fault\n");
if(!error_reported.test(4)) THEKERNEL->streams->printf("%c, ERROR: Channel B predriver fault\n", designator);
error= true;
error_reported.set(4);
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class StreamOutput;
class DRV8711DRV
{
public:
DRV8711DRV(std::function<int(uint8_t *b, int cnt, uint8_t *r)> spi);
DRV8711DRV(std::function<int(uint8_t *b, int cnt, uint8_t *r)> spi, char designator);

void init(uint16_t cs) ;

Expand Down Expand Up @@ -142,7 +142,7 @@ class DRV8711DRV
float resistor{0.05};
std::bitset<8> error_reported;
uint8_t gain{20};

char designator;

// float _amps;
// uint8_t _microstepreg;
Expand Down
16 changes: 8 additions & 8 deletions src/modules/utils/motordrivercontrol/drivers/TMC26X/TMC26X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
/*
* Constructor
*/
TMC26X::TMC26X(std::function<int(uint8_t *b, int cnt, uint8_t *r)> spi) : spi(spi)
TMC26X::TMC26X(std::function<int(uint8_t *b, int cnt, uint8_t *r)> spi, char d) : spi(spi), designator(d)
{
//we are not started yet
started = false;
Expand Down Expand Up @@ -863,7 +863,7 @@ bool TMC26X::isCurrentScalingHalfed()
void TMC26X::dumpStatus(StreamOutput *stream, bool readable)
{
if (readable) {
stream->printf("Chip type TMC26X\n");
stream->printf("designator %c, Chip type TMC26X\n", designator);

check_error_status_bits(stream);

Expand Down Expand Up @@ -966,30 +966,30 @@ bool TMC26X::check_error_status_bits(StreamOutput *stream)
readStatus(TMC26X_READOUT_POSITION); // get the status bits

if (this->getOverTemperature()&TMC26X_OVERTEMPERATURE_PREWARING) {
if(!error_reported.test(0)) stream->printf("WARNING: Overtemperature Prewarning!\n");
if(!error_reported.test(0)) stream->printf("%c - WARNING: Overtemperature Prewarning!\n", designator);
error_reported.set(0);
}else{
error_reported.reset(0);
}

if (this->getOverTemperature()&TMC26X_OVERTEMPERATURE_SHUTDOWN) {
if(!error_reported.test(1)) stream->printf("ERROR: Overtemperature Shutdown!\n");
if(!error_reported.test(1)) stream->printf("%c - ERROR: Overtemperature Shutdown!\n", designator);
error=true;
error_reported.set(1);
}else{
error_reported.reset(1);
}

if (this->isShortToGroundA()) {
if(!error_reported.test(2)) stream->printf("ERROR: SHORT to ground on channel A!\n");
if(!error_reported.test(2)) stream->printf("%c - ERROR: SHORT to ground on channel A!\n", designator);
error=true;
error_reported.set(2);
}else{
error_reported.reset(2);
}

if (this->isShortToGroundB()) {
if(!error_reported.test(3)) stream->printf("ERROR: SHORT to ground on channel B!\n");
if(!error_reported.test(3)) stream->printf("%c - ERROR: SHORT to ground on channel B!\n", designator);
error=true;
error_reported.set(3);
}else{
Expand All @@ -998,15 +998,15 @@ bool TMC26X::check_error_status_bits(StreamOutput *stream)

// these seem to be triggered when moving so ignore them for now
if (this->isOpenLoadA()) {
if(!error_reported.test(4)) stream->printf("ERROR: Channel A seems to be unconnected!\n");
if(!error_reported.test(4)) stream->printf("%c - ERROR: Channel A seems to be unconnected!\n", designator);
error=true;
error_reported.set(4);
}else{
error_reported.reset(4);
}

if (this->isOpenLoadB()) {
if(!error_reported.test(5)) stream->printf("ERROR: Channel B seems to be unconnected!\n");
if(!error_reported.test(5)) stream->printf("%c - ERROR: Channel B seems to be unconnected!\n", designator);
error=true;
error_reported.set(5);
}else{
Expand Down
4 changes: 3 additions & 1 deletion src/modules/utils/motordrivercontrol/drivers/TMC26X/TMC26X.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class TMC26X
* You can select a different stepping with setMicrosteps() to aa different value.
* \sa start(), setMicrosteps()
*/
TMC26X(std::function<int(uint8_t *b, int cnt, uint8_t *r)> spi);
TMC26X(std::function<int(uint8_t *b, int cnt, uint8_t *r)> spi, char designator);

/*!
* \brief configures the TMC26X stepper driver. Before you called this function the stepper driver is in nonfunctional mode.
Expand Down Expand Up @@ -445,5 +445,7 @@ class TMC26X
};

uint8_t cool_step_lower_threshold; // we need to remember the threshold to enable and disable the CoolStep feature
char designator;

};

0 comments on commit b6c3b76

Please sign in to comment.