Shop OBEX P1 Docs P2 Docs Learn Events
Stingray 3 Ping Demo — Parallax Forums

Stingray 3 Ping Demo

BocephusBocephus Posts: 58
edited 2010-02-16 08:08 in Robotics
In the Stingray Demo using the 3 pings I am curious to know which ping is in which part of the Distance variable. If I stand behind the stingray, facing the front of the robot, I identify Distance[noparse][[/noparse]0] as Right ping, 1 as Center, and 2 as Left. Is this correct?

As a learning exercise I have been converting what I figure I need of the ping object code and the demo ping code into asm. I realized my ping setup is 0-Right, 1-Left, 2-Center. I also don't understand some of the divisions for the ticks of the ping in the stingray demo and simply chose a >> 7 in place of them to see if it would still work. It does! If you notice any errors or bad habits please let me know. I'm really enjoying learning about the Propeller and playing with the Stingray!

DAT
        org
pings   mov     t1,#1           ' Configure Pin       right side pin 0
        andn    outa,t1         ' PreSet DataPin LOW     
        or      dira,t1         ' Set DataPin to an OUTPUT
        or      outa,t1         ' set HIGH 
        
        mov     time,cnt        ' need 2-5 us delay
        add     time,delay
        waitcnt time,delay        
        
        andn    outa,t1         ' clear pin
        andn    dira,t1         ' set pin to INPUT
        waitpne :null,t1        ' wait for pin to go HIGH
        
        mov     cnt1,cnt        ' store count
        waitpeq :null,t1        ' wait for pin to go LOW
        
        mov     cnt2,cnt        ' store count2
        sub     cnt1,cnt2       ' calculate ping time
        abs     cnt2,cnt1
        shr     cnt2,#7
        mov     addr,par                             
        wrlong  cnt2,addr       
        
        'second ping              left side pin 1
        shl     t1,#1
        andn    outa,t1         
        or      dira,t1         
        or      outa,t1         

        mov     time,cnt        
        add     time,delay
        waitcnt time,delay       
        
        andn    outa,t1         
        andn    dira,t1      
        waitpne :null,t1
              
        mov     cnt1,cnt          
        waitpeq :null,t1
              
        mov     cnt2,cnt        
        sub     cnt1,cnt2
        abs     cnt2,cnt1
        shr     cnt2,#7
        
        add     addr,#4         ' move to next long
        wrlong  cnt2,addr  
        
        'third ping               center pin 2
        shl     t1,#1
        andn    outa,t1                                              
        or      dira,t1         
        or      outa,t1        

        mov     time,cnt        '
        add     time,delay
        waitcnt time,delay       
        
        andn    outa,t1         
        andn    dira,t1         
        waitpne :null,t1
        
        mov     cnt1,cnt        
        waitpeq :null,t1
           
        mov     cnt2,cnt        
        sub     cnt1,cnt2
        abs     cnt2,cnt1
        shr     cnt2,#7
        
        add     addr,#4         ' move to next long
        wrlong  cnt2,addr   
     
        jmp     #pings
        
:null long 0
delay long 160
t1    res  1
cnt1  res  1
cnt2  res  1
addr  res  1
time  res  1

