Let's Make Robots!

RoboDragon

Turn towards detected movement

This is to be (aka not done yet) an animatronic dragon's head.  It currently has 3 PIR sensors to act as eyes.  My goal is to have it interact on some limited level with people.  The idea is to have to head turn right/left towards the most recent movement, and center itself on the 'target' and perform some other entertainment behaviors (open mouth, blink lights, etc..)  So far I can get it to turn towards movement on it's right, but I seem to have a problem with the code to turn the other direction.  I know the sense routine is working (I've checked the output), but the movement routine has a problem I was hoping someone on LMR can give me a hint to get me back on track.  Yes, this is my first 'robot'..  I have no plans to leave the microcontroller imbeded, so I'm using an Arduino.  Here's the function I'm having problems with...

void moveHeadNeck() {
  int alittle = 1; // a small move to one side for fine tuning
  int alot = 2; // a big move to one side when something new is noticed.
  int cPos = neck.read(); // current position of neck servo
  //    Serial.print("cPos:"); Serial.println(cPos);
  //    Serial.print("cPos-1:"); Serial.println(cPos-1);
  if (motionCenter==true) {
      if (motionRight==true) {
        // move a little to the right
        neck.write(cPos-alittle);
        Serial.println("Motion to the CENTER/RIGHT");
      }
      if (motionLeft==true) {
        // move a little to the left
        neck.write(cPos+alittle);
        Serial.println("Motion to the CENTER/LEFT");
      }
    } else { // motionCenter==false
      if (motionRight==true) {
        // move a lot to the right
        neck.write(cPos-alot);
        Serial.println("Motion to the RIGHT");
      }
      if (motionRight==true) {
        // move a lot to the left
        neck.write(cPos+alot);
        Serial.println("Motion to the LEFT");
      }
    }
}

 

This moves to the right (adding) just fine, but refused to turn to the left (subtracting).  Any suggestions?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Combine Splatbot, this bot, some smooth object tracking, and mount it all on some sort of gun-sentry type platform and I think I have something to keep the rodents away from my vegetables at night! Good stuff, m8.

waiting for the video

:)

After seeing your successes with the sharp sensors for motion tracking, I'm considering either doing an addition, or a redesign.  I'm not sure yet, and I have not received the sharp sensors I ordered today.. :)

Perhaps a combination of the two?  The sharps for when you have someone to track, and the PIRs for when you haven't found someone and are looking for a "target"?

the only problem i found with sharp sensors is that they loose the object at some points as you can see in the video.Maybe because of the unstable readings from the sensors .but this problem can be overcomed using PIR sensors along i guess.

Well, whatever the problem is, I hope that you can get it working the way you want it to. It appears that you are going to have quite the robot that is going to be really cool to check out once it is completed.

Try reading through your code line by line, there could be several places where it can go wrong. In your function above I can see at least 1 instance which would cause a problem. The last motionRight should probably be motionLeft. Also if motionRight/Left etc are global variables be sure to reset them each loop.

 

THANK YOU!

 

I don't know why I missed that.  I read the code, I-don't-know-how-many times..  The head is moving right/left based on surrounding movement.. ! ! !

 

Now if I can get the PIR's to quit reporting false movement..  I've inserted delays long enough for them to reset, and debounce, but I'm still getting a little random artifact from the side without movement.  The loop() reads for motion, but waits for 400 millis before reading, to make sure the head isn't picking up it's own movement..  :)  Here's the revised head move function...

 

void moveHeadNeck() {
  int alittle = 5; // a small move to one side for fine tuning
  int alot = 20; // a big move to one side when something new is noticed.
  int cPos = neck.read(); // current position of neck servo
  if (motionCenter==true) {
      if (motionRight==true) { // move a little to the right, closer to 0
        neck.write(cPos-alittle);
        Serial.println("Motion to the CENTER/RIGHT");
      }
      if (motionLeft==true) { // move a little to the left, closer to 180
        neck.write(cPos+alittle);
        Serial.println("Motion to the CENTER/LEFT");
      }
    } else { // motionCenter==false
      if (motionRight==true) { // move a lot to the right, closer to 0
        neck.write(cPos-alot);
        Serial.println("Motion to the RIGHT");
      }
      if (motionLeft==true) { // move a lot to the left, closer to 180
        neck.write(cPos+alot);
        Serial.println("Motion to the LEFT");
      }
    }
  moving = true;
  stopTime = millis() + 350;
}

Forgive me if you are already familiar with this info, but here is a great tutorial on using the PIR sensors from Lady Ada.

Maybe a review of this info will help.

Many PIR sensors have a jumper to select between retriggering and non-retriggering modes. Do you have a link to your specific PIRs?

I got my PIR from Lady Ada, but the ones she sent me are a slightly different model than her tutorial shows.  There weren't jumpers on my PIRs when I got them, a jumper (wire) was soldered in place to the 'hi' setting.  I removed this on each of my PIRs and put the pins in, and jumpers connecting to 'low'.  I've also calibrated each of them so their refresh rate is very short, about 300 to 350 millis is the average.  With this in mind, I've set my readsensor function to self limit to reading once every 400 millis to avoid reacting multiple times to the same stimuli.  I have also included a 400millis delay to allow for the servos to move.  As it stands now, the sensors "see" movement, the servos react, then the whole thing just waits about 400 millis then reads again. The only problem I have now is that it's a little jerky with it's movements, not the fluid motion you'd expect to see in an organic.

Are you fairly sure the PIRs reset properly within 400ms? It just seems very short. Most of the ones I`ve seen need several seconds to settle.