123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- //
- // Created by zx on 23-5-8.
- //
- #include "navigation_main.h"
- NavigationMain::NavigationMain(){
- move_mode_=Monitor_emqx::eSingle;
- wheelBase_=0;
- }
- NavigationMain::~NavigationMain(){
- }
- void NavigationMain::ResetPose(const Pose2d& pose){
- if(move_mode_==Monitor_emqx::eMain) {
- if(timedBrotherPose_.timeout()==true)
- {
- std::cout<<"Brother pose is timeout can not set MainAGV pose"<<std::endl;
- return;
- }
- //Pose2d transform(-wheelBase_/2.0,0,0);
- //Navigation::ResetPose(pose * transform);
- Pose2d brother=timedBrotherPose_.Get();
- Pose2d diff=Pose2d::abs(Pose2d::relativePose(brother,pose));
- if(diff.x()>3.4 || diff.x()<2.3 || diff.y()>0.2 || diff.theta()>5*M_PI/180.0)
- {
- std::cout<<" distance with two agv is too far diff: "<<diff<<std::endl;
- return;
- }
- Pose2d agv=Pose2d((pose.x()+brother.x())/2.0,(pose.y()+brother.y())/2.0,pose.theta());
- Navigation::ResetPose(agv);
- }
- else
- Navigation::ResetPose(pose);
- }
- void NavigationMain::publish_statu(NavMessage::NavStatu& statu)
- {
- statu.set_main_agv(true);
- Navigation::publish_statu(statu);
- }
- void NavigationMain::HandleNavCmd(const NavMessage::NavCmd& cmd)
- {
- if(cmd.action()==4)
- {
- if(cmd.wheelbase()<2.4 || cmd.wheelbase()>3.5)
- {
- printf("Failed to Switch MoveMode --> main,wheelbase invalid :%f\n",cmd.wheelbase());
- return;
- }
- SwitchMode(Monitor_emqx::eMain,cmd.wheelbase());
- return ;
- }
- if(cmd.action()==5)
- {
- printf(" Switch MoveMode --> single\n");
- SwitchMode(Monitor_emqx::eSingle,0);
- return ;
- }
- else
- {
- Navigation::HandleNavCmd(cmd);
- }
- }
- bool NavigationMain::Start(const NavMessage::NavCmd& cmd)
- {
- /*if(move_mode_!=Monitor_emqx::eMain)
- {
- printf(" navigation mode must set main,parameter:Pose2d\n");
- return false;
- }*/
- return Navigation::Start(cmd);
- }
- void NavigationMain::SendMoveCmd(Monitor_emqx::ActionMode mode,Monitor_emqx::ActionType type,
- double v,double angular)
- {
- if(monitor_)
- {
- monitor_->set_speed(mode,type,v,angular,wheelBase_);
- }
- }
- NavMessage::RobotStatu NavigationMain::CreateRobotStatuMsg()
- {
- NavMessage::RobotStatu agvStatu=Navigation::CreateRobotStatuMsg();
- agvStatu.mutable_agvstatu()->set_clamp_other(timed_other_clamp_.Get());
- //std::cout<<agvStatu.DebugString()<<std::endl;
- return agvStatu;
- }
- void NavigationMain::ResetOtherClamp(ClampStatu statu)
- {
- timed_other_clamp_.reset(statu,1);
- }
- void NavigationMain::HandleAgvStatu(const MqttMsg& msg)
- {
- NavMessage::AgvStatu speed;
- if(msg.toProtoMessage(speed))
- {
- ResetStatu(speed.v(),speed.w());
- ResetClamp((ClampStatu)speed.clamp());
- ResetOtherClamp((ClampStatu)speed.clamp_other());
- //printf(" clamp:%d other:%d\n",speed.clamp(),speed.clamp_other());
- }
- }
- bool NavigationMain::clamp_close()
- {
- if(move_mode_==Monitor_emqx::eSingle)
- return Navigation::clamp_close();
- printf("双车夹持\n");
- if(monitor_) {
- monitor_->clamp_close(move_mode_);
- while (exit_ == false) {
- if (timed_clamp_.timeout() || timed_other_clamp_.timeout()) {
- printf("timed clamp is timeout\n");
- return false;
- }
- if (timed_clamp_.Get() == eClosed && timed_other_clamp_.Get()==eClosed) {
- printf("双车夹持completed!!!\n");
- return true;
- }
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
- monitor_->clamp_close(move_mode_);
- }
- return false;
- }
- return false;
- }
- bool NavigationMain::clamp_open() {
- if(move_mode_==Monitor_emqx::eSingle)
- return Navigation::clamp_open();
- if(monitor_) {
- printf("双车松夹持\n");
- monitor_->clamp_open(move_mode_);
- while(exit_==false)
- {
- if(timed_clamp_.timeout()||timed_other_clamp_.timeout())
- {
- printf("timed clamp is timeout\n");
- return false;
- }
- if(timed_clamp_.Get()==eOpened&&timed_other_clamp_.Get()==eOpened) {
- printf("双车松夹持completed!!!\n");
- return true;
- }
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
- monitor_->clamp_open(move_mode_);
- }
- return false;
- }
- return false;
- }
|