Skip to content

Commit

Permalink
Added Jrk error settings configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
poes-weather committed Apr 30, 2012
1 parent 97b5099 commit 8126eca
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 48 deletions.
24 changes: 24 additions & 0 deletions jrk/jrk_protocol.h
Expand Up @@ -133,5 +133,29 @@ typedef struct jrk_pid_variables_t
#define JRK_PARAMETER_ERROR_ENABLE 130 // 2 byte unsigned value. See below for the meanings of the bits.
#define JRK_PARAMETER_ERROR_LATCH 132 // 2 byte unsigned value. See below for the meanings of the bits.

// There are several different errors. Each error is represented by a
// different bit number from 0 to 15.
#define JRK_ERROR_AWAITING_COMMAND 0 // Always enabled. Never latched.
#define JRK_ERROR_NO_POWER 1 // Always enabled.
#define JRK_ERROR_MOTOR_DRIVER 2 // Always enabled.
#define JRK_ERROR_INPUT_INVALID 3 // Always enabled.
#define JRK_ERROR_INPUT_DISCONNECT 4
#define JRK_ERROR_FEEDBACK_DISCONNECT 5
#define JRK_ERROR_MAXIMUM_CURRENT_EXCEEDED 6
#define JRK_ERROR_SERIAL_SIGNAL 7 // Always latched.
#define JRK_ERROR_SERIAL_OVERRUN 8 // Always latched.
#define JRK_ERROR_SERIAL_BUFFER_FULL 9 // Always latched.
#define JRK_ERROR_SERIAL_CRC 10 // Always latched.
#define JRK_ERROR_SERIAL_PROTOCOL 11 // Always latched.
#define JRK_ERROR_SERIAL_TIMEOUT 12 // Always latched.

#define JRK_ERROR(x) ((unsigned short) 1 << x)

// Certain errors are always enabled, so their corresponding error enable bit is ignored.
#define JRK_ERRORS_ALWAYS_ENABLED (((unsigned short)1<<JRK_ERROR_AWAITING_COMMAND) | ((unsigned short)1<<JRK_ERROR_NO_POWER) | ((unsigned short)1<<JRK_ERROR_MOTOR_DRIVER) | ((unsigned short)1<<JRK_ERROR_INPUT_INVALID))

// Certain errors are always latched, so their corresponding latch bit is ignored.
#define JRK_ERRORS_ALWAYS_LATCHED (((unsigned short)1<<JRK_ERROR_AWAITING_COMMAND) | ((unsigned short)1<<JRK_ERROR_SERIAL_SIGNAL) | ((unsigned short)1<<JRK_ERROR_SERIAL_CRC) | ((unsigned short)1<<JRK_ERROR_SERIAL_PROTOCOL) | ((unsigned short)1<<JRK_ERROR_SERIAL_TIMEOUT) | ((unsigned short)1<<JRK_ERROR_SERIAL_BUFFER_FULL))


#endif // JRK_PROTOCOL_H
160 changes: 128 additions & 32 deletions jrk/usbjrkdialog.cpp
Expand Up @@ -254,38 +254,19 @@ void USBJrkDialog::onJrkReadWrite(void)
}
}

#if 0
d_deg = maxdeg - mindeg;
d_fb = 4095;
current_deg = 0;

if(d_fb > 0 && d_deg > 0) {
sfb = vars.scaledFeedback;
degrees = mindeg + (d_deg / d_fb) * sfb;
current_deg = degrees;

str.sprintf("%.3f", degrees);
ui->degreesLabel->setText(str);

v = ((degrees * pid_vars.error) / 4095.0);
str.sprintf("%.3f", v);
ui->degErrorLabel->setText(str);
}
#endif

if(wFlags & WF_CALIB_MIN_FB) {
ui->feedbackMin->setValue(jrkusb->vars.scaledFeedback);
ui->feedbackDisconnectMin->setValue(jrkusb->vars.scaledFeedback / 2);
if(wFlags & WF_CALIB_MIN_FB) {
ui->feedbackMin->setValue(jrkusb->vars.scaledFeedback);
ui->feedbackDisconnectMin->setValue(jrkusb->vars.scaledFeedback / 2);

wFlags &= ~WF_CALIB_MIN_FB;
}
wFlags &= ~WF_CALIB_MIN_FB;
}

