Shop OBEX P1 Docs P2 Docs Learn Events
How to make alogrith for a artificial intelligence line follower. — Parallax Forums

How to make alogrith for a artificial intelligence line follower.

RITESH KAKKARRITESH KAKKAR Posts: 254
edited 2011-11-10 05:38 in Robotics
hi guys,

I have decided to make a line follower robot which sound easier but viewing the arena of it.
makes me confuse how to make control over robot for deciding the right path as give here in end.


any help will be appreciated,
thanks
962 x 615 - 45K
«13

Comments

  • Martin_HMartin_H Posts: 4,051
    edited 2011-10-25 17:07
    That maze looks amenable to the right hand rule to me. The only tricky bit are the large rectangular areas, but you should be able to tell the robot is over one by the thickness of the region.
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-25 20:21
    The problem for me is how to program in spin which we repeat each instruction again ..............

    Here is my logic:-
    I am using 5 LDR sensors middle 3 will will work for finding the tract and last will triggers at T junction. (0-> black 1-> white)

    1.) Robot will be on tract so 11011
    2.) then 11000
    3.) at T junction 00000 at this instance the robot will move in right side.
    4.) then 11000
    5.) " 00011
    6.) move straight 00000
    7.) move right 00000
    8.) " 00000
    .............................


    like this.
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-26 01:55
    HI again,

    I want a solution regarding repeating loop and testing condition
    for eg:-
    If defied inputs are matched with statement the outputs goes high in one loop but repeating this loop 2nd time the uC should again check this condition and work...

    Till now i have used CASE, IF else statement and waitpeq....they only work once after this they 2nd check condition .

    please reply and figure out the problem.

    NOTE:- I am testing the inputs to uC with DIP not using sensors just for now and all outputs are seen on QS board LED.
  • Martin_HMartin_H Posts: 4,051
    edited 2011-10-26 06:08
    Spin uses the repeat command to loop and it maps onto both for and while loops. So I would suggest reading the Propeller manual as the syntax is fairly rich and I don't remember it off the top of my head.

    You are also going to need to store state within the robot. So for example when it passes the wider part of the line and then it goes narrow the robot knows bot the previous and current reading.
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-26 06:36
    Spin uses the repeat command to loop and it maps onto both for and while loops.

    I have tried repeat instruction at the end of code with any untill,etc...but seems to be no use in my code it was running as it is..!!
    You are also going to need to store state within the robot. So for example when it passes the wider part of the line and then it goes narrow the robot knows bot the previous and current reading.

    Storing and reading current value will not good for beginner (like me)

    Please help.
  • Martin_HMartin_H Posts: 4,051
    edited 2011-10-26 07:01
    Well you could post your code and I could take a look for any errors. But I have limited time so it can't be in depth.

    One thing you might want to consider is spending an evening writing Computer Science 101 programs in Spin until you are confident that you understand the language. Are you familiar with the Parallax serial terminal and the serial monitor on the PC? Here's a hello world with a repeat forever as well:
    CON
             _clkmode       = xtal1 + pll16x
            _xinfreq        = 5_000_000
    
    OBJ
      pst     : "Parallax Serial Terminal" 
      io      : "basic_sio"
    
    PUB start | i, val
    
      pst.Start(115200)    
      pst.str(STRING("Hello World", 13)) 
      repeat
        pst.str(STRING("Hello Again World", 13))
    

    Try a set of simple exercises and constructs until you are comfortable, then try using those skills to solve a robotics problem.
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-26 07:59
    Are you familiar with the Parallax serial terminal and the serial monitor on the PC?

    Not at all.......
    This QS was gifted by Sir Duane of this forum.
  • mindrobotsmindrobots Posts: 6,506
    edited 2011-10-26 08:04
    Ritesh,

    Martin has several good points. You really need to learn programming in general and Spin programming in specific and understand the basics of the language - Computer Science 101. Then you need to start coding a solution to your problem - a line following robot.

    The forum members will be very helpful if you post your code and have questions about it when you get stuck on something. The forum members won't write your code for you and solve all your problems. We had this same problem last time when your were starting to learn Spin and the QuickStart board. I'm not sure what you've learned about Spin programming since then but you do need a basic understanding to get this project started.

    First get your robot so it will follow lines without any intelligence - it just needs to stay on the line and make some decision when it reaches the end of a line. Once it can do this, it can start maze solving and you can build maze solving on top of the working line following algorithms. There is a TON of information you can find via Google about Maze solving algorithms but you need to research it and start writing the code to implement it.
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-26 08:14
    Hi again,

    I have seen the procedure of its working:
    here is the problem
    I was testing my code in uC board itself.....
    I was trying to write code with dozen of case or if else statement and waitpeq ( wait for pin too go as per logic it pause the up i.e. Cog) these all are syntax.

    The code was working well on first attempt mean 1st loop ..after continuing second loop it forget the condition and run on previous value.

    I am using DIP switch which are taking position of LDR sensors just for testing code.!!
    So, problem is that the code should check the condition in every loop and process the output not blind outputs.
  • mindrobotsmindrobots Posts: 6,506
    edited 2011-10-26 08:26
    Put your code in a message or you won't get help. Nobody can solve:
    The code was working well on first attempt mean 1st loop ..after continuing second loop it forget the condition and run on previous value.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-10-26 08:27
    Hi Ritesh,

    The Parallax Serial Termainal (PST) makes it easy to display information from the Propeller chip.

    You might have an icon for PST on your desktop. If not you can find it at:

    Start \ All Programs \ Parallax Inc \ Propeller Tool v1.3 \ Parallax Serial Terminal

    You want to make sure the baud rate is the same in PST as the rate you are using in the Propeller.

    Can you open PST on your computer?

    Duane
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-26 08:33
    Hi again,
    Can you open PST on your computer?

    Yes it has black screen with some txt serial baund rate enable, etc........
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-26 08:36
    It is something like this:-
    VAR
    BYTE A ' DECLARING A VARIABLE NAME

    PUB LINE
    A:=INA[16..20] '16 17 18 19 20 AS INPUTS PINS
    DIRA[16..22]:= % 0000011 ' 0 FOR INPUTS 1 FOR % FOR BINARY DIGIT

    CASE A
    00100: OUTA[21..22] ' MOVE STRAIGHT
    00010: OUTA[21] ' MOVE RIGHT
  • FranklinFranklin Posts: 4,747
    edited 2011-10-26 08:40
    You need to supply ALL your code as a complete program wrapped in "CODE" tags so the indenting (important in spin code) remains intact.
    If you won't help us we can't help you.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-26 09:50
    Follow the instructions here for posting code:


    attachment.php?attachmentid=78421&d=1297987572
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-10-26 10:06
    The code tags are very important since Spin uses indentation as syntax.
    VAR
    
      BYTE A ' DECLARING A VARIABLE NAME
    
    PUB LINE 
    
      DIRA[16..22]:= %0000011 ' 0 FOR INPUTS 1 FOR % FOR BINARY DIGIT 
    
      REPEAT
        A := INA[16..20] '16 17 18 19 20 AS INPUTS PINS
        CASE A
          %00100: OUTA[21..22] := %11 ' MOVE STRAIGHT
          %00010: OUTA[21] := 0 ' MOVE RIGHT
    

    Both REPEAT and CASE use the indentation to know what to repeat and what items belong to the CASE statement.

    Please notice the added := and %. I don't think your code would work without them.

    Duane
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-26 21:26
    [code]CON
      Delay = 1_000_000
      x =20
    VAR
     BYTE A
    PUB Toggle
      dira[16..22]:=%0000011           { 16..20 are for sensors now iam using DIP switch for testing}
      A:=INA [16..20]
        
      CASE A
    
        %00100:
         repeat 10
            !outa[21..22]               {21..22 are the output for motor}
              waitcnt( delay + cnt)
    
        %00011:
          repeat 10
            !outa[21]
            waitcnt(delay + cnt)
            
                            
        
                 
    
    [/code]

    I was on another PC so i was late to post code.
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-26 21:39
    I will use 2 motors of 375RPM and Li..battery......
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-10-26 22:46
    Ritesh,

    What are you using to control the motor?

    I often use these H-bridge chips to control relatively small motors. I couldn't find any H-bridge chips at the robokits.co.in.

    You could also use relays to turn motors on and off.

    Did you notice that "A := INA[16..20]" is checked with each loop in the code I wrote?

    Duane
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-27 04:09
    Did you notice that "A := INA[16..20]" is checked with each loop in the code I wrote?
    `

    HI again,

    That mean now it will work fine??
    please tell me how to place REPEAT in code??
    What are you using to control the motor?

    I was thinking to use transistor at one side only not bidirectional method of H bridge and is there any need of buffer chip at output of uC i.e. QS board??


    and you were talking about serial transfer....how to use it ??
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-27 04:14
    Here is my hand drawn sketch of robot please feel free to remove mechanical error the size should not exceed 24Cm x 24CM it can be small.
    1024 x 768 - 66K
  • Heater.Heater. Posts: 21,230
    edited 2011-10-27 06:18
    Ritesh,
    If you are really having problems with knowing how to use repeat in your code I do urge that you forget about any kind of robot or artificial inteligence for a while. Instead spend some time learning about programming first. There are many tutorials, examples and so on out there. Starting with the Propeller manual itself.
    Everyone starts with the simple things, like flashing a single LED using repeat. Then moving up to more complicated programs.
    You have to know the basics of the language, in this case Spin, and how to use it before you can get on with "algorithms" and robots and AI or whatever it is you want to do.
    As always, everyone here is quite willing to help even if you are stuck at the flash a LED stage.
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-27 06:31
    Everyone starts with the simple things, like flashing a single LED using repeat. Then moving up to more complicated programs.
    You have to know the basics of the language, in this case Spin, and how to use it before you can get on with "algorithms" and robots and AI or whatever it is you want to do.
    As always, everyone here is quite willing to help even if you are stuck at the flash a LED stage.

    OK OK, so it was same REPEAT instruction as i have it any time sorry i was confused i know if it is written like this
    repeat 10
    for flashing LED the LED will work for 5 cyles...

    Sorry for confusing.
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-27 07:19
    I have done some changes in my code it is working perfectly..
    thanks.
    CON
    Delay = 100_000
    x =20
    VAR
    BYTE A
    PUB Toggle
    dira[16..22]:=%0000011 { 16..20 are for sensors now iam using DIP switch for testing}
    repeat
    A:=INA [16..20]
    CASE A

    %00100:
    repeat 2
    !outa[21..22] {21..22 are the output for motor}
    waitcnt( delay + cnt)

    %10100:
    repeat 2
    !outa[21]
    waitcnt(delay + cnt)

    %10000:
    repeat 2
    !outa[22]
    waitcnt(delay + cnt)
    %00000:
    repeat 2
    !outa[21..22]
    waitcnt(delay + cnt)
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-28 04:43
    The Parallax Serial Termainal (PST) makes it easy to display information from the Propeller chip.

    You might have an icon for PST on your desktop. If not you can find it at:

    Start \ All Programs \ Parallax Inc \ Propeller Tool v1.3 \ Parallax Serial Terminal

    You want to make sure the baud rate is the same in PST as the rate you are using in the Propeller.

    Can you open PST on your computer?

    Hi again,

    Please help me to how to use this serial transfer data??
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-28 05:35
    Here is some CAD images please tell any changes to do........
    1024 x 768 - 74K
    1024 x 768 - 69K
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-10-29 19:02
    and you were talking about serial transfer....how to use it ??
    Duane Degn wrote: »
    Can you open PST on your computer?

    There is more about serial tranfer on page 97 of the Propeller Education Kit (available from the help menu of the Propeller Tool).

    Duane
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-29 21:48
    HI again,

    It was something like CTRA instruction give any hint to start it.......
    one thing more the motor i bot was of 375 RPM which is pretty fast for an line follower without any PID control so i want PWM to control RPM of motor
    can we use PID control in propeller chip??
  • Heater.Heater. Posts: 21,230
    edited 2011-10-30 01:07
    Yes, of course. Write your own or I think you will find PID object(s) in the OBEX.
  • RITESH KAKKARRITESH KAKKAR Posts: 254
    edited 2011-10-30 01:35
    Yes, of course. Write your own

    any hint will be useful..
    I think you will find PID object(s) in the OBEX
    .

    What is OBEX??
Sign In or Register to comment.