Comments

  • BocephusBocephus Posts: 58
    edited 2010-01-04 16:44
    Well, being new to hardware stuff and microcontrollers in general, I can't seem to figure out my IR issue in the other thread, so I came back to play with the assembler for the three pings. I left it unrolled so I can integrate other sensors into the loop more easily, plus I like fast stuff.

    VAR
    
      long  Distance[noparse][[/noparse] 3 ]
    
    PUB main 
    
      cognew(@pings, @Distance)
    
    DAT
                  org
    pings         mov     t1,#1           ' first ping, right side pin 0    
                  or      dira,t1         ' Set pin to output
                  or      outa,t1         ' set high 
            
                  mov     time,cnt        ' need 2-5 us delay
                  add     time,delay
                  waitcnt time,delay        
            
                  andn    outa,t1         ' clear pin
                  andn    dira,t1         ' set pin to input
                  waitpne :null,t1        ' wait for pin to go high
            
                  mov     cnt1,cnt        ' store count
                  waitpeq :null,t1        ' wait for pin to go low
            
                  mov     cnt2,cnt        ' store count2
                  sub     cnt2,cnt1       ' calculate ping time
                  shr     cnt2,#7
            
                  mov     addr,par        ' get variable address                     
                  wrlong  cnt2,addr       ' write ping time
            
                  'second ping              left side pin 1
                  shl     t1,#1        
                  or      dira,t1         
                  or      outa,t1         
    
                  mov     time,cnt        
                  add     time,delay
                  waitcnt time,delay       
            
                  andn    outa,t1         
                  andn    dira,t1      
                  waitpne :null,t1
                  
                  mov     cnt1,cnt          
                  waitpeq :null,t1
                  
                  mov     cnt2,cnt        
                  sub     cnt2,cnt1   
                  shr     cnt2,#7
            
                  add     addr,#4         ' move to next long
                  wrlong  cnt2,addr  
            
                  'third ping               center pin 2
                  shl     t1,#1                                               
                  or      dira,t1         
                  or      outa,t1        
    
                  mov     time,cnt        '
                  add     time,delay
                  waitcnt time,delay       
            
                  andn    outa,t1         
                  andn    dira,t1         
                  waitpne :null,t1
            
                  mov     cnt1,cnt        
                  waitpeq :null,t1
               
                  mov     cnt2,cnt        
                  sub     cnt2,cnt1
                  shr     cnt2,#7
            
                  add     addr,#4         ' move to next long
                  wrlong  cnt2,addr   
         
                  jmp     #pings
            
    :null   long  0
    delay   long  160
    t1      res   1
    cnt1    res   1
    cnt2    res   1
    addr    res   1
    time    res   1
    
  • rpdbrpdb Posts: 101
    edited 2010-02-06 03:32
    Hi Bocephus,

    I just ran across your ping code in pasm. Looks good. I am going to go try it out. I do also like how fast asm runs.

    You seem to have a good handle on it from what I see. Have you been programming in assembler long? I learned on the intel 8080 way back in the mid 1980s, and am just now relearning asm on the propeller. Are you using PASD for debugging or what do you use?

    I don't have a stingray, but I am using the MRS1 board and have 3 pings, so the code applies.

    Did you find a solution for your IRs? I am working on some for a look down/forward sensor to detect drop offs, curbs and such.
  • BocephusBocephus Posts: 58
    edited 2010-02-06 06:38
    Hey rpdb, I looked at my most recent spin file and I rolled the code into a callable routine since this one. I'll attach my current stingray code for you to try. You can comment out or delete what you don't need.

    As a hobby, I programmed in x86 assembler for several years, but it has been a few years since I have coded anything, until I stumbled upon the Propeller chip. I always wanted to get into electronics, robotics, and microcontrollers, and this interesting chip gave me the excitement to get started. My programming is very rusty, and things take a while to sink in for me sometimes, but I prefer to program in assembler. It makes more sense to me and is easier for me than other languages. I learned what I know of pasm from the manual and DeSilva's excellent pasm tutorial. I'm still learning more every day.

    I do use PASD for debugging and it is a fine tool.

    As for the IR, I realized I will have to solder the expensive board to bypass the level translators and I am uncomfortable with this task. When I am more confident in my soldering skills I will give it a go. Hopefully I will get some time for practice this weekend since my XBee's arrived.

    This is all new to me but lots of fun!
  • WhitWhit Posts: 4,191
    edited 2010-02-06 13:46
    Hey Becephus,

    To test you IR (just be sure that this is what you really need to do if you are going to bypass)·you could bypass the level translators with a small piece of jumper wire. I know this is not a permanent solution, but it should work okay for a test.

    A better solution would be to get header (see here - http://www.parallax.com/Store/Components/WireConnection/tabid/151/CategoryID/29/List/0/SortField/0/Level/a/ProductID/487/Default.aspx ) Break off two pins (they are made to do this - notched at each pin). Put it in the place for the holes at the bypass on one or all of the sets. On the underside of the board you could splay (push out) the pins so that it holds nicely in place. On the top side you could use a slide on jumper. All this could be easily removed. When you are more confident, you can permenantly attach it. See pics attached.

    Hope this helps!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Whit+


    "We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths." - Walt Disney

    Post Edited (Whit) : 2/6/2010 2:08:25 PM GMT
    803 x 550 - 27K
    667 x 500 - 34K
    667 x 500 - 33K
  • BocephusBocephus Posts: 58
    edited 2010-02-06 18:44
    Hey Whit,

    I reckon this is what someone, CannibalRobotics I think, did in the IR thread to verify it worked correctly that way.

    Thanks for the explanation, pics, and details! I'll add some headers with my next order and try it out.
  • rpdbrpdb Posts: 101
    edited 2010-02-06 22:35
    Hi Bocephus,
    I picked up a pair of IR detectors last week as well as some emitters. I want to make a small board with some headers for easy connections with one mounting hole. I got access to a circuit board mill, but have to work out the schematics --> drawings -->routing --> dxf.file --> ISOPro --> for milling etc. and the mechanical mounting to allow adjustments. I would like to make something standard that all could use. Any input from all is welcome. If the proto type has support I would get them printed and divide the cost. What Ir detectors emitters do you have and Specs? I'll compare to what I have.
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2010-02-07 02:08
    Why can't the IR detection stuff worth through the translators? Has Chris or one of the other Parallax folks chimed in on the issue?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out the Propeller Wiki·and contribute if you can.
  • BocephusBocephus Posts: 58
    edited 2010-02-07 19:32
    rpdb, I have the IR LED / receiver from Parallax.

    Roy, I am not sure really. Then best I could gather is that there may be too much resistance in the translators for the IR to work. I don't think Parallax chimed in, but I know this is an intermediate level bot, and my skills are not at that level, so I don't bother them. You and the other forum members have helped me tremendously with my beginner questions and I am thankful for that!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-02-09 21:28
    Without seeing how you're driving the IR system (how it is connected) I can't answer for what the issue may be, however we are currently compiling feedback on various issues regarding the Stingray and deciding on possible solutions, even if it means making some changes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    Check out the new Savage Circuits TV!
    ·
  • BocephusBocephus Posts: 58
    edited 2010-02-09 22:27
    Chris, here is a link with an explanation and pics. http://forums.parallax.com/forums/default.aspx?f=10&m=414262
  • BocephusBocephus Posts: 58
    edited 2010-02-16 02:16
    Phil Pilgrim brought up in another thread that well written code would not rely on using certain pin assignments for the pings. This is true of course and my code relied heavily on this assumption. So to please the masses, and to become a better coder, I updated my pasm code with comments on usage. Hopefully we will only have to change the number of pings variable (tot_pings), when/if we move to the ten ping robot. As long as the pings are on consecutive pins, any pins may be used. Comments, corrections and suggestions are welcome and I'll try real hard not to resurrect this thread again. lol.gif
  • rpdbrpdb Posts: 101
    edited 2010-02-16 08:08
    The comment section at the very begining of this code states that it is to control two HB25s, but the code has been modified to use the PWM.DutyCycle method to control the LT6205 H-Bridge chip on the MSR1 board on Pins[noparse][[/noparse]24..27] instead.

    Do you have a copy of the code that was for the HB25s before it was modified?
Sign In or Register to comment.