if(wFlags & WF_CALIB_MAX_FB) {
ui->feedbackMax->setValue(jrkusb->vars.scaledFeedback);
ui->feedbackDisconnectMax->setValue(jrkusb->vars.scaledFeedback + (4095 - jrkusb->vars.scaledFeedback) / 2);
if(wFlags & WF_CALIB_MAX_FB) {
ui->feedbackMax->setValue(jrkusb->vars.scaledFeedback);
ui->feedbackDisconnectMax->setValue(jrkusb->vars.scaledFeedback + (4095 - jrkusb->vars.scaledFeedback) / 2);

wFlags &= ~WF_CALIB_MAX_FB;
}
wFlags &= ~WF_CALIB_MAX_FB;
}


}
Expand All @@ -312,8 +293,7 @@ double USBJrkDialog::getComapssDegrees(void)
}

case 1: v = compass->getHeading(); break;
case 2: v = compass->getHeading() * 2.0; break;
case 3: v = compass->getRoll(); break;
case 2: v = compass->getRoll(); break;

default:
v = 0;
Expand Down Expand Up @@ -382,7 +362,7 @@ void USBJrkDialog::readParameters(void)
wFlags |= WF_INIT;

unsigned char u8, u8_2;
unsigned short u16;
unsigned short u16, u16_2;

// read feedback parameters
qDebug("read feedback parameters");
Expand Down Expand Up @@ -454,6 +434,12 @@ void USBJrkDialog::readParameters(void)
u8 = jrk->control_read_u8(JRK_REQUEST_GET_TYPE, JRK_REQUEST_GET_PARAMETER, 0, JRK_PARAMETER_FEEDBACK_DEAD_ZONE);
ui->feedbackDeadZoneSb->setValue(u8);

// error settings
u16 = jrk->control_read_u16(JRK_REQUEST_GET_TYPE, JRK_REQUEST_GET_PARAMETER, 0, JRK_PARAMETER_ERROR_ENABLE);
u16_2 = jrk->control_read_u16(JRK_REQUEST_GET_TYPE, JRK_REQUEST_GET_PARAMETER, 0, JRK_PARAMETER_ERROR_LATCH);
setErrorSettings(u16, u16_2);


// set target slider etc
jrkusb->readVariables();

Expand All @@ -470,6 +456,115 @@ void USBJrkDialog::readParameters(void)
calcDerivative();
}

//---------------------------------------------------------------------------
void USBJrkDialog::setErrorSettings(quint16 error_enable, quint16 error_latch)
{
quint16 enable, latch;

latch = error_latch & JRK_ERROR(JRK_ERROR_NO_POWER);
ui->err_powerCb->setCurrentIndex(latch ? 1:0);

latch = error_latch & JRK_ERROR(JRK_ERROR_MOTOR_DRIVER);
ui->err_motordrvCb->setCurrentIndex(latch ? 1:0);

latch = error_latch & JRK_ERROR(JRK_ERROR_INPUT_INVALID);
ui->err_inputinvalidCb->setCurrentIndex(latch ? 1:0);

enable = error_enable & JRK_ERROR(JRK_ERROR_INPUT_DISCONNECT);
latch = error_latch & JRK_ERROR(JRK_ERROR_INPUT_DISCONNECT);
ui->err_inputdisconnectCb->setCurrentIndex(to3itemIndex(enable, latch));

enable = error_enable & JRK_ERROR(JRK_ERROR_FEEDBACK_DISCONNECT);
latch = error_latch & JRK_ERROR(JRK_ERROR_FEEDBACK_DISCONNECT);
ui->err_fbdisconnectCb->setCurrentIndex(to3itemIndex(enable, latch));

enable = error_enable & JRK_ERROR(JRK_ERROR_MAXIMUM_CURRENT_EXCEEDED);
latch = error_latch & JRK_ERROR(JRK_ERROR_MAXIMUM_CURRENT_EXCEEDED);
ui->err_currentCb->setCurrentIndex(to3itemIndex(enable, latch));
}

