2

Author Topic: Fonctions and priority  (Read 1409 times)

0 Members and 1 Guest are viewing this topic.

Offline ishkaTopic starter

  • Jr. Member
  • **
  • Posts: 38
  • Helpful? 0
Fonctions and priority
« on: June 02, 2008, 11:44:27 PM »
Hi
As I'm still in exams and so can't get my part nor start the construction of my 50 robot, all I can do is designing it and wondering about how to code it.
And so, as I'm a total newbie in programming, I found this problem :
it is possible for one sensor to get two fonctions wich would not have to same importance. Concrete example :
I would add two sharpIr rangefinder on my bot : one for obstacle avoiding, and another one to do line following + hole avoiding. Then would this pseudo code work :

if no hole
then check for obstacle
else bacward
if no obstacle
then follow the line
else go left // getting behind the obstacle and perhaps find the line again
go forward
go right


Thx for advices
May the Achtuche be with you...

Offline SixRingz

  • Full Member
  • ***
  • Posts: 76
  • Helpful? 0
  • Bit's and pc's = Robot.
Re: Fonctions and priority
« Reply #1 on: June 03, 2008, 06:47:40 AM »
What cruel robot constructor would put obstacles and holes on the line that the bot is supposed to follow?!?  ::)
Your code looks like a good start for a newbie programmer. You should try to tab or put brackets in it also to clearly show the blocks of code for example:

Code: [Select]
If hole
     go backwards
else
     if no obstacle
          follow the line
     else
          go left //getting behind obstacle and perhaps find the line again
.....
....

This is of course very very pseudo since "follow the line" for example involves a whole steering algorithm of some kind.
A good way to begin might be to do sort of a case study for the sensor input. If we are to simplify the sensors to 1 = object or hole found, 0 = nothing found we could do sort of a table for the four cases:

Sensor 1, Sensor 2,       Action
0               0            Run line following algorithm
1               0            Hole detected, run backward maneuver
0               1            Obstacle detected, run obstacle avoiding maneuver
1               1            Hole and obstacle found, run an appropriate maneuver for this case

then you can build upon that with your code:
Code: [Select]
while(1) //Create an infinite loop
{
...read sensors...

     if(sensor1==1)
     {
          backward_maneuver();
     }

     if(sensor2==1)
     {
          obstacle_maneuver();
     }

     if(sensor1 ==1 and sensor2 == 1)
     {
     some_other_function();
     }

line following algorithm here...
}

Ok, this is just an example to show you one way to create code. This code will not work entirely though. See any problem? What happens if both sensors are 1? It will make a backward_maneuver, then an obstacle_maneuver and then finally run some_other_function(). The two first if statements are true then and need to be modified if this code is to be used. (I hope my attempt at being pedagogical didn't complicate things)
Grounding things properly means burying them in the backyard...

Offline ishkaTopic starter

  • Jr. Member
  • **
  • Posts: 38
  • Helpful? 0
Re: Fonctions and priority
« Reply #2 on: June 03, 2008, 07:14:15 AM »
Quote from: SixRingz
What cruel robot constructor would pur obstacles and holes on the line that the bot is supposed to follow ?!?  ::)
Well, it was more for security, as there's lot of stairs and steps between rooms, I don't want to see my robot lost the line and then try to fly.   :-\ I'm not at this level of robotics yet  :D
Thx for your explanations, it looks ofc more "pro" than what I thought. Can't wait to be the 20th to start my real robotics experience ( the only one I ever get was soldering a small cyberbug photovore kit, wich never worked really well but with all the info i found on this forum I think I find some things to fix it)

And for the code, I was wondering what would happen if there nothing in the area( no line to follow, no obstacles nor holes to avoid) ? Let's imagine I don't want to reprog it each time I want him to do something else (  line following once, running freely in the room another time). Would I need some hardware switch or can I try to code it?
May the Achtuche be with you...

Offline SixRingz

  • Full Member
  • ***
  • Posts: 76
  • Helpful? 0
  • Bit's and pc's = Robot.
Re: Fonctions and priority
« Reply #3 on: June 03, 2008, 08:39:03 AM »
Quote
Let's imagine I don't want to reprog it each time I want him to do something else (  line following once, running freely in the room another time). Would I need some hardware switch or can I try to code it?
There are many ways to do that. Maybe have a startup phase for 5-10 seconds where the robot use the sensor to decide what "program" to run, reading from the sensor those seconds and comparing the value to a certain threshold. With a distance measuring sensor one could make something like this (pseudo):


Code: [Select]
while timer < 10 seconds
{
 //do nothing, just kill time. (maybe some init can be done here)
}

distance = read_sensor();
if(distance>10cm)
{
     random_riot();
}

if(distance <10 cm)
{
     line_follower();
}


.....
function random_riot()
{
.....
}

function line_follower()
{
.....
}

After startup now, you can control how the program reacts by holding something closer than 10 cm or keeping objects further than that distance. There are some disadvantanges to this approach such as using a bigger program then necessary (only one of the "programs"/functions will be run unless they call eachother) but it's a quick brute force non hardware solution.  8)

edit: Added a quote for style... :))
« Last Edit: June 03, 2008, 08:41:17 AM by SixRingz »
Grounding things properly means burying them in the backyard...

Offline ishkaTopic starter

  • Jr. Member
  • **
  • Posts: 38
  • Helpful? 0
Re: Fonctions and priority
« Reply #4 on: June 03, 2008, 08:55:27 AM »
Thx. I could never get this idea  :P Hope my robotic imagination will improve this summer 8)
May the Achtuche be with you...

 


Get Your Ad Here