navigation.cpp 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668
  1. //
  2. // Created by zx on 22-12-2.
  3. //
  4. #include "navigation.h"
  5. #include "loaded_mpc.h"
  6. #include "rotate_mpc.h"
  7. #include "../define/TimerRecord.h"
  8. Navigation::~Navigation() {
  9. exit_ = true;
  10. if (terminator_)
  11. delete terminator_;
  12. if (brotherEmqx_)
  13. delete brotherEmqx_;
  14. if (monitor_)
  15. delete monitor_;
  16. if (pubthread_ != nullptr) {
  17. if (pubthread_->joinable())
  18. pubthread_->join();
  19. delete pubthread_;
  20. }
  21. }
  22. /*
  23. * 高斯函数压缩,x=3
  24. */
  25. double limit_gause(double x, double min, double max) {
  26. double r = x >= 0 ? 1.0 : -1.0;
  27. double delta = max / 1.0;
  28. return (max - (max - min) * exp(-x * x / (delta * delta))) * r;
  29. }
  30. double limit(double x, double min, double max) {
  31. double ret = x;
  32. if (x >= 0) {
  33. if (x > max) ret = max;
  34. if (x < min) ret = min;
  35. } else {
  36. if (x < -max) ret = -max;
  37. if (x > -min) ret = -min;
  38. }
  39. return ret;
  40. }
  41. double next_speed(double speed, double target_speed, double acc, double dt) {
  42. if (fabs(target_speed - speed) / dt < acc) {
  43. return target_speed;
  44. } else {
  45. double r = target_speed - speed >= 0. ? 1.0 : -1.0;
  46. return speed + r * acc * dt;
  47. }
  48. }
  49. bool Navigation::PoseTimeout() {
  50. // if (timedPose_.timeout() == false && timedBrotherPose_.timeout() == false) {
  51. if (timedPose_.timeout() == false) {
  52. return false;
  53. } else {
  54. if (timedPose_.timeout()) {
  55. printf(" current pose is timeout \n");
  56. }
  57. // if (timedBrotherPose_.timeout()) {
  58. // printf(" brother pose is timeout \n");
  59. // }
  60. return true;
  61. }
  62. }
  63. bool Navigation::Init(const NavParameter::Navigation_parameter &parameter) {
  64. parameter_ = parameter;
  65. NavParameter::AgvEmqx_parameter agv_p = parameter.agv_emqx();
  66. if (monitor_ == nullptr) {
  67. monitor_ = new Monitor_emqx(agv_p.nodeid());
  68. if (monitor_->Connect(agv_p.ip(), agv_p.port()) == false) {
  69. printf(" agv emqx connected failed\n");
  70. return false;
  71. }
  72. monitor_->set_speedcmd_topic(agv_p.pubspeedtopic());
  73. monitor_->AddCallback(agv_p.subposetopic(), Navigation::RobotPoseCallback, this);
  74. monitor_->AddCallback(agv_p.subspeedtopic(), Navigation::RobotSpeedCallback, this);
  75. }
  76. NavParameter::Emqx_parameter terminal_p = parameter.terminal_emqx();
  77. if (terminator_ == nullptr) {
  78. terminator_ = new Terminator_emqx(terminal_p.nodeid());
  79. if (terminator_->Connect(terminal_p.ip(), terminal_p.port()) == false) {
  80. printf(" terminator emqx connected failed\n");
  81. return false;
  82. }
  83. }
  84. if (parameter.has_brother_emqx()) {
  85. NavParameter::BrotherEmqx brotherEmqx = parameter.brother_emqx();
  86. if (brotherEmqx_ == nullptr) {
  87. brotherEmqx_ = new Terminator_emqx(brotherEmqx.nodeid());
  88. if (brotherEmqx_->Connect(brotherEmqx.ip(), brotherEmqx.port()) == true) {
  89. brotherEmqx_->AddCallback(brotherEmqx.subbrotherstatutopic(), Navigation::BrotherAgvStatuCallback,
  90. this);
  91. } else {
  92. printf(" brother emqx connected failed\n");
  93. // return false;
  94. }
  95. //
  96. }
  97. }
  98. inited_ = true;
  99. if (pubthread_ != nullptr) {
  100. exit_ = true;
  101. if (pubthread_->joinable())
  102. pubthread_->join();
  103. delete pubthread_;
  104. }
  105. exit_ = false;
  106. pubthread_ = new std::thread(&Navigation::pubStatuThreadFuc, this);
  107. return true;
  108. }
  109. void Navigation::RobotPoseCallback(const MqttMsg &msg, void *context) {
  110. Navigation *navigator = (Navigation *) context;
  111. NavMessage::LidarOdomStatu statu;
  112. if (msg.toProtoMessage(statu)) {
  113. navigator->ResetPose(Pose2d(statu.x(), statu.y(), statu.theta()));
  114. }
  115. }
  116. void Navigation::HandleAgvStatu(const MqttMsg &msg) {
  117. NavMessage::AgvStatu speed;
  118. if (msg.toProtoMessage(speed)) {
  119. ResetStatu(speed.v(), speed.w());
  120. ResetClamp((ClampStatu) speed.clamp());
  121. ResetLifter((LifterStatus) speed.lifter());
  122. }
  123. }
  124. void Navigation::RobotSpeedCallback(const MqttMsg &msg, void *context) {
  125. Navigation *navigator = (Navigation *) context;
  126. navigator->HandleAgvStatu(msg);
  127. }
  128. void Navigation::pubStatuThreadFuc(void *p) {
  129. Navigation *navogator = (Navigation *) p;
  130. if (navogator) {
  131. while (navogator->exit_ == false) {
  132. std::this_thread::sleep_for(std::chrono::milliseconds(50));
  133. NavMessage::NavStatu statu;
  134. statu.set_main_agv(false);
  135. navogator->publish_statu(statu);
  136. }
  137. }
  138. }
  139. void Navigation::publish_statu(NavMessage::NavStatu &statu) {
  140. if (timedPose_.timeout() == false) {
  141. NavMessage::LidarOdomStatu odom;
  142. odom.set_x(timedPose_.Get().x());
  143. odom.set_y(timedPose_.Get().y());
  144. odom.set_theta(timedPose_.Get().theta());
  145. if (timedV_.timeout() == false)
  146. odom.set_v(timedV_.Get());
  147. if (timedA_.timeout() == false)
  148. odom.set_vth(timedA_.Get());
  149. statu.mutable_odom()->CopyFrom(odom);
  150. }
  151. statu.set_in_space(isInSpace_);
  152. if (isInSpace_) statu.set_space_id(space_id_);
  153. //发布nav状态
  154. statu.set_statu(actionType_); //
  155. statu.set_move_mode(move_mode_);
  156. if (running_) {
  157. statu.set_key(global_navCmd_.key());
  158. }
  159. //发布MPC信息
  160. //发布mpc 预选点
  161. if (selected_traj_.timeout() == false) {
  162. for (int i = 0; i < selected_traj_.Get().size(); ++i) {
  163. Pose2d pt = selected_traj_.Get()[i];
  164. NavMessage::Pose2d *pose = statu.mutable_selected_traj()->add_poses();
  165. pose->set_x(pt.x());
  166. pose->set_y(pt.y());
  167. pose->set_theta(pt.theta());
  168. }
  169. }
  170. //发布 mpc 预测点
  171. if (predict_traj_.timeout() == false) {
  172. for (int i = 0; i < predict_traj_.Get().size(); ++i) {
  173. Pose2d pt = predict_traj_.Get()[i];
  174. NavMessage::Pose2d *pose = statu.mutable_predict_traj()->add_poses();
  175. pose->set_x(pt.x());
  176. pose->set_y(pt.y());
  177. pose->set_theta(pt.theta());
  178. }
  179. }
  180. // std::cout<<"nav statu:"<<statu.DebugString()<<std::endl;
  181. MqttMsg msg;
  182. msg.fromProtoMessage(statu);
  183. if (terminator_)
  184. terminator_->Publish(parameter_.terminal_emqx().pubnavstatutopic(), msg);
  185. //发布位姿 ------robot状态--------------------------
  186. NavMessage::RobotStatu robot;
  187. if (CreateRobotStatuMsg(robot)) {
  188. if (terminator_) {
  189. MqttMsg msg;
  190. msg.fromProtoMessage(robot);
  191. terminator_->Publish(parameter_.terminal_emqx().pubstatutopic(), msg);
  192. }
  193. }
  194. }
  195. bool Navigation::CreateRobotStatuMsg(NavMessage::RobotStatu &robotStatu) {
  196. //printf(" %d %d %d \n",timedPose_.timeout(),timedV_.timeout(),timedA_.timeout());
  197. if (timedPose_.timeout() == false) {
  198. Pose2d pose = timedPose_.Get();
  199. robotStatu.set_x(pose.x());
  200. robotStatu.set_y(pose.y());
  201. robotStatu.set_theta(pose.theta());
  202. if ((timedV_.timeout() == false && timedA_.timeout() == false)) {
  203. NavMessage::AgvStatu plc;
  204. plc.set_v(timedV_.Get());
  205. plc.set_w(timedA_.Get());
  206. plc.set_clamp(timed_clamp_.Get());
  207. plc.set_lifter(timed_lifter_.Get());
  208. //printf(" timed_clamp_:%d\n ",timed_clamp_.Get());
  209. robotStatu.mutable_agvstatu()->CopyFrom(plc);
  210. }
  211. return true;
  212. }
  213. return false;
  214. }
  215. void Navigation::ResetStatu(double v, double a) {
  216. timedV_.reset(v, 0.5);
  217. timedA_.reset(a, 0.5);
  218. }
  219. void Navigation::ResetClamp(ClampStatu statu) {
  220. timed_clamp_.reset(statu, 1);
  221. }
  222. void Navigation::ResetLifter(LifterStatus status) {
  223. timed_lifter_.reset(status, 1);
  224. }
  225. void Navigation::ResetPose(const Pose2d &pose) {
  226. timedPose_.reset(pose, 1.0);
  227. if(pose.theta()>0){
  228. if(parameter_.main_agv()){
  229. isFront_.reset(true,1.0);
  230. }else{
  231. isFront_.reset(false,1.0);
  232. }
  233. }else{
  234. if(parameter_.main_agv()){
  235. isFront_.reset(false,1.0);
  236. }else{
  237. isFront_.reset(true,1.0);
  238. }
  239. }
  240. }
  241. void Navigation::Cancel(const NavMessage::NavCmd &cmd, NavMessage::NavResponse &response) {
  242. cancel_ = true;
  243. response.set_ret(0);
  244. }
  245. bool Navigation::Stop() {
  246. if (monitor_) {
  247. monitor_->stop();
  248. while (cancel_ == false) {
  249. if (timedV_.timeout() == false && timedA_.timeout() == false) {
  250. if (fabs(timedV_.Get()) < 1e-2 && fabs(timedA_.Get()) < 1e-3)
  251. return true;
  252. else
  253. monitor_->stop();
  254. printf("Stoped wait V/A ==0(1e-4,1e-4),V:%f,A:%f\n", fabs(timedV_.Get()), fabs(timedA_.Get()));
  255. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  256. } else {
  257. printf("Stop failed V/A timeout\n");
  258. return false;
  259. }
  260. }
  261. }
  262. printf("stoped ret false.\n");
  263. return false;
  264. }
  265. bool Navigation::SlowlyStop() {
  266. double acc = 3.0;
  267. double dt = 0.1;
  268. while (cancel_ == false) {
  269. if (timedV_.timeout() == false) {
  270. double v = timedV_.Get();
  271. if (fabs(v < 1e-2 && fabs(timedA_.Get()) < 1e-3))
  272. return true;
  273. if (v > 0) {
  274. double new_v = v - acc * dt;
  275. new_v = new_v > 0 ? new_v : 0;
  276. SendMoveCmd(move_mode_, actionType_, new_v, 0);
  277. } else {
  278. double new_v = v + acc * dt;
  279. new_v = new_v < 0 ? new_v : 0;
  280. SendMoveCmd(move_mode_, actionType_, new_v, 0);
  281. }
  282. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  283. } else {
  284. printf("Stop failed V/A timeout\n");
  285. return false;
  286. }
  287. }
  288. printf("stoped ret false.\n");
  289. return false;
  290. }
  291. Navigation::Navigation() {
  292. isInSpace_ = false; //是否在车位或者正在进入车位
  293. RWheel_position_ = eUnknow;
  294. move_mode_ = eSingle;
  295. monitor_ = nullptr;
  296. terminator_ = nullptr;
  297. obs_h_=4.0;
  298. obs_w_=2.0;
  299. timedBrotherPose_.reset(Pose2d(-100, 0, 0), 0.5);
  300. }
  301. void Navigation::BrotherAgvStatuCallback(const MqttMsg &msg, void *context) {
  302. Navigation *navigator = (Navigation *) context;
  303. NavMessage::NavStatu brother_statu;
  304. if (msg.toProtoMessage(brother_statu) == false) {
  305. std::cout << " msg transform to AGVStatu failed,msg:" << msg.data() << std::endl;
  306. return;
  307. }
  308. //std::cout<<brother_nav.DebugString()<<std::endl<<std::endl;
  309. if (brother_statu.has_odom()) {
  310. NavMessage::LidarOdomStatu odom = brother_statu.odom();
  311. Pose2d pose(odom.x(), odom.y(), odom.theta());
  312. navigator->timedBrotherPose_.reset(pose, 1);
  313. navigator->timedBrotherV_.reset(odom.v(), 1);
  314. navigator->timedBrotherA_.reset(odom.vth(), 1);
  315. navigator->timedBrotherNavStatu_.reset(brother_statu, 0.1);
  316. }
  317. }
  318. //未使用
  319. bool Navigation::RotateReferToTarget(const Pose2d &target, stLimit limit_rotate, bool anyDirect) {
  320. while (cancel_ == false) {
  321. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  322. if (timedPose_.timeout()) {
  323. printf(" RotateBytarget failed pose timeout\n");
  324. return false;
  325. }
  326. if (timedA_.timeout()) {
  327. printf(" RotateBytarget failed wmg timeout\n");
  328. return false;
  329. }
  330. Pose2d targetInPose = Pose2d::relativePose(target, timedPose_.Get());
  331. float yawDiff = Pose2d::vector2yaw(targetInPose.x(), targetInPose.y());
  332. float minYawdiff = yawDiff;
  333. if (anyDirect) {
  334. Pose2d p0 = timedPose_.Get();
  335. float yawdiff[4] = {0};
  336. yawdiff[0] = yawDiff;
  337. Pose2d relativePose;
  338. relativePose = Pose2d::relativePose(target, p0 - Pose2d(0, 0, M_PI / 2));
  339. yawdiff[1] = Pose2d::vector2yaw(relativePose.x(), relativePose.y()); ////使用减法,保证角度在【-pi pi】
  340. relativePose = Pose2d::relativePose(target, p0 - Pose2d(0, 0, M_PI));
  341. yawdiff[2] = Pose2d::vector2yaw(relativePose.x(), relativePose.y());
  342. relativePose = Pose2d::relativePose(target, p0 - Pose2d(0, 0, 3 * M_PI / 2));
  343. yawdiff[3] = Pose2d::vector2yaw(relativePose.x(), relativePose.y());
  344. for (int i = 1; i < 4; ++i) {
  345. if (fabs(yawdiff[i]) < fabs(minYawdiff)) {
  346. minYawdiff = yawdiff[i];
  347. targetInPose = Pose2d::relativePose(target, p0 - Pose2d(0, 0, i * M_PI / 2.0));
  348. }
  349. }
  350. }
  351. //std::cout<<" Rotate refer to target:"<<target<<",targetInPose:"
  352. //<<targetInPose<<",anyDirect:"<<anyDirect<<std::endl;
  353. //以当前点为原点,想方向经过目标点的二次曲线曲率>0.25,则需要调整 y=a x*x
  354. float cuv = compute_cuv(targetInPose);
  355. float dt = 0.1;
  356. float acc_angular = 15 * M_PI / 180.0;
  357. if (cuv > 2 * M_PI / 180.0) {
  358. double theta = limit_gause(minYawdiff, limit_rotate.min, limit_rotate.max);
  359. double angular = next_speed(timedA_.Get(), theta, acc_angular, dt);
  360. double limit_angular = limit(angular, limit_rotate.min, limit_rotate.max);
  361. SendMoveCmd(move_mode_, eRotation, 0, limit_angular);
  362. actionType_ = eRotation;
  363. printf(" Rotate | input angular:%f,next angular:%f,down:%f diff:%f anyDirect:%d\n",
  364. timedA_.Get(), angular, limit_angular, minYawdiff, anyDirect);
  365. continue;
  366. } else {
  367. if (fabs(timedA_.Get()) < 5 * M_PI / 180.0) {
  368. printf(" Rotate refer target completed,cuv:%f\n", cuv);
  369. return true;
  370. }
  371. continue;
  372. }
  373. }
  374. return false;
  375. }
  376. Navigation::MpcResult Navigation::RotateReferToTarget(NavMessage::PathNode node, stLimit limit_rotate, int directions) {
  377. if (inited_ == false) {
  378. printf(" MPC_rotate has not inited\n");
  379. return eMpcFailed;
  380. }
  381. if (PoseTimeout()) {
  382. printf(" MPC_rotate Error:Pose is timeout \n");
  383. return eMpcFailed;
  384. }
  385. printf(" exec MPC_rotate autoDirect:%d\n", directions);
  386. while (cancel_ == false) {
  387. std::this_thread::sleep_for(std::chrono::milliseconds(30));
  388. if (pause_ == true) {
  389. //发送暂停消息
  390. continue;
  391. }
  392. if (PoseTimeout()) {
  393. printf(" MPC_rotate Error:Pose is timeout \n");
  394. return eMpcFailed;
  395. }
  396. if (timedA_.timeout()) {
  397. printf(" MPC_rotate Error:v/a is timeout \n");
  398. return eMpcFailed;
  399. }
  400. Pose2d current = timedPose_.Get();
  401. Pose2d target(node.x(), node.y(), node.theta());
  402. Pose2d targetInPose = Pose2d::relativePose(target, current);
  403. // 需要旋转的角度
  404. float target_yaw_diff = Pose2d::vector2yaw(targetInPose.x(), targetInPose.y());
  405. // 自由方向
  406. if (directions) {
  407. std::vector<double> yaw_diffs;
  408. if (directions & Direction::eForward) {
  409. yaw_diffs.push_back(target_yaw_diff);
  410. }
  411. if (directions & Direction::eBackward) {
  412. Pose2d relative_pose = Pose2d::relativePose(targetInPose, Pose2d(0, 0, M_PI));
  413. yaw_diffs.push_back(Pose2d::vector2yaw(relative_pose.x(), relative_pose.y()));
  414. }
  415. if (directions & Direction::eLeft) {
  416. Pose2d relative_pose = Pose2d::relativePose(targetInPose, Pose2d(0, 0, 1.0 / 2 * M_PI));
  417. yaw_diffs.push_back(Pose2d::vector2yaw(relative_pose.x(), relative_pose.y()));
  418. }
  419. if (directions & Direction::eRight) {
  420. Pose2d relative_pose = Pose2d::relativePose(targetInPose, Pose2d(0, 0, 3.0 / 2 * M_PI));
  421. yaw_diffs.push_back(Pose2d::vector2yaw(relative_pose.x(), relative_pose.y()));
  422. }
  423. for (auto i = 0; i < yaw_diffs.size(); ++i) {
  424. if (fabs(yaw_diffs[i]) < fabs(target_yaw_diff))
  425. target_yaw_diff = yaw_diffs[i];
  426. }
  427. // std::cout << std::endl;
  428. // std::cout << std::endl << " min_diff: " << current_to_target.theta() << std::endl;
  429. }
  430. //一次变速
  431. std::vector<double> out;
  432. bool ret;
  433. TimerRecord::Execute([&, this]() {
  434. ret = Rotation_mpc_once(Pose2d(0, 0, target_yaw_diff), limit_rotate, out);
  435. }, "Rotation_mpc_once");
  436. if (ret == false) {
  437. Stop();
  438. return eMpcFailed;
  439. }
  440. //下发速度
  441. if (fabs(target_yaw_diff) < 0.2 * M_PI / 180.0 && fabs(timedA_.Get()) < 5 * M_PI / 180.0) {
  442. printf(" MPC_rotate | refer target completed\\n,cuv:%f\n", target_yaw_diff);
  443. Stop();
  444. return eMpcSuccess;
  445. } else{
  446. const int down_count = 3;
  447. double v[down_count] = {0,0,0};
  448. double w[down_count] = {out[0], out[1], out[2]};
  449. // if(out[0]>=0){
  450. // w[0]=1.*M_PI/180.0;
  451. // w[1]=1.*M_PI/180.0;
  452. // w[2]=1.*M_PI/180.0;
  453. // }else{
  454. // w[0]=-1.*M_PI/180.0;
  455. // w[1]=-1.*M_PI/180.0;
  456. // w[2]=-1.*M_PI/180.0;
  457. // }
  458. SendMoveCmd(move_mode_, eRotation, v, w);
  459. actionType_ = eRotation;
  460. double input_w = timedA_.Get();
  461. for (int i = 0; i < down_count; ++i) {
  462. printf(" MPC_rotate |P[%d], input anguar:%f, down:%f(%f), diff:%f anyDirect:%d\n",
  463. i, input_w, w[i], w[i]/M_PI*180, target_yaw_diff, directions);
  464. }
  465. }
  466. continue;
  467. // //下发速度
  468. // if (fabs(target_yaw_diff) > 2 * M_PI / 180.0) {
  469. // SendMoveCmd(move_mode_, eRotation, 0, out[0]);
  470. // actionType_ = eRotation;
  471. // printf(" MPC_rotate | input angular_v:%f, down:%f, diff:%f autoDirect:%d\n",
  472. // timedA_.Get(), out[0], target_yaw_diff, directions);
  473. // } else if (fabs(timedA_.Get()) < 5 * M_PI / 180.0) {
  474. // printf(" MPC_rotate refer target completed,cuv:%f\n", target_yaw_diff);
  475. // return eMpcSuccess;
  476. // }
  477. // continue;
  478. }
  479. return eMpcFailed;
  480. }
  481. bool Navigation::MoveToTarget(NavMessage::PathNode node, Navigation::stLimit limit_v, Navigation::stLimit limit_w,
  482. bool anyDirect, bool enable_rotate) {
  483. // LogWriter("MoveToTarget beg");
  484. if (IsArrived(node)) {
  485. return true;
  486. }
  487. bool already_in_mpc = false;
  488. while (cancel_ == false) {
  489. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  490. if (PoseTimeout()) {
  491. printf(" navigation Error:Pose is timeout \n");
  492. break;
  493. }
  494. Pose2d current = timedPose_.Get();
  495. if (IsArrived(node)) {
  496. break;
  497. }
  498. //两个方向都无法到达目标点,旋转 朝向目标点
  499. bool x_enable = PossibleToTarget(node, false);
  500. bool y_enable = PossibleToTarget(node, true);
  501. bool enableTotarget = x_enable || y_enable;
  502. if (anyDirect == false) {
  503. enableTotarget = x_enable;
  504. }
  505. //巡线无法到达目标点
  506. if (enableTotarget == false) {
  507. if (already_in_mpc && enable_rotate == false) {
  508. printf(" Move to node failed ,impossible to target and rotate is not enabled\n");
  509. return false;
  510. }
  511. Pose2d target(node.x(), node.y(), 0);
  512. // if (RotateReferToTarget(target, limit_w, anyDirect) == false) {
  513. int directions = Direction::eForward;
  514. if (anyDirect)
  515. directions = Direction::eForward | Direction::eBackward |
  516. Direction::eLeft | Direction::eRight;
  517. if (RotateReferToTarget(node, limit_w, directions) != eMpcSuccess) {
  518. std::cout << " Rotate refer to target failed,target: " << target <<
  519. " directions: " << std::hex << directions << " line_: " << __LINE__ << std::endl;
  520. return false;
  521. }
  522. continue;
  523. }
  524. already_in_mpc = true;
  525. MpcResult ret = MpcToTarget(node, limit_v, anyDirect);
  526. if (ret == eMpcSuccess) {
  527. printf(" MPC to target:%f %f l:%f,w:%f theta:%f completed\n",
  528. node.x(), node.y(), node.l(), node.w(), node.theta());
  529. break;
  530. } else if (ret == eImpossibleToTarget) {
  531. printf(" MPC to target:%f %f l:%f,w:%f theta:%f impossible ,retry ...\n",
  532. node.x(), node.y(), node.l(), node.w(), node.theta());
  533. } else {
  534. return false;
  535. }
  536. }
  537. if (cancel_) {
  538. return false;
  539. }
  540. return true;
  541. }
  542. bool Navigation::execute_nodes(NavMessage::NewAction action) {
  543. if (action.type() == 3 || action.type() == 4) //最优动作导航 or 导航中保证朝向严格一致
  544. {
  545. if (!parameter_.has_nodeangularlimit() || !parameter_.has_nodevelocitylimit() || action.pathnodes_size() == 0) {
  546. std::cout << "execute pathNodes failed ,Action invalid:" << action.DebugString() << std::endl;
  547. return false;
  548. }
  549. bool anyDirect = (action.type() == 3);
  550. //速度限制
  551. stLimit wmg_limit = {parameter_.nodeangularlimit().min(), parameter_.nodeangularlimit().max()};
  552. stLimit mpc_velocity = {parameter_.nodevelocitylimit().min(), parameter_.nodevelocitylimit().max()};
  553. for (int i = 0; i < action.pathnodes_size(); ++i) {
  554. NavMessage::PathNode node = action.pathnodes(i);
  555. if (i + 1 < action.pathnodes_size()) {
  556. NavMessage::PathNode next = action.pathnodes(i + 1);
  557. Pose2d vec(next.x() - node.x(), next.y() - node.y(), 0);
  558. node.set_theta(Pose2d::vector2yaw(vec.x(), vec.y()));
  559. node.set_l(0.05);
  560. node.set_w(0.10);
  561. } else {
  562. node.set_theta(0);
  563. node.set_l(0.03);
  564. node.set_w(0.10);
  565. }
  566. int directions = Direction::eForward;
  567. if (anyDirect)
  568. directions = Direction::eForward | Direction::eBackward |
  569. Direction::eLeft | Direction::eRight;
  570. if (i > 0){
  571. if (RotateReferToTarget(node, wmg_limit, directions) != eMpcSuccess){
  572. printf(" before move node RotateReferToNone Failed!!\n");
  573. return false;
  574. }
  575. }
  576. if (MoveToTarget(node, mpc_velocity, wmg_limit, anyDirect, true) == false)
  577. return false;
  578. else
  579. isInSpace_ = false;
  580. }
  581. return true;
  582. }
  583. printf("execute PathNode failed ,action type is not 3/4 :%d\n", action.type());
  584. return false;
  585. }
  586. Navigation::MpcResult Navigation::RotateAfterOutSpace(){
  587. if(move_mode_!=eDouble)
  588. return eMpcSuccess;
  589. Pose2d init = timedPose_.Get();
  590. double diff1=fabs(M_PI/2.0-init.theta());
  591. double diff2=fabs(-M_PI/2.0-init.theta());
  592. double target= diff1<diff2?M_PI/2.0:-M_PI/2.0;
  593. stLimit limit_rotate = {3 * M_PI / 180.0, 15 * M_PI / 180.0};
  594. while (cancel_ == false) {
  595. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  596. Pose2d current = timedPose_.Get();
  597. double yawDiff = (target - current.theta());
  598. //一次变速
  599. std::vector<double> out;
  600. bool ret;
  601. TimerRecord::Execute([&, this]() {
  602. ret = Rotation_mpc_once(Pose2d(0, 0, yawDiff), limit_rotate, out);
  603. }, "Rotation_mpc_once");
  604. if (ret == false) {
  605. Stop();
  606. return eMpcFailed;
  607. }
  608. //下发速度
  609. if (fabs(yawDiff) < 0.3 * M_PI / 180.0 && fabs(timedA_.Get()) < 5 * M_PI / 180.0) {
  610. printf(" RotateBeforeEnterSpace refer target completed\\n,cuv:%f\n", yawDiff);
  611. Stop();
  612. return eMpcSuccess;
  613. } else{
  614. const int down_count = 3;
  615. double v[down_count] = {0,0,0};
  616. double w[down_count] = {out[0], out[1], out[2]};
  617. SendMoveCmd(move_mode_, eRotation, v, w);
  618. actionType_ = eRotation;
  619. printf(" RotateBeforeEnterSpace | input anguar:%f, down:%f(%f), diff:%f anyDirect:false\n",
  620. timedA_.Get(), out[0], out[0]/M_PI*180, yawDiff);
  621. }
  622. continue;
  623. }
  624. return eMpcFailed;
  625. }
  626. Navigation::MpcResult
  627. Navigation::RotateBeforeEnterSpace(NavMessage::PathNode space,
  628. double wheelbase, NavMessage::PathNode &target) {
  629. // if (timedBrotherNavStatu_.timeout() || timedPose_.timeout()) {
  630. if (timedPose_.timeout()) {
  631. printf(" rotate failed : timedBrotherNavStatu_ or pose timeout\n");
  632. return eMpcFailed;
  633. }
  634. NavMessage::NavStatu brother = timedBrotherNavStatu_.Get();
  635. stLimit limit_rotate = {2 * M_PI / 180.0, 15 * M_PI / 180.0};
  636. double acc_angular = 20 * M_PI / 180.0;
  637. double dt = 0.1;
  638. Pose2d rotated = timedPose_.Get();
  639. double x = space.x();
  640. double y = space.y();
  641. Pose2d vec(x - rotated.x(), y - rotated.y(), 0);
  642. rotated.mutable_theta() = Pose2d::vector2yaw(vec.x(), vec.y());
  643. bool isFront=isFront_.Get();
  644. if(rotated.theta()>0.)
  645. isFront=!isFront;
  646. //前车先到,后车进入2点,保持与前车一致的朝向
  647. if (isFront==false ) {
  648. printf("后车 RotateBeforeEnterSpace | , __LINE__ = %d\n", __LINE__);
  649. if (move_mode_ == eSingle) {
  650. x -= wheelbase * cos(rotated.theta());
  651. y -= wheelbase * sin(rotated.theta());
  652. printf("确定车位点:eSingle\n");
  653. }
  654. } else { //当后车先到,倒车入库
  655. printf("前车RotateBeforeEnterSpace | __LINE__ = %d\n", __LINE__);
  656. rotated.mutable_theta() = space.theta();
  657. rotated = rotated.rotate(rotated.x(), rotated.y(), M_PI);
  658. }
  659. target.set_x(x);
  660. target.set_y(y);
  661. target.set_theta(rotated.theta());
  662. target.set_l(0.02);
  663. target.set_w(0.05);
  664. target.set_id(space.id());
  665. printf("RotateBeforeEnterSpace | target:[x:%f,y:%f,theta:%f]\n",x,y,target.theta());
  666. // //整车协调的时候,保持前后与车位一致即可
  667. // if (move_mode_ == eDouble) {
  668. // double yawDiff1 = (rotated - timedPose_.Get()).theta();
  669. // double yawDiff2 = (rotated + Pose2d(0, 0, M_PI) - timedPose_.Get()).theta();
  670. // if (fabs(yawDiff1) < fabs(yawDiff2)) {
  671. // rotated = rotated + Pose2d(0, 0, M_PI);
  672. // }
  673. // }
  674. while (cancel_ == false) {
  675. std::this_thread::sleep_for(std::chrono::milliseconds(30));
  676. Pose2d current = timedPose_.Get();
  677. double yawDiff = (rotated - current).theta();
  678. //一次变速
  679. std::vector<double> out;
  680. bool ret;
  681. TimerRecord::Execute([&, this]() {
  682. ret = Rotation_mpc_once(Pose2d(0, 0, yawDiff), limit_rotate, out);
  683. }, "Rotation_mpc_once");
  684. if (ret == false) {
  685. Stop();
  686. return eMpcFailed;
  687. }
  688. //下发速度
  689. if (fabs(yawDiff) < 0.3 * M_PI / 180.0 && fabs(timedA_.Get()) < 5 * M_PI / 180.0) {
  690. printf(" RotateBeforeEnterSpace refer target completed\\n,cuv:%f\n", yawDiff);
  691. Stop();
  692. return eMpcSuccess;
  693. } else{
  694. const int down_count = 3;
  695. double v[down_count] = {0,0,0};
  696. double w[down_count] = {out[0], out[1], out[2]};
  697. SendMoveCmd(move_mode_, eRotation, v, w);
  698. actionType_ = eRotation;
  699. printf(" RotateBeforeEnterSpace | input anguar:%f, down:%f(%f), diff:%f anyDirect:false\n",
  700. timedA_.Get(), out[0], out[0]/M_PI*180, yawDiff);
  701. }
  702. continue;
  703. }
  704. return eMpcFailed;
  705. }
  706. bool Navigation::execute_InOut_space(NavMessage::NewAction action) {
  707. // LogWriter("execute_InOut_space beg");
  708. if (action.type() != 1 && action.type() != 2) {
  709. printf(" Inout_space failed : msg action type must ==1\n ");
  710. return false;
  711. }
  712. if (!parameter_.has_inoutvlimit() || !action.has_spacenode() ||
  713. !action.has_streetnode()) {
  714. std::cout << "execute enter_space failed ,Action miss some infos:" << action.DebugString() << std::endl;
  715. return false;
  716. }
  717. if (PoseTimeout() == true) {
  718. printf(" inout_space failed type:%d : current pose is timeout\n", action.type());
  719. return false;
  720. }
  721. stLimit limit_v = {parameter_.inoutvlimit().min(), parameter_.inoutvlimit().max()};
  722. stLimit limit_w = {2 * M_PI / 180.0, 20 * M_PI / 180.0};
  723. //入库,起点为streetNode
  724. if (action.type() == 1) {
  725. // LogWriter("In space beg-");
  726. Pose2d vec(action.spacenode().x() - action.streetnode().x(), action.spacenode().y() - action.streetnode().y(),
  727. 0);
  728. action.mutable_streetnode()->set_l(0.05);
  729. action.mutable_streetnode()->set_w(0.05);
  730. action.mutable_streetnode()->set_theta(Pose2d::vector2yaw(vec.x(), vec.y()));
  731. /*
  732. * 是否需要添加判断,距离较远才先运动到马路点==============================?????????
  733. */
  734. if (MoveToTarget(action.streetnode(), limit_v, limit_w, true, true) == false) {
  735. printf(" Enter space failed type:%d: MoveTo StreetNode failed\n", action.type());
  736. return false;
  737. }
  738. //移动到库位点, 禁止任意方向// 不允许巡线中停下旋转(当无法到达目标点时,返回false)
  739. printf("inout ----------------------------------------\n");
  740. //计算车位朝向
  741. action.mutable_spacenode()->set_theta(Pose2d::vector2yaw(vec.x(), vec.y()));
  742. //计算当前车是进入车位1点还是2点
  743. NavMessage::PathNode new_target;
  744. if (RotateBeforeEnterSpace(action.spacenode(), action.wheelbase(), new_target) == eMpcFailed) {
  745. return false;
  746. }
  747. std::string id = action.spacenode().id().substr(1,action.spacenode().id().length()-1);
  748. int space_id = stoi(id);
  749. if (space_id>99 && space_id< 1000){
  750. //进载车板库前提升机构上升
  751. if (lifter_rise() == false){
  752. printf(" Enter space | lifter rise failed. line:%d\n",__LINE__);
  753. }
  754. }
  755. else{
  756. //否则下降
  757. if (lifter_down() == false){
  758. printf(" Enter space | lifter down failed. line:%d\n",__LINE__);
  759. }
  760. }
  761. if (space_id == 1101){
  762. //单车进入口搬车,夹持杆打开到全开位
  763. }
  764. //入库
  765. if(isFront_.Get()==false && move_mode_==eSingle){
  766. while(timedBrotherNavStatu_.Get().in_space()==false){
  767. if(cancel_){
  768. return false;
  769. }
  770. printf(" 后车 等待 前车先入库。。。\n");
  771. usleep(1000*500);
  772. continue;
  773. }
  774. }
  775. isInSpace_=true;
  776. printf("Enter space beg...\n");
  777. if (MoveToTarget(new_target, limit_v, limit_w, true, false) == false) {
  778. printf(" Enter space:%s failed. type:%d\n",action.spacenode().id().data(), action.type());
  779. return false;
  780. }
  781. } else if (action.type() == 2) {
  782. // LogWriter("Out space beg-");
  783. // 计算当前位置,在车位点到马路点的连线方向上,与车位点的相对位姿
  784. Pose2d vec(action.streetnode().x() - action.spacenode().x(),
  785. action.streetnode().y() - action.spacenode().y(), 0);
  786. float theta = Pose2d::vector2yaw(vec.x(), vec.y());
  787. Pose2d space(action.spacenode().x(), action.spacenode().y(), theta);
  788. Pose2d current = timedPose_.Get();
  789. Pose2d diff = Pose2d::abs(Pose2d::relativePose(Pose2d(current.x(),current.y(),0),space));
  790. if (diff.x() < 0.05 || diff.y() < 0.10) {
  791. //出库,移动到马路点,允许自由方向,不允许中途旋转
  792. action.mutable_streetnode()->set_theta(theta);
  793. action.mutable_streetnode()->set_l(0.04);
  794. action.mutable_streetnode()->set_w(0.06);
  795. std::cout << " Out space target street node:" << space << std::endl;
  796. if (MoveToTarget(action.streetnode(), limit_v, limit_w, true, false) == false) {
  797. printf(" out space failed type:%d: MoveTo StreetNode failed\n", action.type());
  798. return false;
  799. }
  800. //出库后提升机构下降
  801. if (lifter_down() == false){
  802. printf(" Out space | lifter down failed. line:%d\n",__LINE__);
  803. }
  804. // if(RotateAfterOutSpace()!=eMpcSuccess) {
  805. // printf(" after out space rotate Failed!!!\n");
  806. // return false;
  807. // }
  808. // LogWriter("Out space end-");
  809. } else {
  810. std::cout << " Out space failed: current pose too far from space node:" << space << ",diff:" << diff
  811. << std::endl;
  812. return false;
  813. }
  814. isInSpace_=false;
  815. }
  816. return true;
  817. }
  818. /* current_to_target: current_to_target.theta()为所需旋转的角度
  819. * */
  820. bool Navigation::Rotation_mpc_once(Pose2d current_to_target, Navigation::stLimit limit_wmg, std::vector<double> &out,
  821. bool all_direct) {
  822. if (PoseTimeout() == true) {
  823. printf(" Rotation_mpc_once Error:Pose is timeout \n");
  824. return false;
  825. }
  826. if (timedV_.timeout() == true || timedA_.timeout() == true) {
  827. printf(" Rotation_mpc_once Error:V/A is timeout \n");
  828. return false;
  829. }
  830. Pose2d pose = timedPose_.Get();
  831. double line_velocity = timedV_.Get(); //从plc获取状态
  832. double angular_velocity = timedA_.Get();
  833. Eigen::VectorXd statu = Eigen::VectorXd::Zero(5);//agv状态
  834. statu[0] = pose.x();
  835. statu[1] = pose.y();
  836. statu[2] = pose.theta();
  837. statu[3] = line_velocity;
  838. statu[4] = angular_velocity;
  839. NavParameter::MPC_parameter mpc_parameter = parameter_.x_mpc_parameter();
  840. double obs_w = 0.95;//0.85;
  841. double obs_h = 1.55;//1.45;
  842. MpcError ret = failed;
  843. Pose2d brother = timedBrotherPose_.Get();
  844. Pose2d brother_in_self = Pose2d::relativePose(brother, pose);
  845. // std::cout<<" brother_in_self: "<<brother_in_self<<std::endl;
  846. if (move_mode_ == eDouble) {
  847. brother_in_self = Pose2d(pose.x() + 100, pose.y() + 100, 0);
  848. }
  849. RotateMPC MPC(brother_in_self, obs_w, obs_h, limit_wmg.min, limit_wmg.max);
  850. RotateMPC::MPC_parameter parameter = {mpc_parameter.shortest_radius(), mpc_parameter.dt(),
  851. mpc_parameter.acc_velocity(), mpc_parameter.acc_angular()};
  852. ret = MPC.solve(current_to_target, statu, parameter, out);
  853. if (ret == no_solution) {
  854. printf(" Rotation_mpc solve no solution set v/w = 0\n");
  855. out.clear();
  856. out.push_back(0);
  857. out.push_back(0);
  858. out.push_back(0);
  859. } else {
  860. // double min_angular_velocity = 1.0 / 180 * M_PI;
  861. double min_angular_velocity = 0.01;
  862. const int down_count = 3;
  863. for (int i = 0; i < down_count; ++i) {
  864. if (fabs(out[i]) < min_angular_velocity) {
  865. if (out[i] > 0)
  866. out[i] = min_angular_velocity;
  867. else if (out[i] < 0)
  868. out[i] = -min_angular_velocity;
  869. else {}
  870. }
  871. }
  872. }
  873. return ret == success || ret == no_solution;
  874. }
  875. bool Navigation::mpc_once(Trajectory traj, stLimit limit_v, std::vector<double> &out, bool directY) {
  876. if (PoseTimeout() == true) {
  877. printf(" MPC once Error:Pose is timeout \n");
  878. return false;
  879. }
  880. if (timedV_.timeout() == true || timedA_.timeout() == true) {
  881. printf(" MPC once Error:V/A is timeout \n");
  882. return false;
  883. }
  884. if (traj.size() == 0) {
  885. printf("traj size ==0\n");
  886. return false;
  887. }
  888. Pose2d pose = timedPose_.Get();
  889. double velocity = timedV_.Get(); //从plc获取状态
  890. double angular = timedA_.Get();
  891. // float diffYaw1=timedPose_.Get().m_diffYaw1;
  892. // float diffYaw2=timedPose_.Get().m_diffYaw2;
  893. Eigen::VectorXd statu = Eigen::VectorXd::Zero(5);//agv状态
  894. statu[0] = pose.x();
  895. statu[1] = pose.y();
  896. statu[2] = pose.theta();
  897. statu[3] = velocity;
  898. statu[4] = angular;
  899. Trajectory optimize_trajectory;
  900. Trajectory selected_trajectory;
  901. NavParameter::MPC_parameter mpc_parameter = parameter_.x_mpc_parameter();
  902. double obs_w =obs_w_;// 0.95;//0.85;
  903. double obs_h =obs_h_;// 1.55;//1.45;
  904. if (directY == true) {
  905. //将车身朝向旋转90°,车身朝向在(-pi,pi]
  906. statu[2] += M_PI / 2;
  907. if (statu[2] > M_PI)
  908. statu[2] -= 2 * M_PI;
  909. mpc_parameter = parameter_.y_mpc_parameter();
  910. obs_w = obs_h_;// 0.95;//0.85;
  911. obs_h = obs_w_;//1.55;//1.45;
  912. }
  913. Pose2d brother = timedBrotherPose_.Get();
  914. Pose2d relative = Pose2d::relativePose(brother, pose);
  915. if (directY)
  916. relative = Pose2d::relativePose(brother.rotate(brother.x(), brother.y(), M_PI / 2),
  917. pose.rotate(pose.x(), pose.y(), M_PI / 2));//计算另一节在当前小车坐标系下的坐标
  918. std::cout<<"pose:"<<pose<<", brother:"<<brother<<", relative:"<<relative<<std::endl;
  919. if (move_mode_ == eDouble)
  920. relative = Pose2d(-1e8, -1e8, 0);
  921. MpcError ret = failed;
  922. LoadedMPC MPC(relative, obs_w, obs_h, limit_v.min, limit_v.max);
  923. LoadedMPC::MPC_parameter parameter = {mpc_parameter.shortest_radius(), mpc_parameter.dt(),
  924. mpc_parameter.acc_velocity(), mpc_parameter.acc_angular()};
  925. //printf(" r:%f dt:%f acc:%f acc_a:%f\n",mpc_parameter.shortest_radius(),
  926. // mpc_parameter.dt(),mpc_parameter.acc_velocity(),mpc_parameter.acc_angular());
  927. ret = MPC.solve(traj, traj[traj.size() - 1], statu, parameter,
  928. out, selected_trajectory, optimize_trajectory,directY);
  929. //std::cout<<" traj size %d %d -------- "<<selected_trajectory.size()<<","<<optimize_trajectory.size()<<std::endl;
  930. if (ret == no_solution) {
  931. printf(" mpc solve no solution set v/w = 0\n");
  932. out.clear();
  933. out.push_back(0);
  934. out.push_back(0);
  935. out.push_back(0);
  936. out.push_back(0);
  937. out.push_back(0);
  938. out.push_back(0);
  939. }
  940. //
  941. // diff_yaw.push_back(0);
  942. // diff_yaw.push_back(0);
  943. predict_traj_.reset(optimize_trajectory, 1);
  944. selected_traj_.reset(selected_trajectory, 1);
  945. return ret == success || ret == no_solution;
  946. }
  947. bool Navigation::IsArrived(NavMessage::PathNode targetNode) {
  948. if (timedPose_.timeout() || timedV_.timeout() || timedA_.timeout()) {
  949. printf(" pose / v / w timeout,IsArrived return false\n");
  950. return false;
  951. }
  952. Pose2d current = timedPose_.Get();
  953. double x = current.x();
  954. double y = current.y();
  955. double tx = targetNode.x();
  956. double ty = targetNode.y();
  957. double l = fabs(targetNode.l());
  958. double w = fabs(targetNode.w());
  959. double theta = -targetNode.theta();
  960. if (newUnfinished_cations_.front().type() == 1 && targetNode.id().find('S')!=-1){//入库只判断前后方向上是否到达
  961. tx = x;
  962. }
  963. if (l < 1e-10 || w < 1e-10) {
  964. printf("IsArrived: Error target l or w == 0\n");
  965. return false;
  966. }
  967. double a = (x - tx) * cos(theta) - (y - ty) * sin(theta);
  968. double b = (x - tx) * sin(theta) + (y - ty) * cos(theta);
  969. if (pow(a / l, 8) + pow(b / w, 8) <= 1) {
  970. if (fabs(timedV_.Get()) < 0.06 && fabs(timedA_.Get()) < 5 * M_PI / 180.0) {
  971. printf(" Arrived target: %f %f l:%f w:%f theta:%f\n", tx, ty, l, w, theta);
  972. return true;
  973. }
  974. }
  975. return false;
  976. }
  977. void Navigation::SendMoveCmd(int mode, ActionType type,
  978. double v, double angular) {
  979. if (monitor_) {
  980. monitor_->set_speed(mode, type, v, angular);
  981. if (type == eRotation)
  982. RWheel_position_ = eR;
  983. if (type == eVertical)
  984. RWheel_position_ = eX;
  985. if (type == eHorizontal)
  986. RWheel_position_ = eY;
  987. }
  988. }
  989. void Navigation::SendMoveCmd(int mode, ActionType type,
  990. double v[], double angular[]) {
  991. if (monitor_) {
  992. monitor_->set_ToAgvCmd(mode, type, v, angular);
  993. if (type == eRotation)
  994. RWheel_position_ = eR;
  995. if (type == eVertical)
  996. RWheel_position_ = eX;
  997. if (type == eHorizontal)
  998. RWheel_position_ = eY;
  999. }
  1000. }
  1001. void Navigation::SendMoveCmd(int mode, ActionType type, double v[], double angular[], int space_id, double distance) {
  1002. if (monitor_) {
  1003. monitor_->set_ToAgvCmd(mode, type, v, angular, 0, space_id, distance);
  1004. if (type == eRotation)
  1005. RWheel_position_ = eR;
  1006. if (type == eVertical)
  1007. RWheel_position_ = eX;
  1008. if (type == eHorizontal)
  1009. RWheel_position_ = eY;
  1010. }
  1011. }
  1012. //void Navigation::SendMoveCmd(int mode, ActionType type, double v[], double angular[], double yaw_diff[] ,int space_id, double distance) {
  1013. // if (monitor_) {
  1014. // monitor_->set_ToAgvCmd(mode, type, v, angular, yaw_diff ,0,space_id, distance);
  1015. // if (type == eRotation)
  1016. // RWheel_position_ = eR;
  1017. // if (type == eVertical)
  1018. // RWheel_position_ = eX;
  1019. // if (type == eHorizontal)
  1020. // RWheel_position_ = eY;
  1021. // }
  1022. //}
  1023. bool Navigation::clamp_close() {
  1024. if (monitor_) {
  1025. printf("Clamp closing...\n");
  1026. monitor_->clamp_close(move_mode_);
  1027. actionType_ = eClampClose;
  1028. while (cancel_ == false) {
  1029. if (timed_clamp_.timeout()) {
  1030. printf("timed clamp is timeout\n");
  1031. return false;
  1032. }
  1033. if (timed_clamp_.Get() == eClosed)
  1034. return true;
  1035. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  1036. monitor_->clamp_close(move_mode_);
  1037. actionType_ = eClampClose;
  1038. }
  1039. return false;
  1040. }
  1041. return false;
  1042. }
  1043. bool Navigation::clamp_open() {
  1044. if (monitor_) {
  1045. printf("Clamp openning...\n");
  1046. monitor_->clamp_open(move_mode_);
  1047. actionType_ = eClampOpen;
  1048. while (cancel_ == false) {
  1049. if (timed_clamp_.timeout()) {
  1050. printf("timed clamp is timeout\n");
  1051. return false;
  1052. }
  1053. if (timed_clamp_.Get() == eOpened)
  1054. return true;
  1055. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  1056. monitor_->clamp_open(move_mode_);
  1057. actionType_ = eClampOpen;
  1058. }
  1059. return false;
  1060. }
  1061. return false;
  1062. }
  1063. bool Navigation::clamp_fully_open(){
  1064. if (monitor_){
  1065. printf("Clamp fully openning...\n");
  1066. monitor_->clamp_fully_open(move_mode_);
  1067. actionType_ = eClampFullyOpen;
  1068. while (cancel_ == false) {
  1069. if (timed_clamp_.timeout()) {
  1070. printf("timed clamp is timeout\n");
  1071. return false;
  1072. }
  1073. if (timed_clamp_.Get() == eFullyOpened)
  1074. return true;
  1075. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  1076. monitor_->clamp_fully_open(move_mode_);
  1077. actionType_ = eClampFullyOpen;
  1078. }
  1079. return false;
  1080. }
  1081. return false;
  1082. }
  1083. bool Navigation::lifter_rise() {
  1084. if (monitor_) {
  1085. printf("Lifter upping...\n");
  1086. monitor_->lifter_rise(move_mode_);
  1087. actionType_ = eLifterRise;
  1088. while (cancel_ == false) {
  1089. if (timed_lifter_.timeout()) {
  1090. printf("timed lifter is timeout\n");
  1091. return false;
  1092. }
  1093. if (timed_lifter_.Get() == eRose)
  1094. return true;
  1095. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  1096. monitor_->lifter_rise(move_mode_);
  1097. actionType_ = eLifterRise;
  1098. }
  1099. return false;
  1100. }
  1101. return false;
  1102. }
  1103. bool Navigation::lifter_down() {
  1104. if (monitor_) {
  1105. printf("Lifter downing...\n");
  1106. monitor_->lifter_down(move_mode_);
  1107. actionType_ = eLifterDown;
  1108. while (cancel_ == false) {
  1109. if (timed_lifter_.timeout()) {
  1110. printf("timed lifter is timeout\n");
  1111. return false;
  1112. }
  1113. if (timed_lifter_.Get() == eDowned)
  1114. return true;
  1115. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  1116. monitor_->lifter_down(move_mode_);
  1117. actionType_ = eLifterDown;
  1118. }
  1119. return false;
  1120. }
  1121. return false;
  1122. }
  1123. Navigation::MpcResult Navigation::MpcToTarget(NavMessage::PathNode node, stLimit limit_v, bool autoDirect) {
  1124. // LogWriter("MpcToTarget beg");
  1125. if (IsArrived(node)) {
  1126. printf(" current already in target completed !!!\n");
  1127. return eMpcSuccess;
  1128. }
  1129. if (inited_ == false) {
  1130. printf(" navigation has not inited\n");
  1131. return eMpcFailed;
  1132. }
  1133. if (PoseTimeout()) {
  1134. printf(" navigation Error:Pose is timeout \n");
  1135. return eMpcFailed;
  1136. }
  1137. Pose2d current = timedPose_.Get();
  1138. Pose2d target(node.x(), node.y(), 0);
  1139. //生成轨迹
  1140. Trajectory traj = Trajectory::create_line_trajectory(current, target, 0.1);
  1141. if (traj.size() == 0)
  1142. return eMpcSuccess;
  1143. //判断 巡线方向
  1144. bool directY = false;
  1145. if (autoDirect) {
  1146. Pose2d target_relative = Pose2d::relativePose(target, timedPose_.Get());
  1147. if (fabs(target_relative.y()) > fabs(target_relative.x())) { //目标轨迹点在当前点Y轴上
  1148. std::cout << " MPC Y axis target_relative:" << target_relative << std::endl;
  1149. directY = true;
  1150. } else {
  1151. std::cout << " MPC X axis target_relative:" << target_relative << std::endl;
  1152. }
  1153. }
  1154. printf(" exec along autoDirect:%d\n", autoDirect);
  1155. //文件log
  1156. std::ofstream ofs; //创建流对象
  1157. std::string log_file_dir = "../data/";
  1158. time_t t = time(0);
  1159. char tmp[32]={NULL};
  1160. strftime(tmp, sizeof(tmp), "%Y_%m_%d_%H_%M_%S.txt",localtime(&t));
  1161. std::string log_file_name = tmp;
  1162. ofs.open(log_file_dir+log_file_name,std::ios::app); //打开的地址和方式
  1163. auto beg_time = std::chrono::steady_clock::now();
  1164. while (cancel_ == false) {
  1165. std::this_thread::sleep_for(std::chrono::milliseconds(20));
  1166. if (pause_ == true) {
  1167. //发送暂停消息
  1168. continue;
  1169. }
  1170. if (PoseTimeout()) {
  1171. printf(" navigation Error:Pose is timeout \n");
  1172. ofs.close();//关闭文件
  1173. return eMpcFailed;
  1174. }
  1175. if (timedV_.timeout() || timedA_.timeout()) {
  1176. printf(" navigation Error:v/a is timeout | __LINE__:%d \n", __LINE__);
  1177. ofs.close();//关闭文件
  1178. return eMpcFailed;
  1179. }
  1180. //判断是否到达终点
  1181. if (IsArrived(node)) {
  1182. if (Stop()) {
  1183. printf(" exec along completed !!!\n");
  1184. ofs.close();//关闭文件
  1185. return eMpcSuccess;
  1186. }
  1187. }
  1188. //一次变速
  1189. std::vector<double> out;
  1190. // std::vector<double> diff_yaw; //两车分别与整车的相对角度
  1191. bool ret;
  1192. TimerRecord::Execute([&, this]() {
  1193. ret = mpc_once(traj, limit_v, out, directY);
  1194. }, "mpc_once");
  1195. if (ret == false) {
  1196. Stop();
  1197. ofs.close();//关闭文件
  1198. return eMpcFailed;
  1199. }
  1200. const int down_count = 3;//下发前多少步
  1201. double down_v[down_count] ={out[0], out[2], out[4]};//下发线速度
  1202. double down_w[down_count] ={out[1], out[3], out[5]};//下发角速度
  1203. /*
  1204. * AGV 在终点附近低速巡航时,设置最小速度0.05
  1205. */
  1206. Pose2d target_in_agv = Pose2d::relativePose(target, timedPose_.Get());
  1207. if (directY) {
  1208. target_in_agv = target_in_agv.rotate(M_PI / 2.0);
  1209. }
  1210. if (Pose2d::abs(target_in_agv) < Pose2d(0.2, 2, M_PI * 2)) {
  1211. for (int i = 0; i < down_count; ++i) {
  1212. if (down_v[i] >= 0 && down_v[i] < limit_v.min)
  1213. down_v[i] = limit_v.min;
  1214. if (down_v[i] < 0 && down_v[i] > -limit_v.min)
  1215. down_v[i] = -limit_v.min;
  1216. }
  1217. }
  1218. //放大角速度
  1219. // out[1] *= 10;
  1220. //入库,行进方向上最后一米不纠偏
  1221. if (newUnfinished_cations_.front().type() == 1 && node.id().find('S')!=-1){//入库
  1222. if(fabs(target_in_agv.x()) < 0.5){
  1223. printf("target_in_agv: %f", target_in_agv.x());
  1224. for (double & i : down_w) {
  1225. i = 0.0;
  1226. }
  1227. }
  1228. }else if (newUnfinished_cations_.front().type() == 2){//出库,行进方向上开始一米不纠偏
  1229. Pose2d agv_in_space =
  1230. Pose2d::relativePose(
  1231. Pose2d(newUnfinished_cations_.front().spacenode().x(), newUnfinished_cations_.front().spacenode().y(), 0),
  1232. timedPose_.Get());
  1233. if(fabs(agv_in_space.x()) < 0.3){
  1234. printf("agv_in_space: %f", agv_in_space.x());
  1235. for (double & i : down_w) {
  1236. i = 0.0;
  1237. }
  1238. }
  1239. }
  1240. //下发速度
  1241. //printf(" nav input :%f out:%f\n",timedV_.Get(),out[0]);
  1242. //添加车位号,距目标点距离信息
  1243. double distance = Pose2d::distance(target_in_agv, Pose2d(0,0,0));
  1244. int space_id = 0;
  1245. if(node.id().find('S') != -1){
  1246. std::string id = node.id().substr(1,node.id().length()-1);
  1247. space_id = stoi(id);
  1248. }
  1249. // double diff_yaw_[2] = {diff_yaw[0], diff_yaw[1]};
  1250. if (directY == false)
  1251. SendMoveCmd(move_mode_, eVertical, down_v, down_w, space_id, distance);
  1252. else
  1253. SendMoveCmd(move_mode_, eHorizontal, down_v, down_w, space_id, distance);
  1254. actionType_ = directY ? eHorizontal : eVertical;
  1255. //日志打印
  1256. std::string log_inf_line = std::to_string(move_mode_);
  1257. log_inf_line += " ";
  1258. log_inf_line += std::to_string(parameter_.x_mpc_parameter().shortest_radius())+" "+std::to_string(parameter_.x_mpc_parameter().acc_angular());
  1259. log_inf_line += " ";
  1260. Pose2d cur_pose = timedPose_.Get();//自身x,y,theta
  1261. log_inf_line += std::to_string(cur_pose.x()) + " " + std::to_string(cur_pose.y()) + " " + std::to_string(cur_pose.theta());
  1262. log_inf_line += " ";
  1263. Pose2d cur_Bro_pose = timedBrotherPose_.Get();//另一节x,y,theta
  1264. log_inf_line += std::to_string(cur_Bro_pose.x()) + " " + std::to_string(cur_Bro_pose.y()) + " " + std::to_string(cur_Bro_pose.theta());
  1265. log_inf_line += " ";
  1266. log_inf_line += std::to_string(out[0]) + " " + std::to_string(out[1]);//下发速度
  1267. log_inf_line += " ";
  1268. log_inf_line += std::to_string(out[2]) + " " + std::to_string(out[3]);//下发速度
  1269. log_inf_line += " ";
  1270. log_inf_line += std::to_string(out[4]) + " " + std::to_string(out[5]);//下发速度
  1271. log_inf_line += " ";
  1272. auto cur_time = std::chrono::steady_clock::now();
  1273. auto duration = std::chrono::duration_cast<std::chrono::microseconds>(cur_time - beg_time);
  1274. double time =
  1275. double(duration.count()) * std::chrono::microseconds::period::num / std::chrono::microseconds::period::den;
  1276. log_inf_line += std::to_string(time);
  1277. ofs << log_inf_line << std::endl; //一行日志的内容
  1278. /*
  1279. * 判断车辆是否在终点附近徘徊,无法到达终点
  1280. */
  1281. if (PossibleToTarget(node, directY) == false) {
  1282. printf(" --------------MPC imposible to target -------------------------------------------\n");
  1283. if (fabs(timedV_.Get()) > 0.1 || fabs(timedA_.Get()) > 10 * M_PI / 180.0)
  1284. SlowlyStop();
  1285. else
  1286. Stop();
  1287. ofs.close();//关闭文件
  1288. return eImpossibleToTarget;
  1289. }
  1290. }
  1291. ofs.close();//关闭文件
  1292. return eMpcFailed;
  1293. }
  1294. bool Navigation::PossibleToTarget(NavMessage::PathNode targetNode, bool directY) {
  1295. if (timedPose_.timeout()) {
  1296. return false;
  1297. }
  1298. Pose2d current = timedPose_.Get();
  1299. if(targetNode.id().find('S') != -1){
  1300. //车位点强制可到达
  1301. return true;
  1302. }
  1303. double tx = targetNode.x();
  1304. double ty = targetNode.y();
  1305. double l = fabs(targetNode.l());
  1306. double w = fabs(targetNode.w());
  1307. double theta = -targetNode.theta();
  1308. // double W = 2.45;
  1309. // double L = 1.3;
  1310. // double minYaw = 3 * M_PI / 180.0;
  1311. // if (move_mode_ == eDouble) {
  1312. // L = 1.3 + 2.7;
  1313. //
  1314. // }
  1315. double W = 2.5;
  1316. double L = 1.565;
  1317. double minYaw = 5 * M_PI / 180.0;
  1318. if (move_mode_ == eDouble) {
  1319. L = 1.565 + 2.78;
  1320. }
  1321. if (directY) {
  1322. current = current.rotate(current.x(), current.y(), M_PI / 2);
  1323. double t = W;
  1324. W = L;
  1325. L = t;
  1326. }
  1327. double minR = W / 2 + L / tan(minYaw);
  1328. //printf("l:%f,w:%f\n",l,w);
  1329. std::vector<Pose2d> poses = Pose2d::generate_rectangle_vertexs(Pose2d(tx, ty, 0), l * 2, w * 2);
  1330. bool nagY = false;
  1331. bool posiY = false;
  1332. for (int i = 0; i < poses.size(); ++i) {
  1333. Pose2d rpos = poses[i].rotate(tx, ty, theta);
  1334. Pose2d relative = Pose2d::relativePose(rpos, current);
  1335. double ax = fabs(relative.x());
  1336. double ay = fabs(relative.y());
  1337. if (relative.y() > 0) posiY = true;
  1338. if (relative.y() < 0) nagY = true;
  1339. if (ax * ax + pow(ay - minR, 2) > minR * minR) {
  1340. /*printf(" possible to target:%f %f l:%f,w:%f theta:%f minR:%f ax:%f,ay:%f\n",
  1341. targetNode.x(),targetNode.y(),targetNode.l(),targetNode.w(),targetNode.theta(),
  1342. minR,ax,ay);*/
  1343. return true;
  1344. } else if (nagY && posiY) {
  1345. // std::cout << "nagY && posiY" << std::endl;
  1346. return true;
  1347. }
  1348. // printf("directY:%d targetInPose:%f %f l:%f,w:%f theta:%f minR:%f ax:%f,ay:%f\n", directY,
  1349. // relative.x(), relative.y(), targetNode.l(), targetNode.w(), targetNode.theta(),
  1350. // minR, ax, ay);
  1351. }
  1352. printf(" impossible to target:%f %f l:%f,w:%f theta:%f, ",
  1353. targetNode.x(), targetNode.y(), targetNode.l(), targetNode.w(), targetNode.theta());
  1354. printf(" current:%f, %f, %f\n",
  1355. current.x(), current.y(),current.theta());
  1356. return false;
  1357. }
  1358. void Navigation::Start(const NavMessage::NavCmd &cmd, NavMessage::NavResponse &response) {
  1359. if (inited_ == false) {
  1360. response.set_ret(-1);
  1361. response.set_info("navigation has not inited");
  1362. printf(" navigation has not inited\n");
  1363. return;
  1364. }
  1365. if (newUnfinished_cations_.empty() == false) //正在运行中,上一次指令未完成
  1366. {
  1367. response.set_ret(-2);
  1368. response.set_info("navigation is running pls cancel before");
  1369. printf(" navigation is running pls cancel before\n");
  1370. return;
  1371. }
  1372. //add 先检查当前点与起点的距离
  1373. global_navCmd_ = cmd;
  1374. for (int i = 0; i < cmd.newactions_size(); ++i)
  1375. newUnfinished_cations_.push(cmd.newactions(i));
  1376. pause_ = false;
  1377. cancel_ = false;
  1378. running_ = true;
  1379. actionType_ = eReady;
  1380. printf("Navigation beg...\n");
  1381. while (newUnfinished_cations_.empty() == false && cancel_ == false) {
  1382. std::cout << "unfinished size:" << newUnfinished_cations_.size() << std::endl;
  1383. NavMessage::NewAction act = newUnfinished_cations_.front();
  1384. if (act.type() == 1) { //入库
  1385. space_id_ = act.spacenode().id();
  1386. obs_w_=1.25;
  1387. obs_h_=1.87;
  1388. if (!execute_InOut_space(act)) {
  1389. printf(" In space failed\n");
  1390. isInSpace_ = false;
  1391. break;
  1392. }
  1393. } else if (act.type() == 2) { //出库
  1394. obs_w_=1.25;
  1395. obs_h_=1.87;
  1396. if (!execute_InOut_space(act)) {
  1397. printf(" out space failed\n");
  1398. break;
  1399. } else {
  1400. isInSpace_ = false;
  1401. }
  1402. } else if (act.type() == 3 || act.type() == 4) { //马路导航
  1403. obs_w_=1.25;
  1404. obs_h_=1.87;
  1405. if (!execute_nodes(act)){
  1406. printf(" street nav failed\n");
  1407. break;
  1408. }
  1409. } else if (act.type() == 5) {
  1410. printf(" 汽车模型导航....\n");
  1411. } else if (act.type() == 6) {//夹持
  1412. if (this->clamp_close() == false) {
  1413. printf("夹持failed ...\n");
  1414. break;
  1415. }
  1416. } else if (act.type() == 7) {
  1417. if (this->clamp_open() == false) {
  1418. printf("打开夹持 failed...\n");
  1419. break;
  1420. }
  1421. } else if (act.type() == 8) { //切换模式
  1422. SwitchMode(act.changedmode(), act.wheelbase());
  1423. } else if (act.type() == 9) { //提升机构提升
  1424. if (this->lifter_rise() == false) {
  1425. printf("提升failed ...\n");
  1426. break;
  1427. }
  1428. } else if (act.type() == 10) { //提升机构下降
  1429. if (this->lifter_down() == false) {
  1430. printf("下降failed ...\n");
  1431. break;
  1432. }
  1433. }else {
  1434. printf(" action type invalid not handled !!\n");break;
  1435. }
  1436. newUnfinished_cations_.pop();
  1437. }
  1438. actionType_ = eReady;
  1439. Stop();
  1440. if (cancel_ == true) {
  1441. response.set_ret(-3);
  1442. response.set_info("navigation canceled");
  1443. printf(" navigation canceled\n");
  1444. while (newUnfinished_cations_.empty() == false)
  1445. newUnfinished_cations_.pop();
  1446. } else {
  1447. if (newUnfinished_cations_.empty()) {
  1448. response.set_ret(0);
  1449. response.set_info("navigation completed!!!");
  1450. printf("navigation completed!!!\n");
  1451. } else {
  1452. response.set_ret(-4);
  1453. response.set_info("navigation Failed!!!!");
  1454. printf(" navigation Failed\n");
  1455. while (newUnfinished_cations_.empty() == false)
  1456. newUnfinished_cations_.pop();
  1457. }
  1458. }
  1459. running_ = false;
  1460. }
  1461. void Navigation::SwitchMode(int mode, float wheelBase) {
  1462. printf("Child AGV can not Switch Mode\n");
  1463. }
  1464. float Navigation::compute_cuv(const Pose2d &target) {
  1465. float x = fabs(target.x());
  1466. float y = fabs(target.y());
  1467. float cuv = atan(y / (x + 1e-8));
  1468. //printf(" ---------------------- cuv:%f\n",cuv);
  1469. return cuv;
  1470. }
  1471. void Navigation::ManualOperation(const NavMessage::ManualCmd &cmd, NavMessage::NavResponse &response) {
  1472. return;
  1473. // pause_ = false;
  1474. // cancel_ = false;
  1475. // running_ = true;
  1476. // actionType_ = eReady;
  1477. // printf("ManualOperation: %d | start...\n", cmd.operation_type());
  1478. //
  1479. // float symbol = cmd.velocity() < 0 ? -1 : 1; // 判断为正方向or负方向
  1480. // double velocity;
  1481. // std::this_thread::sleep_for(std::chrono::milliseconds(100));
  1482. // switch (cmd.operation_type()) {
  1483. // case 1: // 旋转
  1484. // velocity = 2.0 * M_PI / 180.0 * symbol;
  1485. // SendMoveCmd(move_mode_, eRotation, 0, velocity);
  1486. // actionType_ = eRotation;
  1487. // printf(" ManualOperation: %d | input angular_v: %f, down: %f\n",
  1488. // cmd.operation_type(), timedA_.Get(), velocity);
  1489. // break;
  1490. // case 2: // X平移
  1491. // velocity = 1.0 * symbol;
  1492. // SendMoveCmd(move_mode_, eVertical, velocity, 0);
  1493. // actionType_ = eVertical;
  1494. // printf(" ManualOperation: %d | input line_v : %f, down: %f\n",
  1495. // cmd.operation_type(), timedV_.Get(), velocity);
  1496. // break;
  1497. // case 3: // Y平移
  1498. // velocity = 1.0 * symbol;
  1499. // SendMoveCmd(move_mode_, eHorizontal, velocity, 0);
  1500. // actionType_ = eHorizontal;
  1501. // printf(" ManualOperation: %d | input line_v: %f, down: %f\n",
  1502. // cmd.operation_type(), timedV_.Get(), velocity);
  1503. // break;
  1504. // default:
  1505. // break;
  1506. // }
  1507. //
  1508. // actionType_ = eReady;
  1509. // response.set_ret(-3);
  1510. // response.set_info("ManualOperation: %d, canceled!!!", cmd.operation_type());
  1511. // printf("ManualOperation: %d | canceled!!!\n", cmd.operation_type());
  1512. // running_ = false;
  1513. }