//---------------------------------------------------------------------------
void USBJrkDialog::on_writeErrorsButton_clicked()
{
if(!jrk)
return;

quint16 enabled = jrk->control_read_u16(JRK_REQUEST_GET_TYPE, JRK_REQUEST_GET_PARAMETER, 0, JRK_PARAMETER_ERROR_ENABLE);
quint16 latched = jrk->control_read_u16(JRK_REQUEST_GET_TYPE, JRK_REQUEST_GET_PARAMETER, 0, JRK_PARAMETER_ERROR_LATCH);

twoItemsToError(&latched, JRK_ERROR(JRK_ERROR_NO_POWER), ui->err_powerCb->currentIndex());
twoItemsToError(&latched, JRK_ERROR(JRK_ERROR_MOTOR_DRIVER), ui->err_motordrvCb->currentIndex());
twoItemsToError(&latched, JRK_ERROR(JRK_ERROR_INPUT_INVALID), ui->err_inputinvalidCb->currentIndex());


threeItemsToError(&enabled, &latched, JRK_ERROR(JRK_ERROR_INPUT_DISCONNECT), ui->err_inputdisconnectCb->currentIndex());
threeItemsToError(&enabled, &latched, JRK_ERROR(JRK_ERROR_FEEDBACK_DISCONNECT), ui->err_fbdisconnectCb->currentIndex());
threeItemsToError(&enabled, &latched, JRK_ERROR(JRK_ERROR_MAXIMUM_CURRENT_EXCEEDED), ui->err_currentCb->currentIndex());

enabled |= JRK_ERRORS_ALWAYS_ENABLED;
latched |= JRK_ERRORS_ALWAYS_LATCHED;

set_parameter_u16(JRK_PARAMETER_ERROR_ENABLE, enabled);
set_parameter_u16(JRK_PARAMETER_ERROR_LATCH, latched);
}


//---------------------------------------------------------------------------
int USBJrkDialog::to3itemIndex(bool enable, bool latch)
{
/*
i = 1 = disable
i = 2 = enable
i = 3 = enable and latch
*/

int i = 0;

if(!enable && !latch)
i = 0;
else {
if(enable)
i = 1;
if(latch)
i = 2;
}

return i;
}

//---------------------------------------------------------------------------
void USBJrkDialog::threeItemsToError(quint16 *error_enable, quint16 *error_latch, quint16 value, int index)
{
*error_enable &= ~value;
*error_latch &= ~value;

/*
index
1 = disable
2 = enable
3 = enable and latch
*/

if(index == 1 || index == 2) {
*error_enable |= value;
if(index == 2)
*error_latch |= value;
}
}

//---------------------------------------------------------------------------
void USBJrkDialog::twoItemsToError(quint16 *error_latch, quint16 value, int index)
{
*error_latch &= ~value;
/*
index
0 = enable
1 = enable and latch
*/
*error_latch |= index == 1 ? value:0;

}

//---------------------------------------------------------------------------
void USBJrkDialog::on_targetSlider_valueChanged(int value)
{
Expand Down Expand Up @@ -1025,3 +1120,4 @@ void USBJrkDialog::on_recordLUTButton_clicked()

//---------------------------------------------------------------------------


7 changes: 7 additions & 0 deletions jrk/usbjrkdialog.h
Expand Up @@ -86,6 +86,8 @@ private slots:
void on_targetTodegreesLUTcb_clicked();
void on_recordLUTButton_clicked();

void on_writeErrorsButton_clicked();

protected:
void readSettings(void);
void writeSettings(void);
Expand All @@ -100,6 +102,11 @@ private slots:
void setResolution(void);
double getComapssDegrees(void);

void setErrorSettings(quint16 error_enable, quint16 error_latch);
int to3itemIndex(bool enable, bool latch);
void threeItemsToError(quint16 *error_enable, quint16 *error_latch, quint16 value, int index);
void twoItemsToError(quint16 *error_latch, quint16 value, int index);


private:
Ui::USBJrkDialog *ui;
Expand Down

0 comments on commit 8126eca

Please sign in to comment.