Files
gcs-nf/App/ToolsUI/ServoSystem/ServoSystem.cpp
T
2022-05-31 18:22:08 +08:00

1168 lines
34 KiB
C++

#include "ServoSystem.h"
#include "ui_ServoSystem.h"
ServoSystem::ServoSystem(QWidget *parent) :
QWidget(parent),
ui(new Ui::ServoSystem)
{
ui->setupUi(this);
m_parent = parent;
setWindowTitle(tr("ServoSyste"));
//load qss
QFile file(":/qss/ServoSystem.qss");
file.open(QFile::ReadOnly);
QTextStream filetext(&file);
QString stylesheet = filetext.readAll();
this->setStyleSheet(stylesheet);
file.close();
//========
setColor(ui->checkBox_onBoard,state::success);
setColor(ui->checkBox_28v,state::success);
setColor(ui->checkBox_56v,state::success);
setColor(ui->checkBox_AirSpeed,state::success);
setColor(ui->checkBox_500W,state::failure);
//setColor(ui->label_LE_SBIT,state::failure);
setCheckState(6,state::failure);
setCheckState(7,state::failure);
setCheckState(8,state::failure);
setCheckState(9,state::failure);
setCheckState(10,state::failure);
setCheckState(11,state::failure);
Config *cfg = new Config();
cfg->getServoOffset(&dir_la,&dir_ra,&dir_le,&dir_re,&dir_ru,
&max_la,&max_ra,&max_le,&max_re,&max_ru,
&scale_la,&scale_ra,&scale_le,&scale_re,&scale_ru,
&bias_la,&bias_ra,&bias_le,&bias_re,&bias_ru);
ui->comboBox_Full->addItem("基准档",0x85);
ui->comboBox_Full->addItem("1档",0x16);
ui->comboBox_Full->addItem("2档",0x26);
ui->comboBox_Full->addItem("3档",0x36);
ui->comboBox_Full->addItem("4档",0x46);
ui->comboBox_Full->addItem("5档",0x56);
ui->comboBox_Full->addItem("6档",0x66);
ui->comboBox_Full->addItem("7档",0x76);
ui->comboBox_Full->addItem("8档",0x86);
ui->comboBox_Full->addItem("9档",0x96);
ui->comboBox_Full->setCurrentIndex(0);
ui->comboBox_Half->addItem("基准档",0x75);
ui->comboBox_Half->addItem("1档",0x1c);
ui->comboBox_Half->addItem("2档",0x2c);
ui->comboBox_Half->addItem("3档",0x3c);
ui->comboBox_Half->addItem("4档",0x4c);
ui->comboBox_Half->addItem("5档",0x5c);
ui->comboBox_Half->addItem("6档",0x6c);
ui->comboBox_Half->addItem("7档",0x7c);
ui->comboBox_Half->addItem("8档",0x8c);
ui->comboBox_Half->addItem("9档",0x9c);
ui->comboBox_Half->setCurrentIndex(0);
ui->comboBox_rate->addItem("10000",10000);
ui->comboBox_rate->addItem("13700",13700);
ui->comboBox_rate->addItem("15000",15000);
ui->comboBox_rate->addItem("20000",20000);
ui->comboBox_rate->addItem("25000",25000);
ui->comboBox_rate->addItem("30000",30000);
ui->comboBox_rate->addItem("35000",35000);
ui->comboBox_rate->addItem("40000",40000);
ui->comboBox_rate->addItem("46000",46000);
ui->comboBox_rate->setEditable(true);
ui->comboBox_rate->setCurrentIndex(-1);
ui->comboBox_TestPoint->addItem("核心机主燃油泵",0x19);
ui->comboBox_TestPoint->addItem("加力主燃油泵",0x29);
ui->comboBox_TestPoint->addItem("加力点火燃油泵",0x49);
ui->comboBox_TestPoint->addItem("尾喷口舵机",0x79);
ui->comboBox_TestPoint->addItem("点火器",0x89);
ui->comboBox_TestPoint->addItem("起动控制1",0xb9);
ui->comboBox_TestPoint->addItem("起动控制2",0xd9);
ui->comboBox_TestPoint->addItem("核心机点火油阀",0x1a);
ui->comboBox_TestPoint->addItem("核心机优先油阀",0x2a);
ui->comboBox_TestPoint->addItem("核心机清吹油阀",0x4a);
ui->comboBox_TestPoint->addItem("核心机起动气阀",0x7a);
ui->comboBox_TestPoint->addItem("核心机主油阀",0x8a);
ui->comboBox_TestPoint->addItem("加力主油阀",0xba);
ui->comboBox_TestPoint->addItem("加力清吹阀",0xda);
ui->comboBox_TestPoint->addItem("加力点火快速阀",0xea);
ui->comboBox_TestPoint->addItem("手动转速控制",0xd5);
ui->comboBox_TestPoint->setCurrentIndex(-1);
ui->comboBox_TestValue->show();
ui->comboBox_TestValue->setCurrentIndex(-1);
//use_ext_ins参数名称
ui->comboBox_IMU->addItem("内置惯导",0);
ui->comboBox_IMU->addItem("SBG",1);
ui->comboBox_IMU->setCurrentIndex(0);
ui->comboBox_ServoType->addItem("左副翼",0x01);
ui->comboBox_ServoType->addItem("右副翼",0x02);
ui->comboBox_ServoType->addItem("左升降",0x03);
ui->comboBox_ServoType->addItem("右升降",0x04);
ui->comboBox_ServoType->addItem("方向舵",0x05);
ui->comboBox_ServoType->setCurrentIndex(0);
/*
ui->comboBox_sel_ch->addItem("关闭",0x00);
ui->comboBox_sel_ch->addItem("左副翼",0x01);
ui->comboBox_sel_ch->addItem("右副翼",0x02);
ui->comboBox_sel_ch->addItem("左升降",0x03);
ui->comboBox_sel_ch->addItem("右升降",0x04);
ui->comboBox_sel_ch->addItem("方向舵",0x05);
ui->comboBox_sel_ch->setCurrentIndex(0);
*/
//ui->pushButton_AirHeatOff->hide();
//ui->pushButton_AirHeatOn->hide();
//ui->pushButton_HeatOn3->hide();
//ui->pushButton_HeatOn4->hide();
m_ra = 0;
m_la = 0;
m_ru = 0;
m_re = 0;
m_le = 0;
ui->pushButton_HeatOn1->setHidden(true);
ui->pushButton_HeatOn2->setHidden(true);
}
ServoSystem::~ServoSystem()
{
delete ui;
}
void ServoSystem::closeEvent(QCloseEvent *event)
{
setFloat();
event->ignore();
}
void ServoSystem::contextMenuEvent(QContextMenuEvent *event)
{
/*
QMenu *menu = new QMenu(this);
QAction *pAction = new QAction("float",this);
connect(pAction,SIGNAL(triggered(bool)),
this,SLOT(setFloat()));
menu->addAction(pAction);
menu->move(cursor().pos());
menu->show();
*/
}
void ServoSystem::setFloat(void)
{
if(this->parent())
{
this->setParent(nullptr);
this->show();
}
else
{
this->setParent(m_parent);
this->move(0,0);
//this->hide();
this->show();
this->resize(m_parent->size());
}
//
}
void ServoSystem::setColor(QWidget *w,state s)
{
w->setProperty("state",s);
w->style()->unpolish(w);
w->style()->polish(w);
}
void ServoSystem::setValue(QLabel *w,QString s)
{
w->setText(s);
}
void ServoSystem::setServoOffset(QVariant dirla, QVariant dirra, QVariant dirle, QVariant dirre, QVariant dirru,
QVariant maxla, QVariant maxra, QVariant maxle, QVariant maxre, QVariant maxru,
QVariant scalela, QVariant scalera, QVariant scalele, QVariant scalere, QVariant scaleru,
QVariant la, QVariant ra,QVariant le, QVariant re,QVariant ru)
{
dir_la = dirla;
dir_ra = dirra;
dir_le = dirle;
dir_re = dirre;
dir_ru = dirru;
max_la = maxla;
max_ra = maxra;
max_le = maxle;
max_re = maxre;
max_ru = maxru;
scale_la = scalela;
scale_ra = scalera;
scale_le = scalele;
scale_re = scalere;
scale_ru = scaleru;
bias_la = la;
bias_ra = ra;
bias_le = le;
bias_re = re;
bias_ru = ru;
}
void ServoSystem::setBUMState(mavlink_bmustate_t *t)
{
ui->label_temp_28->setText(QString::number((int16_t)t->BAT1_low_temp_degC)+ "/" + QString::number((int16_t)t->BAT1_hi_temp_degC));
ui->label_temp_56->setText(QString::number((int16_t)t->BAT2_low_temp_degC)+ "/" + QString::number((int16_t)t->BAT2_hi_temp_degC));
ui->label_onBoard_28V_Voltage->setText(QString::number(t->BAT1_group_voltage_mv * 0.001,'f',1));
ui->label_onBoard_28V_Current->setText(QString::number((float)((int16_t)t->BAT1_group_current_dA) *0.1f,'f',1));
ui->label_onBoard_56V_Voltage->setText(QString::number(t->BAT2_group_voltage_mv * 0.001,'f',1));
ui->label_onBoard_56V_Current->setText(QString::number((float)((int16_t)t->BAT2_group_current_dA) *0.1f,'f',1));
ui->label_28V_percent->setText(QString::number((float)(t->BAT1_remain_perc *0.1f),'f',1));
ui->label_56V_percent->setText(QString::number((float)(t->BAT2_remain_perc *0.1f),'f',1));
}
void ServoSystem::setCheckState(uint32_t pos,QVariant value)
{
switch (pos) {
case 1:
setColor(ui->checkBox_onBoard,(value.toBool())?(state::success):(state::failure));
break;
case 2:
setColor(ui->checkBox_28v,(value.toBool())?(state::success):(state::failure));
break;
case 3:
setColor(ui->checkBox_56v,(value.toBool())?(state::success):(state::failure));
break;
case 4:
setColor(ui->checkBox_AirSpeed,(value.toBool())?(state::success):(state::failure));
break;
case 5:
setColor(ui->checkBox_500W,(value.toBool())?(state::success):(state::failure));
break;
case 6:
//setColor(ui->checkBox_5525D,(value.toBool())?(state::success):(state::failure));
break;
case 7:
//setColor(ui->checkBox_5803A,(value.toBool())?(state::success):(state::failure));
break;
case 8:
//setColor(ui->checkBox_5607A,(value.toBool())?(state::success):(state::failure));
break;
case 9:
//setColor(ui->checkBox_4525D,(value.toBool())?(state::success):(state::failure));
break;
case 10:
//setColor(ui->checkBox_atteck,(value.toBool())?(state::success):(state::failure));
break;
case 11:
//setColor(ui->checkBox_slide,(value.toBool())?(state::success):(state::failure));
break;
}
//qDebug() << pos << value;
}
void ServoSystem::setServoState(mavlink_servo_output_raw_t *t)
{
ui->label_rud_curr->setText( QString::number(dir_ru.toInt() * ((int16_t)t->servo13_raw)/32767.0 * max_ru.toDouble()/scale_ru.toDouble() + bias_ru.toDouble() * 57.295,'f',2));
ui->label_ele_l_curr->setText(QString::number(dir_le.toInt() * ((int16_t)t->servo15_raw)/32767.0 * max_le.toDouble()/scale_le.toDouble() + bias_le.toDouble() * 57.295,'f',2));
ui->label_ele_r_curr->setText(QString::number(dir_re.toInt() * ((int16_t)t->servo12_raw)/32767.0 * max_re.toDouble()/scale_re.toDouble() + bias_re.toDouble() * 57.295,'f',2));
ui->label_ail_l_curr->setText(QString::number(dir_la.toInt() * ((int16_t)t->servo14_raw)/32767.0 * max_la.toDouble()/scale_la.toDouble() + bias_la.toDouble() * 57.295,'f',2));
ui->label_ail_r_curr->setText(QString::number(dir_ra.toInt() * ((int16_t)t->servo11_raw)/32767.0 * max_ra.toDouble()/scale_ra.toDouble() + bias_ra.toDouble() * 57.295,'f',2));
ui->label_rud_cmd->setText( QString::number(dir_ru.toInt() * ((int16_t)t->servo3_raw)/32767.0 * max_ru.toDouble()/scale_ru.toDouble() + bias_ru.toDouble() * 57.295,'f',2));//ru
ui->label_ele_l_cmd->setText(QString::number(dir_le.toInt() * ((int16_t)t->servo1_raw)/32767.0 * max_le.toDouble()/scale_le.toDouble() + bias_le.toDouble() * 57.295,'f',2));//le
ui->label_ele_r_cmd->setText(QString::number(dir_re.toInt() * ((int16_t)t->servo2_raw)/32767.0 * max_re.toDouble()/scale_re.toDouble() + bias_re.toDouble() * 57.295,'f',2));//re
ui->label_ail_l_cmd->setText(QString::number(dir_la.toInt() * ((int16_t)t->servo4_raw)/32767.0 * max_la.toDouble()/scale_la.toDouble() + bias_la.toDouble() * 57.295,'f',2));//la
ui->label_ail_r_cmd->setText(QString::number(dir_ra.toInt() * ((int16_t)t->servo5_raw)/32767.0 * max_ra.toDouble()/scale_ra.toDouble() + bias_ra.toDouble() * 57.295,'f',2));//ra
/*
sbus = feedback (ra)
sbus = feedback (re)
sbus = feedback (ru)
sbus = feedback (la)
15 sbus = feedback (le)
health = 0 ra000 re000 ru000 la000 le000
GBIT zero SBIT
*/
uint16_t health = t->servo16_raw;
//qDebug() << health;
setColor(ui->label_LE_SBIT,((health&0x0004) > 0)?(state::success):(state::failure));
setColor(ui->label_LE_ZERO,((health&0x0002) > 0)?(state::success):(state::failure));
setColor(ui->label_LE_GBIT,((health&0x0001) > 0)?(state::success):(state::failure));
setColor(ui->label_LA_SBIT,((health&0x0020) > 0)?(state::success):(state::failure));
setColor(ui->label_LA_ZERO,((health&0x0010) > 0)?(state::success):(state::failure));
setColor(ui->label_LA_GBIT,((health&0x0008) > 0)?(state::success):(state::failure));
setColor(ui->label_RU_SBIT,((health&0x0100) > 0)?(state::success):(state::failure));
setColor(ui->label_RU_ZERO,((health&0x0080) > 0)?(state::success):(state::failure));
setColor(ui->label_RU_GBIT,((health&0x0040) > 0)?(state::success):(state::failure));
setColor(ui->label_RE_SBIT,((health&0x0800) > 0)?(state::success):(state::failure));
setColor(ui->label_RE_ZERO,((health&0x0400) > 0)?(state::success):(state::failure));
setColor(ui->label_RE_GBIT,((health&0x0200) > 0)?(state::success):(state::failure));
setColor(ui->label_RA_SBIT,((health&0x4000) > 0)?(state::success):(state::failure));
setColor(ui->label_RA_ZERO,((health&0x2000) > 0)?(state::success):(state::failure));
setColor(ui->label_RA_GBIT,((health&0x1000) > 0)?(state::success):(state::failure));
}
void ServoSystem::setAPversion(QString ver)
{
ui->label_APVer->setText(ver);
emit showMessage(tr("飞控软件版本信息:%1").arg(ver));
}
void ServoSystem::setHILMode(QString mode)
{
ui->label_HILMode->setText(mode);
emit showMessage((mode.toInt()>0)?("进入HIL仿真"):("退出HIL仿真"));
}
float ServoSystem::param_getvalue(QVariant param,uint8_t type)
{
float value;
union {
uint8_t u8[8];
int8_t i8[8];
uint16_t u16[4];
int16_t i16[4];
uint32_t u32[2];
int32_t i32[2];
uint64_t u64;
int64_t i64;
float f[2];
double d;
}src;
switch (type)
{
case MAV_PARAM_TYPE_UINT8:
{
src.u8[0] = param.toUInt();
((uint8_t *)&value)[0] = src.u8[0];
}break;
case MAV_PARAM_TYPE_INT8:
{
src.i8[0] = param.toUInt();
((int8_t *)&value)[0] = src.i8[0];
}break;
case MAV_PARAM_TYPE_UINT16:
{
src.u16[0] = param.toUInt();
((uint16_t *)&value)[0] = src.u16[0];
}break;
case MAV_PARAM_TYPE_INT16:
{
src.i16[0] = param.toUInt();
((int16_t *)&value)[0] = src.i16[0];
}break;
case MAV_PARAM_TYPE_UINT32:
{
src.u32[0] = param.toUInt();
((uint32_t *)&value)[0] = (uint32_t)src.u32[0];
}break;
case MAV_PARAM_TYPE_INT32:
{
src.i32[0] = param.toUInt();
((int32_t *)&value)[0] = (int32_t)src.i32[0];
}break;
case MAV_PARAM_TYPE_UINT64:
{
src.u64 = param.toUInt();
((uint64_t *)&value)[0] = (uint64_t )src.u64;
}break;
case MAV_PARAM_TYPE_INT64:
{
src.i64 = param.toUInt();
((int64_t *)&value)[0] = (int64_t)src.i64;
}break;
case MAV_PARAM_TYPE_REAL32:
{
src.f[0] = param.toFloat();
((float *)&value)[0] = (float)src.f[0];
}break;
case MAV_PARAM_TYPE_REAL64:
{
src.d = param.toDouble();
((double *)&value)[0]= (double)src.d;
}break;
default:
{
src.f[0] = param.toFloat();
((float *)&value)[0] = (float)src.i32[0];
}break;
}
return value;
}
void ServoSystem::commandAccepted(bool flag,uint16_t command,uint8_t result)
{
bool isFundSender = false;
QString string;
//找到消息的发送者
QObjectList list = ui->frame->children();
// qDebug() << list;
//qDebug() << CommandBox.findChildren();
if(command == m_command)
{
isFundSender = true;
switch (result) {
case MAV_RESULT_ACCEPTED:
string.append(tr("%1,%2 accepted and executed").arg(command).arg(m_name));
break;
case MAV_RESULT_TEMPORARILY_REJECTED:
string.append(tr("%1,%2 rejected").arg(command).arg(m_name));
break;
case MAV_RESULT_DENIED:
string.append(tr("%1,%2 permanently denied").arg(command).arg(m_name));
break;
case MAV_RESULT_UNSUPPORTED:
string.append(tr("%1,%2 unsupported").arg(command).arg(m_name));
break;
case MAV_RESULT_FAILED:
string.append(tr("%1,%2 failed").arg(command).arg(m_name));
break;
case MAV_RESULT_IN_PROGRESS:
string.append(tr("%1,%2 being executed").arg(command).arg(m_name));
break;
case 0xFE:
string.append(tr("%1,%2 time out").arg(command).arg(m_name));
break;
case 0xFF:
string.append(tr("Please do not operate too fast, the last instruction has not been sent"));
break;
default:
break;
}
ui->lineEdit_CommandName->clear();
m_name.clear();
m_param1 = 0;
m_param2 = 0;
m_param3 = 0;
m_param4 = 0;
m_param5 = 0;
m_param6 = 0;
m_param7 = 0;
m_command = 0;
m_confirm = 0;
}
if(string.size() > 0)
{
QTextToSpeech *tts = new QTextToSpeech();
tts->say(string);
tts->deleteLater();
emit showMessage(string);
}
}
void ServoSystem::on_comboBox_TestPoint_currentIndexChanged(int index)
{
switch (index) {
case 0:
case 1:
case 2:
case 3:
case 15:
ui->label_TestValue->show();
ui->label_TestValue->setText("转速");
ui->comboBox_TestValue->show();
ui->comboBox_TestValue->clear();
ui->comboBox_TestValue->addItem("10000",10000);
if(index == 2)
{
ui->comboBox_TestValue->addItem("13700",13700);
}
ui->comboBox_TestValue->addItem("15000",15000);
ui->comboBox_TestValue->addItem("20000",20000);
ui->comboBox_TestValue->addItem("25000",25000);
ui->comboBox_TestValue->addItem("30000",30000);
ui->comboBox_TestValue->addItem("35000",35000);
ui->comboBox_TestValue->addItem("40000",40000);
if(index != 3)
{
ui->comboBox_TestValue->addItem("45000",45000);
}
ui->comboBox_TestValue->setCurrentIndex(0);
break;
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
ui->label_TestValue->show();
ui->label_TestValue->setText("电平");
ui->comboBox_TestValue->show();
ui->comboBox_TestValue->clear();
ui->comboBox_TestValue->addItem("低电平",0);
ui->comboBox_TestValue->addItem("高电平",1);
ui->comboBox_TestValue->setEditable(true);
ui->comboBox_TestValue->setCurrentIndex(1);
break;
case 4:
ui->label_TestValue->hide();
ui->comboBox_TestValue->hide();
break;
}
}
//二次确认
void ServoSystem::setSecondConfirm(QVariant value)
{
if(value.toBool() == true)
{
emit cmd_long(m_param1,m_param2,m_param3,m_param4,m_param5,m_param6,m_param7,m_command,m_confirm);
}
else
{
ui->lineEdit_CommandName->clear();
m_name.clear();
m_param1 = 0;
m_param2 = 0;
m_param3 = 0;
m_param4 = 0;
m_param5 = 0;
m_param6 = 0;
m_param7 = 0;
m_command = 0;
m_confirm = 0;
}
}
void ServoSystem::on_pushButton_SendCommand_clicked()
{
if(cmdType == 0)
{
if(m_command == 0)
{
emit showMessage(tr("please set command first ,command :%1").arg(m_command));
return;
}
}
if(cmdType == 0)
{
emit showMessage(tr("发送指令 ") + QString::number(m_command) + " " + m_name,5000);
emit cmd_long(m_param1,m_param2,m_param3,m_param4,m_param5,m_param6,m_param7,m_command,m_confirm);
}
else if(cmdType == 1)
{
emit showMessage(tr("修改参数 ") + " " + m_id.toLatin1().data() + " " + QString::number(m_value),5000);
emit WriteCmd(m_sysid,m_compid,m_id.toLatin1().data(),m_type,param_getvalue(m_value,m_type));
}
}
void ServoSystem::on_pushButton_Cancel_clicked()
{
ui->lineEdit_CommandName->clear();
m_name.clear();
m_param1 = 0;
m_param2 = 0;
m_param3 = 0;
m_param4 = 0;
m_param5 = 0;
m_param6 = 0;
m_param7 = 0;
m_command = 0;
m_confirm = 0;
}
void ServoSystem::on_commandClicked(QString name,
float param1,float param2,float param3,float param4,
float param5,float param6,float param7,
uint16_t command,uint8_t confirmation)
{
m_name = name;
m_param1 = param1;
m_param2 = param2;
m_param3 = param3;
m_param4 = param4;
m_param5 = param5;
m_param6 = param6;
m_param7 = param7;
m_command = command;
m_confirm = confirmation;
ui->lineEdit_CommandName->setText(name);
cmdType = 0;
}
void ServoSystem::on_paramClicked(uint8_t sysid, uint8_t compid , QString id, uint8_t type, float value)
{
m_sysid = sysid;
m_compid = compid;
m_id = id;
m_type = type;
m_value = value;
ui->lineEdit_CommandName->setText(id + " " + QString::number(value));
cmdType = 1;
}
//测试指令
void ServoSystem::on_pushButton_SendTest_clicked()
{
//判断 两个 内容是否是空,
float testPoint = 0;
float testValue = 0;
if(!ui->comboBox_TestValue->isHidden())//如果显示
{
testPoint = ui->comboBox_TestPoint->currentData(Qt::UserRole).toFloat();
testValue = ui->comboBox_TestValue->currentData(Qt::UserRole).toFloat();
if((ui->comboBox_TestPoint->currentIndex() != -1)&&(ui->comboBox_TestValue->currentIndex() != -1))
{
on_commandClicked(ui->comboBox_TestPoint->currentText() + " " + ui->comboBox_TestValue->currentText() ,
103,testPoint,testValue,0,0,0,0,180,0);
}
else
{
QMessageBox *box = new QMessageBox(this);
box->setWindowTitle(tr("警告"));
box->setText(tr("请选择测试项和测试点"));
box->show();
}
}
else
{
if(ui->comboBox_TestPoint->currentIndex() != -1)
{
testPoint = ui->comboBox_TestPoint->currentData(Qt::UserRole).toFloat();
on_commandClicked(ui->comboBox_TestPoint->currentText(),
103,testPoint,0,0,0,0,0,180,0);
}
else
{
QMessageBox *box = new QMessageBox(this);
box->setWindowTitle(tr("警告"));
box->setText(tr("请选择测试项和测试点"));
box->show();
}
}
}
//舵机指令
void ServoSystem::on_pushButton_Servo_Check_clicked()
{
on_commandClicked(ui->pushButton_Servo_Check->text(),
1,0,0,0,0,0,0,20004,0);
}
void ServoSystem::on_pushButton_Servo_Read_clicked()
{
on_commandClicked(ui->pushButton_Servo_Read->text(),
2,0,0,0,0,0,0,20004,0);
}
void ServoSystem::on_pushButton_Servo_Zero_clicked()
{
on_commandClicked(ui->pushButton_Servo_Zero->text(),
3,0,0,0,0,0,0,20004,0);
}
void ServoSystem::on_pushButton_Servo_Work_clicked()
{
on_commandClicked(ui->pushButton_Servo_Work->text(),
4,0,0,0,0,0,0,20004,0);
}
void ServoSystem::on_pushButton_coldrun_clicked()
{
on_commandClicked(ui->pushButton_coldrun->text(),
103,0x13,0,0,0,0,0,180,0);
}
void ServoSystem::on_pushButton_groundstartup_clicked()
{
on_commandClicked(ui->pushButton_groundstartup->text(),
103,0x15,0,0,0,0,0,180,0);
}
void ServoSystem::on_pushButton_Afterburner_off_clicked()
{
on_commandClicked(ui->pushButton_Afterburner_off->text(),
103,0xb5,20000,0,0,0,0,180,0);
}
void ServoSystem::on_pushButton_stop_clicked()
{
on_commandClicked(ui->pushButton_stop->text(),
103,0x43,0,0,0,0,0,180,0);
}
void ServoSystem::on_pushButton_EmergencyStop_clicked()
{
on_commandClicked(ui->pushButton_EmergencyStop->text(),
103,0x73,0,0,0,0,0,180,0);
}
void ServoSystem::on_pushButton_Afterburner_on_clicked()
{
//根据档位选择
float Level = ui->comboBox_Full->currentData(Qt::UserRole).toFloat();
on_commandClicked(ui->pushButton_Afterburner_on->text() + " " + ui->comboBox_Full->currentText(),
103,Level,46000,0,0,0,0,180,0);
}
void ServoSystem::on_pushButton_Afterburner_half_clicked()
{
float Level = ui->comboBox_Half->currentData(Qt::UserRole).toFloat();
on_commandClicked(ui->pushButton_Afterburner_half->text() + " " + ui->comboBox_Half->currentText(),
103,Level,46000,0,0,0,0,180,0);
}
void ServoSystem::on_pushButton_setRPM_clicked()
{
if(ui->comboBox_rate->currentIndex() != -1)
{
float rpm = ui->comboBox_rate->currentData(Qt::UserRole).toFloat();
on_commandClicked(ui->pushButton_setRPM->text() + " " + ui->comboBox_rate->currentText(),
103,0x45,rpm,0,0,0,0,180,0);
}
else
{
QMessageBox *box = new QMessageBox(this);
box->setWindowTitle(tr("警告"));
box->setText(tr("请设定给定转速"));
box->show();
}
}
void ServoSystem::on_pushButton_IMU_clicked()
{
if((ui->comboBox_IMU->currentIndex() != -1)&&(ui->comboBox_sys->currentIndex() != -1))
{
uint8_t sysid = ui->comboBox_sys->currentData(Qt::UserRole).toInt();
uint8_t compid = 1;
QString id;
uint8_t type = MAV_PARAM_TYPE_INT8;
id.clear();
id.append("use_ext_ins");
//float value = param_getvalue(ui->comboBox_IMU->currentData(Qt::UserRole).toInt(),type);
on_paramClicked(sysid,compid,id,type,ui->comboBox_IMU->currentData(Qt::UserRole).toDouble());
//emit showMessage(tr("修改参数 ") + " " + m_id.toLatin1().data() + " " + QString::number(ui->comboBox_IMU->currentData(Qt::UserRole).toInt()),5000);
}
else
{
QMessageBox *box = new QMessageBox(this);
box->setWindowTitle(tr("警告"));
box->setText(tr("请设定目标"));
box->show();
}
}
void ServoSystem::on_pushButton_IAS_SEL_0_clicked()
{
if(ui->comboBox_sys->currentIndex() != -1)
{
uint8_t sysid = ui->comboBox_sys->currentData(Qt::UserRole).toInt();
uint8_t compid = 1;
QString id;
uint8_t type = MAV_PARAM_TYPE_UINT8;
id.clear();
id.append("IAS_SEL");
//float value = param_getvalue(0,type);
//emit showMessage(tr("修改参数 ") + " " + m_id.toLatin1().data() + " " + QString::number(0),5000);
on_paramClicked(sysid,compid,id,type,0);
}
else
{
QMessageBox *box = new QMessageBox(this);
box->setWindowTitle(tr("警告"));
box->setText(tr("请设定目标"));
box->show();
}
}
void ServoSystem::on_pushButton_IAS_SEL_1_clicked()
{
if(ui->comboBox_sys->currentIndex() != -1)
{
uint8_t sysid = ui->comboBox_sys->currentData(Qt::UserRole).toInt();
uint8_t compid = 1;
QString id;
uint8_t type = MAV_PARAM_TYPE_UINT8;
id.clear();
id.append("IAS_SEL");
//float value = param_getvalue(1,type);
//emit showMessage(tr("修改参数 ") + " " + m_id.toLatin1().data() + " " + QString::number(1),5000);
on_paramClicked(sysid,compid,id,type,1);
}
else
{
QMessageBox *box = new QMessageBox(this);
box->setWindowTitle(tr("警告"));
box->setText(tr("请设定目标"));
box->show();
}
}
void ServoSystem::on_pushButton_IAS_SEL_2_clicked()
{
if(ui->comboBox_sys->currentIndex() != -1)
{
uint8_t sysid = ui->comboBox_sys->currentData(Qt::UserRole).toInt();
uint8_t compid = 1;
QString id;
uint8_t type = MAV_PARAM_TYPE_UINT8;
id.clear();
id.append("IAS_SEL");
//float value = param_getvalue(2,type);
//emit showMessage(tr("修改参数 ") + " " + m_id.toLatin1().data() + " " + QString::number(2),5000);
on_paramClicked(sysid,compid,id,type,2);
}
else
{
QMessageBox *box = new QMessageBox(this);
box->setWindowTitle(tr("警告"));
box->setText(tr("请设定目标"));
box->show();
}
}
void ServoSystem::addVehicles(int sysid, int compid)
{
Q_UNUSED(compid)
if(ui->comboBox_sys->findData(sysid) == -1)
{
ui->comboBox_sys->addItem(QString::number(sysid),sysid);
}
}
void ServoSystem::on_pushButton_ServoSet_clicked()
{
if(ui->comboBox_ServoType->currentIndex() != -1)
{
switch(ui->comboBox_ServoType->currentData(Qt::UserRole).toInt())
{
case 1:
{
m_la = ui->spinBox_Servo->value();
}break;
case 2:
{
m_ra = ui->spinBox_Servo->value();
}break;
case 3:
{
m_le = ui->spinBox_Servo->value();
}break;
case 4:
{
m_re = ui->spinBox_Servo->value();
}break;
case 5:
{
m_ru = ui->spinBox_Servo->value();
}break;
}
on_commandClicked(tr("设定舵机 %1 %2").arg(ui->comboBox_ServoType->currentText()).arg(ui->spinBox_Servo->value()),
106,m_ra,m_re,m_ru,m_la,m_le,0,180,0);
//qDebug() << m_ra << m_re << m_ru << m_la << m_le;
}
else
{
QMessageBox *box = new QMessageBox(this);
box->setWindowTitle(tr("警告"));
box->setText(tr("请设定"));
box->show();
}
}
void ServoSystem::on_pushButton_Zero_clicked()
{
m_ra = 0;
m_la = 0;
m_ru = 0;
m_re = 0;
m_le = 0;
on_commandClicked(tr("设定舵机归零 %1").arg(ui->pushButton_Zero->text()),
106,m_ra,m_re,m_ru,m_la,m_le,0,180,0);
}
void ServoSystem::on_pushButton_setFuel_clicked()
{
double value = ui->doubleSpinBox_Fuel->value();
on_commandClicked(tr("%1 %2kg").arg(ui->pushButton_setFuel->text()).arg(QString::number(value)),
value,0,0,0,0,0,0,20009,0);
}
/*
void ServoSystem::on_pushButton_AngleZero_clicked()//动压归零
{
on_commandClicked(tr("设定 %1").arg(ui->pushButton_AngleZero->text()),
0,0,1,0,0,0,0,20005,0);
}
void ServoSystem::on_pushButton_ZeroComplete_clicked()
{
on_commandClicked(tr("设定 %1").arg(ui->pushButton_ZeroComplete->text()),
0,0,0,0,0,0,0,20005,0);
}
*/
void ServoSystem::on_pushButton_HeatOn1_clicked()
{
on_commandClicked(tr("设定 %1").arg(ui->pushButton_HeatOn1->text()),
1,0,0,0,0,0,0,20005,0);
}
void ServoSystem::on_pushButton_HeatOn2_clicked()
{
on_commandClicked(tr("设定 %1").arg(ui->pushButton_HeatOn2->text()),
0,1,0,0,0,0,0,20005,0);
}
//伺服指令
void ServoSystem::on_pushButton_AirHeatOn_clicked()
{
on_commandClicked(ui->pushButton_AirHeatOn->text(),
1,1,0,0,0,0,0,20005,0);
}
void ServoSystem::on_pushButton_HeatOff_clicked()
{
on_commandClicked(ui->pushButton_HeatOff->text(),
0,0,0,0,0,0,0,20005,0);
}
void ServoSystem::on_pushButton_ServoTest_clicked()//IDLE
{
on_commandClicked(tr("设定 %1").arg(ui->pushButton_ServoTest->text()),
0,0,0,0,0,0,0,20007,0);
}
void ServoSystem::on_pushButton_StabilizeTest_clicked()
{
on_commandClicked(tr("设定 %1").arg(ui->pushButton_StabilizeTest->text()),
1,0,0,0,0,0,0,20007,0);
}
void ServoSystem::on_pushButton_ManualTest_clicked()
{
on_commandClicked(tr("设定 %1").arg(ui->pushButton_ManualTest->text()),
2,0,0,0,0,0,0,20007,0);
}
void ServoSystem::on_pushButton_swep_clicked()
{
on_commandClicked(tr("设定 %1").arg(ui->pushButton_swep->text()),
3,0,0,0,0,0,0,20007,0);
}
void ServoSystem::on_pushButton_test_cmd_clicked()
{
uint8_t ch = 0;
float A;
float start;
float stop;
float K;
//ch = ui->comboBox_sel_ch->currentData(Qt::UserRole).toInt();
/* 1 ail
* 2 ele
* 4 rud
* */
ch |= ui->checkBox_ail->isChecked()?(1):(0);
ch |= ui->checkBox_ele->isChecked()?(2):(0);
ch |= ui->checkBox_rud->isChecked()?(4):(0);
qDebug() << "ch" << ch;
A = ui->doubleSpinBox_A_deg->value();
start = ui->doubleSpinBox__Start_frq_Hz->value();
stop = ui->doubleSpinBox_Stop_frq_Hz->value();
K = ui->doubleSpinBox_K_frq_Hz->value();
on_commandClicked(tr("设定 %1").arg(ui->pushButton_test_cmd->text()),
ch,A,start,stop,K,0,0,20008,0);
qDebug() << "Servo Test:" <<ch << A << start << stop << K;
}
void ServoSystem::on_pushButton_test_stop_clicked()
{
on_commandClicked(tr("设定 %1").arg(ui->pushButton_test_stop->text()),
0,0,0,0,0,0,0,20008,0);
}
void ServoSystem::on_pushButton_500W_Open_clicked()
{
on_commandClicked(tr("设定 %1").arg(ui->pushButton_500W_Open->text()),
102,1,0,0,0,0,0,180,0);
}
void ServoSystem::on_pushButton_500W_Close_clicked()
{
on_commandClicked(tr("设定 %1").arg(ui->pushButton_500W_Close->text()),
102,0,0,0,0,0,0,180,0);
}