Loading ...
Sorry, an error occurred while loading the content.
 

Re: Chasing the ball

Expand Messages
  • greatbob_cheng
    Hi Ethan: Thanks a lot for the reply! Here is the code that I modified based on the chaseball program: void ChengChaseBallBehavior::processEvent(const
    Message 1 of 8 , Dec 1, 2006
      Hi Ethan:

      Thanks a lot for the reply!

      Here is the code that I modified based on the chaseball program:

      void ChengChaseBallBehavior::processEvent(const EventBase& event)
      {
      WMreg(chase_ball_behavior);
      WMvari_(float, horiz, 0, chase_ball_behavior);
      WMvari_(float, vert, 0, chase_ball_behavior);

      if(event.getGeneratorID()==EventBase::visObjEGID &&
      event.getTypeID()==EventBase::statusETID)
      {
      horiz=static_cast<const VisionObjectEvent*>(&event)->getCenterX();
      vert=static_cast<const VisionObjectEvent*>(&event)->getCenterY();
      }

      WalkMC * walker = (WalkMC*)motman->checkoutMotion(walker_id);

      //below is my code
      **********************************************************
      if(horiz==0 && (vert<0.001 && vert>0))
      //if the AIBO is very close to the pink object, then stop moving
      {
      std::string message = "Stopped\n";
      sock->write((const byte*)message.c_str(), message.length());
      std::cout<<"Stopped"<<std::endl;
      std::cout<<"horiz = "<<horiz<<" | vert = "<< vert<<std::endl;
      stop = true;
      walker->setTargetVelocity(0,0,0);
      motman->checkinMotion(walker_id);
      }

      if(!stop)
      {
      std::cout << "horiz ="<<horiz<<" | vert = " << vert << std::endl;

      if(state->outputs[HeadOffset+PanOffset]<-.05 || state->outputs
      [HeadOffset+PanOffset]>.05)
      {
      walker->setTargetVelocity(100,0,state->outputs
      [HeadOffset+PanOffset]);
      motman->checkinMotion(walker_id);
      }
      else
      {
      walker->setTargetVelocity(160,0,0);
      std::cout<<"160"<<std::endl;
      motman->checkinMotion(walker_id);
      }
      }
      else
      {
      walker->setTargetVelocity(0,0,0);
      motman->checkinMotion(walker_id);
      }
      *******************************************************
      //my code stops here

      double tilt=state->outputs[HeadOffset+TiltOffset]-vert*M_PI/7.5;
      double pan=state->outputs[HeadOffset+PanOffset]-horiz*M_PI/6;
      if(tilt<DtoR(-20))
      tilt=DtoR(-20);
      if(tilt>DtoR(40))
      tilt=DtoR(40);
      if(pan>DtoR(80))
      pan=DtoR(80);
      if(pan<DtoR(-80))
      pan=DtoR(-80);

      HeadPointerMC * headpointer= (HeadPointerMC*)motman->checkoutMotion
      (headpointer_id);
      headpointer->setJoints(tilt,pan,0);
      motman->checkinMotion(headpointer_id);
      }

      - Cheng
    • greatbob_cheng
      Hi Ethan: Are you familiar with this error message?: [oid:80000038,prio:1] OVirtualRobotComm : JAM. SHUTDOWN... MotoObj::DoStop()... MotoObj::DoStop()-DONE
      Message 2 of 8 , Dec 1, 2006
        Hi Ethan:

        Are you familiar with this error message?:

        [oid:80000038,prio:1] OVirtualRobotComm : JAM. SHUTDOWN...
        MotoObj::DoStop()...
        MotoObj::DoStop()-DONE
        [oid:80000044,prio:1] FtpPI::ListenCont() : FAILED. listenMsg->error 2
        [oid:80000044,prio:1] FtpPI::ListenCont() : FAILED. listenMsg->error 2
        MainObj::DoStop()...
        StartupBehavior stopping spawned: Controller
        [oid:80000044,prio:1] FtpPI::ListenCont() : FAILED. listenMsg->error 2
        ~Controller()...
        [oid:80000044,prio:1] FtpPI::ListenCont() : FAILED. listenMsg->error 2
        NETWORK: Message server tore down
        ~Controller()-DONE
        StartupBehavior stopping spawned MC: 1
        MainObj::DoStop()-DONE

        - Cheng
      • Ethan Tira-Thompson
        I think this boils down to a bit of a logic error. You want to stop walking when the ball is close , but you re actually stopping when the ball is in the
        Message 3 of 8 , Dec 2, 2006
          I think this boils down to a bit of a logic error.  You want to stop walking when the ball is "close", but you're actually stopping when the ball is in the center of the image.  Since the head pointer is always trying to center the ball, you're could be stopping any time.  Except you have such tight bounds on this check (horizontal has to be precisely 0, and vertical between 0 and 0.001) that I'm not sure it would actually ever get into the "stop" condition, and if it did, it looks like it wouldn't actually start again until you restarted your behavior.  (so I'm not sure why it would be "walking slowly", unless there's something wrong with the setup in DoStart -- perhaps a leaked posture fighting for control of the joints...)

          If your code has been working to stop the walking when close, I have a feeling it's because when the robot is really close to the ball, the ball fills the entire image and so the object location is consistently set to the precise center of the image.  But you could always get "lucky" at a distance too, so i'd suggest a few changes:

          // the aibo looks down when it's close to the ball, so use that to imply distance
          // 'downAngle' will be the angle at which to say "close enough"
          // default value shown here is halfway down
          float downAngle = outputRanges[HeadOffset+TiltOffset][MinRange] / 2;

          if(state->outputs[HeadOffset+TiltOffset]<downAngle)
          //if the AIBO is very close to the pink object, then stop moving
          {
          std::string message = "Stopped\n";
          sock->write((const byte*)message.c_str(), message.length());
          std::cout<<"Stopped"<<std::endl;
          std::cout<<"horiz = "<<horiz<<" | vert = "<< vert<<std::endl;
          walker->setTargetVelocity(0,0,0);
          // note that if the ball is moved, we'll start walking again.  If you really
          // want to never move again once the ball is close, can either call
          // erouter->removeListener(this,...) or DoStop()
          else {
          std::cout << "horiz ="<<horiz<<" | vert = " << vert << std::endl;


          if(state->outputs[HeadOffset+PanOffset]<-.05 ||
          state->outputs[HeadOffset+PanOffset]>.05)
          {
          walker->setTargetVelocity(100,0,state->outputs[HeadOffset+PanOffset]);
          else {
          walker->setTargetVelocity(160,0,0);
          std::cout<<"160"<<std::endl;
          }
          }
          // note this has been moved outside the 'if's -- we always checkout the motion
          // (as part of the untouched code), so we *always* want to check it in as well.
          motman->checkinMotion(walker_id);

        • Ethan Tira-Thompson
          ... Yes, very familiar -- it means a joint is overloading and the system is shutting down as a safety precaution to avoid breaking a gear or burning out a
          Message 4 of 8 , Dec 2, 2006
            Are you familiar with this error message?:
            [oid:80000038,prio:1] OVirtualRobotComm : JAM. SHUTDOWN...
            Yes, very familiar -- it means a joint is overloading and the system is shutting down as a safety precaution to avoid breaking a gear or burning out a servo.

            Be careful about trying to move the leg joints when standing on them, particularly on a surface with good friction -- the leg joints often are unable to slide along the ground when weight is on them, and so they don't quite get into position.  The PID controller notices the joint is out of place and gradually ramps up power to the joints trying to get it into position until finally it hits the safety override.  So depending on how far out of position the joint is, you might not get the "Jam shutdown" right away.

            -ethan

          • greatbob_cheng
            Hi Ethan: You are right. I am currently using pink cardboard as the target. So when the AIBO gets really close to the board, the entire image will be filled
            Message 5 of 8 , Dec 4, 2006
              Hi Ethan:

              You are right. I am currently using pink cardboard as the
              target. So when the AIBO gets really close to the board, the entire
              image will be filled with pink. Sometimes, I do get those errors where
              the target happens to be in the center of the image from a distance.

              I am sure your solution works for a pink ball, because the AIBO
              has to look down. But for the experiment I am doing, the AIBO doesn't
              need to look down to find the pink, becuase the cardboard is large. So
              I wonder if there is any other functions that I can call to determine
              the distance between the target and the AIBO.

              Thakn you very much!

              - Cheng
            • Ethan Tira-Thompson
              ... It sounds like the IR rangefinder is probably a good choice. There s two of them in the nose that point wherever the head is looking:
              Message 6 of 8 , Dec 4, 2006

                So I wonder if there is any other functions that I can call to determine the distance between the target and the AIBO.

                It sounds like the IR rangefinder is probably a good choice.  There's two of them in the nose that point wherever the head is looking:
                state->sensors[NearIRDistOffset] - provides readings in the range 50 to 500 mm
                state->sensors[FarIRDistOffset] - provides readings in the range 200 to 1500 mm

                Also, if you know the physical size of the target you are going to be seeking, you can use the width of the object in the image as a indication of distance to that object.  I think the math works out something like:
                VisionObjectEvent& ev; // the object you're seeing
                float objWidth; // the physical width of the object
                //(in whatever units you want the results to be in...)
                float dist = objWidth / 2 / tan(ev.getWidth()*CameraHorizFOV/2);

                Another approach is if you can assume something about the height of the object above the ground (generally, assume that the object is *on* the ground), then you can use the project to ground functions of kinematics... you can find example usage of this in Behaviors/Demos/GroundPlaneBehavior.h:

                Each of these methods has its advantages and drawbacks -- you can't use the IR distance if it's not pointing at the target, can't trust the visual width of the object if it's being cut off by the camera frame, and can't use the kinematics solution if you're in motion or don't know the height of the object...

                For reference, the full list of sensors available for the ERS7 is found in Shared/ERS7Info.h, which defines the ERS7Info namespace:

                -ethan

              Your message has been successfully submitted and would be delivered to recipients shortly.