Go Down

Topic: Making a robot stop and hold it's position [SOLVED] (Read 2630 times) previous topic - next topic

Scott_Callahan

I'll add in the extra () that you did and try that. I could definitely go to 500mS and maybe even 1000 but 1000 may give it some false positives. I'll try increasing the mS until I get behavior I don't want. You are also right about the last block time, thank you for catching that error. I think I need to replace ScanForBlocks(); with Camera();. The Camera(); loop produces the lastBlockTime.

I'll give all of that a try and see what happens. Thank you again.

Scott_Callahan

Now some interesting things are happening. I tried quite a few changes that didn't yield any results. One thing I did try was increasing the 200mS to 500mS, 1000mS and all the way to 5000mS. That in itself didn't change anything when the robot was looking at a red object (which is what the camera is programed to look for and produces the lastBlockTime). However, if I showed the robot a red object then quickly swapped it out for another object the robot would hold it's rest(); position for approximately 5 seconds. I've got to think this out a little.

Scott_Callahan

Whoa! It works!
I adjusted the millis all the way up to 50000. I correctly assumed that would cause it to go into rest(); if the IR sensor detected something during that time even if the red object wasn't in front of the camera. meaning if a wall or furniture was detected within the Middle range of the IR it would go into Rest(); To fix that I increased the distance the IR sensor will cause the robot to turn and avoid an object if it doesn't see red. 50,000 millis wouldn't be enough time to hold the position so I upped it again to 500,000. I only poll the IR in the while statement now. Now the robot will hold it's position for a maximum of 8 minutes (which should be enough time). Most importantly, if the object moves during that time it will go back to scanning for the object or tracking it appropriately. It seems like the battery is getting low from all this use so I'm going to charge it and recheck all it's motions before I tag this as solved. Below is what the current loop looks like right now.

Code: [Select]
void loop()
{
  read_Ir();
  ScanForBlocks();
  camera();

  while ((ir > Middle) && (millis() - lastBlockTime < 500000))
  {
    Rest();
    read_Ir();
  }
  if ((panLoop.m_pos < RCS_CENTER_POS) && ir > Far && (millis() - lastBlockTime > 500))
  {
    Turn_Right(200);
  }
  else if ((panLoop.m_pos > RCS_CENTER_POS) && Far > Middle && (millis() - lastBlockTime > 500))
  {
    Turn_Left(200);
  }
}


A very big thank you to you guys for your input so far. Any other advice is always appreciated.

Scott

Scott_Callahan

#18
Feb 02, 2016, 03:23 am Last Edit: Feb 02, 2016, 03:30 am by Scott_Callahan
Thank you very much to the Arduino forum especially CrossRoads. The robot does for the most part exactly as I had wished for. It does stop and hold in the rest() position when appropriate. It also can still roam the house avoiding walls and furniture. I had to make a few minor adjustments in the turn left and turn right obstacle avoidance to avoid false positives (bring the mills - lastBlockTime > back down to 200). I need to do more fine tuning of the IR values and perhaps speed up the pan servo proportional gain to make it run flawlessly. But that wasn't what the topic was about. The robot does stop and hold it's position now until the object moves. Next up is fine tuning adjustments and adding the sound back to it!

Thank you again for your help.

Scott

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Sameer_Shaikh

Thanks for your suggestions it will help me in my project and if I have any doubt I will post it here

Thanks once again

Sameer_Shaikh

Hey Scott_Callahan can I get all details of your project.because I am going make similar to your robot so if I get the details it will be helpful for me

Sameer_Shaikh

Scott_Callahan

Hey Scott_Callahan can I get all details of your project.because I am going make similar to your robot so if I get the details it will be helpful for me

Sameer_Shaikh
While I'd like to be of great assistance you need to know that I know very little about code or robots. I am no expert at all and have no training. Anything I have figured out is from mostly trial and error. I'll spend over a month on trying new ideas and searching the internet before I go to a forum like this to ask for advice.
This is a very new hobby to a nearly 40 year old blue collar worker who's college education didn't even earn an AA. I'm sure that shows in my grammar and punctuation.
I have no idea what you mean by "all the details". My robot's functions and your idea seems to me to be very different. Not to mention I have no idea if your robot walks or is on wheels or tracks.
I read a while ago to start simple and tackle one part of code at a time. I really try to do that and I'd suggest you do the same. Get a robot you think will physically do what you want and get it to move then go from there.
After that the best advice I can offer is if you want a robot that can track color, google PixyCam and PixyPet. That is what changed my robot from a simple device into one that can seek certain objects out.
I promise you, if I just gave you my code it would be absolutely worthless to you and you'd have more questions than answers.
One more piece of info, I can't remember how I found it but I saw a robot on the internet a while ago that was an arm that seeked out certain color objects, picked them up and moved them to another location. The code for that was significantly different than mine and was no use to me. However, that seems more what you are looking for.

Sameer_Shaikh

Where did u saw that video and how did you get the code of that robot if saw it on YouTube how did you get it's code

Scott_Callahan

I'm making some adjustments on the code to make the robot a little more accurate. I'm trying to have the robot take 1 small step before it goes into the rest position with the hopes that a small movement will help the pan servo stay centered on the object. I first simply wrote Walk(5); into the while statement. But of course all the robot did was alternate between Walk(); and Rest();
So I wrote it like what is posted below. It seems to work, but the Walk(5); is such a small step I can't really tell if I wrote it right. Can anyone tell me if this is appropriate? Specifically how I added the first if()

Thanks again

Code: [Select]
void loop()
{
  read_Ir();
  ScanForBlocks();
  camera();

  if ((ir > Middle) && (millis() - lastBlockTime < 200))
  {
    Walk(5);
    {
      while ((ir > Middle) && (millis() - lastBlockTime < 600000))
      {
        Rest();
        read_Ir();
      }
    }
  }

Go Up