|
@@ -20,13 +20,21 @@
|
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
+#include "remotectrl.pb.h"
|
|
|
+#include "platform_feedback.pb.h"
|
|
|
+
|
|
|
void * gpacansend;
|
|
|
void * gpadecition;
|
|
|
void * gpachassis;
|
|
|
+void * gparemote;
|
|
|
+void * gpaPaltformFeedback;
|
|
|
|
|
|
std::string gstrmemdecition;
|
|
|
std::string gstrmemcansend;
|
|
|
std::string gstrmemchassis;
|
|
|
+std::string gstrmemremote; //Remote Ctrl
|
|
|
+std::string gstrmemPaltformFeedback;
|
|
|
+
|
|
|
bool gbSendRun = true;
|
|
|
|
|
|
bool gbChassisEPS = false;
|
|
@@ -34,6 +42,15 @@ bool gbChassisEPS = false;
|
|
|
iv::brain::decition gdecition_def;
|
|
|
iv::brain::decition gdecition;
|
|
|
|
|
|
+bool gbAllowRemote = false; //Default, Not Allow Remote
|
|
|
+
|
|
|
+bool gbAutoDriving = true; //if true, Auto Driving, false, remote controll
|
|
|
+
|
|
|
+iv::brain::decition gdecition_remote;
|
|
|
+iv::platformFeedback gPlatformFeedback;
|
|
|
+
|
|
|
+qint64 gLastRemoteTime = 0;
|
|
|
+
|
|
|
QTime gTime;
|
|
|
int gnLastSendTime = 0;
|
|
|
int gnLastRecvDecTime = -1000;
|
|
@@ -43,7 +60,6 @@ int gnIndex = 0;
|
|
|
|
|
|
boost::shared_ptr<iv::control::Controller> gcontroller; //实际车辆控制器
|
|
|
|
|
|
-
|
|
|
static QMutex gMutex;
|
|
|
//void executeDecition(const iv::decition::Decition decition)
|
|
|
//{
|
|
@@ -134,17 +150,89 @@ void executeDecition(const iv::brain::decition decition)
|
|
|
|
|
|
//qDebug("door is %d",decition.door());
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
gcontroller->cmd_checksum(0x10);
|
|
|
gcontroller->cmd_checksum(0x11);
|
|
|
gcontroller->cmd_checksum(0x12);
|
|
|
|
|
|
+ switch (decition.gear()) {
|
|
|
+ case 0:
|
|
|
+ gPlatformFeedback.set_shift(3); //0N 1D 2R 3P
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ gPlatformFeedback.set_shift(1); //0N 1D 2R 3P
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ gPlatformFeedback.set_shift(2); //0N 1D 2R 3P
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ gPlatformFeedback.set_shift(0); //0N 1D 2R 3P
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ gPlatformFeedback.set_throttle(decition.torque());
|
|
|
+ gPlatformFeedback.set_brake(decition.brake());
|
|
|
+ gPlatformFeedback.set_steeringwheelangle(decition.wheelangle());
|
|
|
+
|
|
|
// qDebug("dangwei is %d mode is %d",decition.gear(),decition.mode());
|
|
|
}
|
|
|
|
|
|
+void ListenRemotectrl(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+// qint64 oldtime;
|
|
|
+ iv::brain::decition xdecition;
|
|
|
+
|
|
|
+ iv::remotectrl xrc;
|
|
|
+
|
|
|
+ if(!xrc.ParseFromArray(strdata,nSize))
|
|
|
+ {
|
|
|
+ std::cout<<"ListenRemotectrl parse error."<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(xrc.ntype() == iv::remotectrl_CtrlType_AUTO)
|
|
|
+ {
|
|
|
+ gbAutoDriving = true;
|
|
|
+ gPlatformFeedback.set_typefeedback(iv::platformFeedback::ctrlType::platformFeedback_ctrlType_AUTO);
|
|
|
+ }
|
|
|
+ else if(xrc.ntype() == iv::remotectrl_CtrlType_STOP)
|
|
|
+ {
|
|
|
+ gbAutoDriving = false;
|
|
|
+ gPlatformFeedback.set_typefeedback(iv::platformFeedback::ctrlType::platformFeedback_ctrlType_STOP);
|
|
|
+ xdecition.set_torque(0.0);
|
|
|
+ xdecition.set_brake(100.0);
|
|
|
+ xdecition.set_wheelangle(0.0);
|
|
|
+ xdecition.set_gear(1); //0P 1D 2R 3N
|
|
|
+ xdecition.set_handbrake(0);
|
|
|
+ xdecition.set_mode(1);
|
|
|
+ gMutex.lock();
|
|
|
+ gdecition_remote.CopyFrom(xdecition);
|
|
|
+ gMutex.unlock();
|
|
|
+ gLastRemoteTime = QDateTime::currentMSecsSinceEpoch();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ gbAutoDriving = false;
|
|
|
+ gPlatformFeedback.set_typefeedback(iv::platformFeedback::ctrlType::platformFeedback_ctrlType_REMOTE);
|
|
|
+ xdecition.set_torque(xrc.acc());
|
|
|
+ xdecition.set_brake(xrc.brake());
|
|
|
+ xdecition.set_wheelangle(xrc.wheel()*5.5f);
|
|
|
+ if(xrc.shift() > 0) //D shift
|
|
|
+ xdecition.set_gear(1); //0P 1D 2R 3N
|
|
|
+ else if(xrc.shift() < 0)
|
|
|
+ xdecition.set_gear(2);
|
|
|
+ else
|
|
|
+ xdecition.set_gear(3);
|
|
|
+ xdecition.set_handbrake(0);
|
|
|
+ xdecition.set_mode(1);
|
|
|
+ gMutex.lock();
|
|
|
+ gdecition_remote.CopyFrom(xdecition);
|
|
|
+ gMutex.unlock();
|
|
|
+ gLastRemoteTime = QDateTime::currentMSecsSinceEpoch();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
void UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
|
|
|
{
|
|
|
iv::chassis xchassis;
|
|
@@ -163,7 +251,6 @@ void UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
void ListenDeciton(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
{
|
|
|
qint64 oldtime;
|
|
@@ -245,6 +332,16 @@ void ExecSend()
|
|
|
{
|
|
|
std::cout<<"MainWindow::onTimer serialize error."<<std::endl;
|
|
|
}
|
|
|
+
|
|
|
+ int ndatasize_pf = gPlatformFeedback.ByteSize();
|
|
|
+ char * str_pf = new char[ndatasize_pf];
|
|
|
+ std::shared_ptr<char> pstr;pstr.reset(str_pf);
|
|
|
+ if(!gPlatformFeedback.SerializeToArray(str_pf,ndatasize_pf))
|
|
|
+ {
|
|
|
+ std::cout<<"MainWindow::on_horizontalSlider_valueChanged serialize error."<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ iv::modulecomm::ModuleSendMsg(gpaPaltformFeedback,str_pf,ndatasize_pf);
|
|
|
}
|
|
|
|
|
|
void initial()
|
|
@@ -265,16 +362,32 @@ void sendthread()
|
|
|
iv::brain::decition xdecition;
|
|
|
while(gbSendRun)
|
|
|
{
|
|
|
- if(gnDecitionNum <= 0)
|
|
|
+ if(gbAutoDriving)
|
|
|
{
|
|
|
- xdecition.CopyFrom(gdecition_def);
|
|
|
+ if(gnDecitionNum <= 0)
|
|
|
+ {
|
|
|
+ xdecition.CopyFrom(gdecition_def);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ gMutex.lock();
|
|
|
+ xdecition.CopyFrom(gdecition);
|
|
|
+ gMutex.unlock();
|
|
|
+ gnDecitionNum--;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- gMutex.lock();
|
|
|
- xdecition.CopyFrom(gdecition);
|
|
|
- gMutex.unlock();
|
|
|
- gnDecitionNum--;
|
|
|
+ if((QDateTime::currentMSecsSinceEpoch() - gLastRemoteTime)> 1000)
|
|
|
+ {
|
|
|
+ xdecition.CopyFrom(gdecition_def);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ gMutex.lock();
|
|
|
+ xdecition.CopyFrom(gdecition_remote);
|
|
|
+ gMutex.unlock();
|
|
|
+ }
|
|
|
}
|
|
|
executeDecition(xdecition);
|
|
|
if(gbChassisEPS == false) ExecSend();
|
|
@@ -317,10 +430,22 @@ int main(int argc, char *argv[])
|
|
|
gstrmemcansend = xp.GetParam("cansend","cansend0");
|
|
|
gstrmemdecition = xp.GetParam("dection","deciton");
|
|
|
gstrmemchassis = xp.GetParam("chassismsgname","chassis");
|
|
|
+ gstrmemremote = xp.GetParam("remotectrl","remotectrl");
|
|
|
+ gstrmemPaltformFeedback = xp.GetParam("paltformFeedback","platformFeedback");
|
|
|
+ std::string strremote = xp.GetParam("allowremote","true");
|
|
|
+ if(strremote == "true")
|
|
|
+ {
|
|
|
+ gbAllowRemote = true;
|
|
|
+ }
|
|
|
|
|
|
gpacansend = iv::modulecomm::RegisterSend(gstrmemcansend.data(),10000,1);
|
|
|
gpadecition = iv::modulecomm::RegisterRecv(gstrmemdecition.data(),ListenDeciton);
|
|
|
gpachassis = iv::modulecomm::RegisterRecv(gstrmemchassis.data(),UpdateChassis);
|
|
|
+ if(gbAllowRemote)
|
|
|
+ {
|
|
|
+ gpaPaltformFeedback = iv::modulecomm::RegisterSend(gstrmemPaltformFeedback.data(),10000,1);
|
|
|
+ gparemote = iv::modulecomm::RegisterRecv(gstrmemremote.data(),ListenRemotectrl);
|
|
|
+ }
|
|
|
|
|
|
#ifdef TORQUEBRAKETEST
|
|
|
EnableTorqueBrakeTest();
|