Exemplo n.º 1
0
int main()
{
    printf("Hello world!\n");
    RobotInit("/dev/ttyUSB1");

    printf("Moving!\n");

    RobotMove(10,10);
    while ( RobotManoeuvresPending() == 1 ) { RobotWait(1000); fprintf(stderr,"."); }
    fprintf(stderr,"done move forward!\n");
    RobotPrintPosition();

    RobotMove(10,-10);
    while ( RobotManoeuvresPending() == 1 ) { RobotWait(1000); fprintf(stderr,"."); }
    fprintf(stderr,"done move backward!\n");
    RobotPrintPosition();

    RobotMove(10,10);
    while ( RobotManoeuvresPending() == 1 ) { RobotWait(1000); fprintf(stderr,"."); }
    fprintf(stderr,"done move forward!\n");
    RobotPrintPosition();

    fprintf(stderr,"DONE!\n");

   // getchar();

    RobotClose();
    return 0;
}
Exemplo n.º 2
0
       bool check_new_position_for_robot(
               Node const& crt_position_, Robot const& new_position_, 
               Robot::names r_, Directions::types dir_)
       {
           // std::cout << new_position_ << std::flush;
           if (crt_position_.m_state[r_] == new_position_) {
               // The specific case (crt == new) is an optimzation as a
               // robot against a wall won't be able to move in the
               // wall direction
               // std::cout << " same place => discard" << std::endl;
               this->m_stats.inc_discarded();
               return false;
           }

           const State pl = crt_position_.move_robot_to(r_, new_position_);
           // const Set::const_iterator it = this->m_seen.find(pl);
           // const bool known = it == this->m_seen.end();
           const bool known = this->has_been_seen(pl);
           if (!known)
           {
               Node* node = this->find_pending(pl);
               if (node) {
                   // ignore this new path as the Node are stored by
                   // growing energy
                   // std::cout << " in stack => discard" << std::endl;
                   this->m_stats.inc_discarded();
                   this->updateOrigins(*node, r_, dir_); // no-op when origin-policies==None
               } else {
                   Node path(pl, crt_position_.m_state, RobotMove(r_, dir_), crt_position_.nrj()+1); // link to previous state, and to nrj, here only
                   this->insert_pending(path);
                   // std::cout << " not in stack " << std::flush;
                   if (m_goal == new_position_)
                   {
                       // std::cout << "; GOAL " << std::flush;
                       // update solution for this robot
                       if (! must_search_for_other_solutions(path, r_))
                       {
                           std::cout << "; all solutions found!" << std::endl;
                           return true;
                       }
                   }
                   // std::cout << std::endl;
               }
           }
           else
           {
               // std::cout << " seen => discard" << std::endl;
               this->m_stats.inc_discarded();
               // by construction, seen elements are searched by
               // growing energy
               // assert(it->m_energy <= crt_position_.nrj());
               // ignore this new path
           }

           this->m_stats.printSituationSoFar(false);
           return false;
       }