Shop OBEX P1 Docs P2 Docs Learn Events
Spin Code Help — Parallax Forums

Spin Code Help

p00ndawgp00ndawg Posts: 70
edited 2010-06-24 01:44 in Propeller 1
 

[b]pub forward
         ' forward movement

PulsOut(0, 1_600)
PulsOut(23, 1_600) [/b] 
                                 


pub right_turn

PulsOut(0, 1_300)
PulsOut(23, 1_620)
                      

pub left_turn

PulsOut(0, 1_620)
PulsOut(23, 1_300)

pub stop

PulsOut(23, 1_475)
PulsOut(0, 1_500)

pri Pause(duration)

  'This function pauses program execution for approximately [noparse][[/noparse]duration] micro seconds
  'so 1_000_000 would be approximately one second.  Doesnt account for instruction
  'execution time overhead.

  if duration < 381
    duration := 381             'lower bound limit. anything lower than this, we
                                'have to wait until the counter comes back around,
                                'which is MUCH longer than [noparse][[/noparse]duration].
  waitcnt(((clkfreq / 1_000_000) * duration) + cnt)

  
[b]pri PulsOut(pin, duration)

  'similar to the BS2 command.  This function pulses the [noparse][[/noparse]pin] for [noparse][[/noparse]duration].
  'This is extremely useful for controlling servos and speed controllers.
  
  dira[noparse][[/noparse]pin]~~      'make pin an output
  outa[noparse][[/noparse]pin]~~      'make pin go high            
  waitcnt(((clkfreq / 1_000_000) * duration) + cnt)  'pause execution
  outa[noparse][[/noparse]pin]~       'make pin go low
[/b]

pri pulsin(pin) : time | cnt1, cnt2

  dira[noparse][[/noparse]Pin]~                                                                    ' Make I/O Pin Input
  waitpne(0, |< Pin, 0)                                                         ' Wait For Pin To Go HIGH
  cnt1 := cnt                                                                   ' Store Current Counter Value
  waitpeq(0, |< Pin, 0)                                                         ' Wait For Pin To Go LOW 
  cnt2 := cnt 
  time := (||(cnt1 - cnt2) / (clkfreq / 1_000_000))



im using this for movement using the msr1 and the 2 hb 25's connected to two motors, although as another user mentioned to me my pulsout method gets stuck in a counter rollover.

I have used these variations of the pulsout method,
pub pulsout(pin, duration) 

  duration := (duration * (clkfreq / 1_000_000)) #> 381

  dira[noparse][[/noparse]pin]~~
  !outa[noparse][[/noparse]pin]
  waitcnt(duration)
  !outa[noparse][[/noparse]pin]


pub pulsout(pin, us)

  if (pin => 0) and (pin =< 31) and (us > 0)
    us := (clkfreq / 1_000_000 * us) #> 381
    outa[noparse][[/noparse]pin]~~
    !dira[noparse][[/noparse]pin]
    waitcnt(us + cnt) 
    !dira[noparse][[/noparse]pin]



with little success. The 2nd pulsout however, executes all the code I have set up it just doesnt actually move the wheels. The other versions tend to get stuck the first time I call forward and never continue.

Post Edited (p00ndawg) : 6/21/2010 5:21:27 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-06-21 15:02
    I think your problem is that each pulsout routine you've shown has a major error in it.

    In the first, you've got WAITCNT(duration). That can't work because WAITCNT doesn't use a duration, it uses an absolute time (system clock value). You'd have to use WAITCNT(cnt + duration).

    In the second, you're toggling the I/O pin between high (1) and input. That would work if the I/O pin had a pulldown resistor, but I don't think that's the way things are set up.
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-21 15:19
    In the second method I tried


    pub pulsout(pin, us)
    
    if (pin => 0) and (pin =< 31) and (us > 0)
        us := (clkfreq / 1_000_000 * us) #> 381
       dira[noparse][[/noparse]pin]~~      'make pin an output
      outa[noparse][[/noparse]pin]~~      'make pin go high            
      waitcnt(us + cnt)  'pause execution
      outa[noparse][[/noparse]pin]~
    



    same result as others.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-06-21 15:26
    You do need some delay between the pulses. I don't know what the minimum delay might be. You'll have to get that from the documentation or just experiment. I suspect that you need several milliseconds' delay at a minimum. Try a WAITCNT(CLKFREQ/100 + CNT) between PULSOUT calls.
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-21 17:02
    ok I got it working with the WAITCNT. It executes for awhile but eventually there is still a counter rollover and it gets stuck in my default call of the forward method.


    pub forward 
    'pin 0 = left wheel pin 23 = right wheel
    WAITCNT(CLKFREQ/100 + CNT)
    PulsOut(0, 1_600)
    WAITCNT(CLKFREQ/100 + CNT)
    PulsOut(23, 1_600)
    
    
    
    pri pulsout(pin, us)
    
    if (pin => 0) and (pin =< 31) and (us > 0)
      us := (clkfreq / 1_000_000 * us) #> 381
      dira[noparse][[/noparse]pin]~~      'make pin an output
      outa[noparse][[/noparse]pin]~~      'make pin go high            
      waitcnt(us + cnt)  'pause execution
      outa[noparse][[/noparse]pin]~
    

    Post Edited (p00ndawg) : 6/21/2010 5:09:54 PM GMT
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-21 18:53
    pri pulsout(pin, us)
    
    us := (clkfreq / 1_000_000 * us)
    
    if (clkfreq / 1_000_000 * us) < 381
      us := 381
      dira[noparse][[/noparse]pin]~~      'make pin an output
      outa[noparse][[/noparse]pin]~~      'make pin go high
      waitcnt((clkfreq / 1_000_000 * us)  + cnt)  'pause execution
      outa[noparse][[/noparse]pin]~
      
    else
      dira[noparse][[/noparse]pin]~~      'make pin an output
      outa[noparse][[/noparse]pin]~~      'make pin go high
      waitcnt(us + cnt)  'pause execution
      outa[noparse][[/noparse]pin]~
    



    tried this as well, was sure it would work and it didnt. Still getting a massive stall in execution when waiting for the system counter.
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-06-21 19:04
    the minimum delay is 385 not 381

    best regards

    Stefan
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-21 19:18
    "This means the value of offset must always be at least 381 to avoid unexpectedly long delays."

    I just pulled this quote from the propellor manual. is the manual wrong?
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-21 21:18
    PUB start
       
       servo.start  
       cognew(sensor_scan, @stack)
       cognew(movement_class,@stack1)
               
    
    
       
    pub movement_class ' will scan and turn away else it will move forward with pulsout 1600
      
      forward
       
      repeat
      
        if inch1 < distance
           inches := inch1
           right_turn
           pause(758_333)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600)     
        
        if inch2 < distance
           inches := inch2
           right_turn
           pause(379_166)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600)     
          
        if inch3 < distance
          inches := inch3
          left_turn
          pause(2_275_000)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600) 
              
        if inch4 < distance
           inches := inch4
           left_turn
           pause(379_166)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600) 
                    
        if inch5 < distance
           inches := inch5
           left_turn
           pause(758_333)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600) 
                   
        if inch6 < distance_back
           inches := inch6
           left_turn
            pause(1_516_666)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600)   
       
        if inch7 < distance_back
           inches := inch7
          left_turn
          pause(1_895_833) 
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600)        
    
        if inch8 < distance_back
           inches := inch8
           left_turn  
            pause(2_275_000)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600) 
               
        if inch9 < distance_back
           inches := inch9
           right_turn
           pause(1_516_666)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600)       
             
        if inch10 < distance_back
           inches := inch10
           right_turn
           pause(1_895_833)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600)   
        
    
    pub forward
     
    'pin 0 = left wheel pin 23 = right wheel
    pause(10_000)
    PulsOut(0, 1_600)
    pause(10_000)  
    PulsOut(23, 1_600)
    
    pub right_turn
    
    pause(10_000)     
    PulsOut(0, 1_300)
    pause(10_000)  
    PulsOut(23, 1_620)
                          
    
    pub left_turn
    pause(10_000)  
    PulsOut(0, 1_620)
    pause(10_000)  
    PulsOut(23, 1_300)
    
    pub stop
    
    pause(10_000)  
    PulsOut(23, 1_475)
    pause(10_000)  
    PulsOut(0, 1_500)  
    
    
    PUB sensor_scan  'scanning of ping sensors
         
      repeat
       inch1 := ping.Inches(pin1)                                            'change time to distance in inches 
       inch2 := ping.Inches(pin2)
       inch3 := ping.Inches(pin3)                                            'change time to distance in inches 
       inch4 := ping.Inches(pin4)
       inch5 := ping.Inches(pin5)                                            'change time to distance in inches 
       inch6 := ping.Inches(pin6)
       inch7 := ping.Inches(pin7)                                            'change time to distance in inches 
       inch8 := ping.Inches(pin8)
       inch9 := ping.Inches(pin9)                                            'change time to distance in inches 
       inch10 := ping.Inches(pin10)
      
                                  
    pri Pause(duration)
    
      'This function pauses program execution for approximately [noparse][[/noparse]duration] micro seconds
      'so 1_000_000 would be approximately one second.  Doesnt account for instruction
      'execution time overhead.
      
      if duration < 381
       duration := 381             'lower bound limit. anything lower than this, we
                                    'have to wait until the counter comes back around,
                                    'which is MUCH longer than [noparse][[/noparse]duration].
      waitcnt(((clkfreq / 1_000_000) * duration) + cnt)
    
    
    pri PulsOut(pin, duration)
    
      'similar to the BS2 command.  This function pulses the [noparse][[/noparse]pin] for [noparse][[/noparse]duration].
      'This is extremely useful for controlling servos and speed controllers.
      'To constantly make a servo move, you have to constantly be calling this
      'function (I.E. you cant set a value and have the servo stay at that value)
      
    
    pri pulsout(pin, us)
    
    if (pin => 0) and (pin =< 31) and (us > 0)
      us := (clkfreq / 1_000_000 * us) #> 381
      dira[noparse][[/noparse]pin]~~      'make pin an output
      outa[noparse][[/noparse]pin]~~      'make pin go high            
      waitcnt(us + cnt)  'pause execution
      outa[noparse][[/noparse]pin]~
    
    



    ok now im getting a little annoyed.
    Here is my full code. Another one of my group members here came and loaded up his code which provided similar functionality to mine, using the pulsout and pause methods provided, and he got no code stalling.

    is there something that anyone can quickly see that I am not?

    Post Edited (p00ndawg) : 6/21/2010 10:25:29 PM GMT
  • hover1hover1 Posts: 1,929
    edited 2010-06-21 22:51
    That's your FULL code? No VAR, CON, Object declarations?
    p00ndawg said...
    ok now im getting a little annoyed.
    Here is my full code. Another one of my group members here came and loaded up his code which provided similar functionality to mine, using the pulsout and pause methods provided, and he got no code stalling.
    
    is there something that anyone can quickly see that I am not?
    

  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-22 00:15
    CON
    _clkmode = xtal1 + pll16x      ' Crystal feedback & PLL multiplier
    _xinfreq = 5_000_000
    
    CON
    pin1 = 1                       ' All the ping pins
    pin2 = 2
    pin3 = 3                       ' All the ping pins
    pin4 = 4
    pin5 = 5                       ' All the ping pins
    pin6 = 6
    pin7 = 7                       ' All the ping pins
    pin8 = 8
    pin9 = 9                       ' All the ping pins
    pin10 = 10
    distance = 18
    
    
    VAR
    
      ' Global Variables:
      
      long inch1
      long inch2
      long inch3
      long inch4
      long inch5
      long inch6
      long inch7
      long inch8
      long inch9
      long inch10
    long stack[noparse][[/noparse]20]
    long stack1[noparse][[/noparse]20]
     
    long inches
     
      
    OBJ
    
      ping:  "Ping"
     servo : "servo32v5"
    
    
    PUB start
       
       servo.start  
       cognew(sensor_scan, @stack)
       cognew(movement_class,@stack1)
               
    
    
       
    pub movement_class ' will scan and turn away else it will move forward with pulsout 1600
      
      forward
       
      repeat
      
        if inch1 < distance
           inches := inch1
           right_turn
           pause(758_333)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600)     
        
        if inch2 < distance
           inches := inch2
           right_turn
           pause(379_166)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600)     
          
        if inch3 < distance
          inches := inch3
          left_turn
          pause(2_275_000)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600) 
              
        if inch4 < distance
           inches := inch4
           left_turn
           pause(379_166)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600) 
                    
        if inch5 < distance
           inches := inch5
           left_turn
           pause(758_333)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600) 
                   
        if inch6 < distance_back
           inches := inch6
           left_turn
            pause(1_516_666)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600)   
       
        if inch7 < distance_back
           inches := inch7
          left_turn
          pause(1_895_833) 
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600)        
    
        if inch8 < distance_back
           inches := inch8
           left_turn  
            pause(2_275_000)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600) 
               
        if inch9 < distance_back
           inches := inch9
           right_turn
           pause(1_516_666)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600)       
             
        if inch10 < distance_back
           inches := inch10
           right_turn
           pause(1_895_833)
        else
          PulsOut(0, 1_600)
          PulsOut(23, 1_600)   
        
    
    pub forward
     
    'pin 0 = left wheel pin 23 = right wheel
    pause(10_000)
    PulsOut(0, 1_600)
    pause(10_000)  
    PulsOut(23, 1_600)
    
    pub right_turn
    
    pause(10_000)     
    PulsOut(0, 1_300)
    pause(10_000)  
    PulsOut(23, 1_620)
                          
    
    pub left_turn
    pause(10_000)  
    PulsOut(0, 1_620)
    pause(10_000)  
    PulsOut(23, 1_300)
    
    pub stop
    
    pause(10_000)  
    PulsOut(23, 1_475)
    pause(10_000)  
    PulsOut(0, 1_500)  
    
    
    PUB sensor_scan  'scanning of ping sensors
         
      repeat
       inch1 := ping.Inches(pin1)                                            'change time to distance in inches 
       inch2 := ping.Inches(pin2)
       inch3 := ping.Inches(pin3)                                            'change time to distance in inches 
       inch4 := ping.Inches(pin4)
       inch5 := ping.Inches(pin5)                                            'change time to distance in inches 
       inch6 := ping.Inches(pin6)
       inch7 := ping.Inches(pin7)                                            'change time to distance in inches 
       inch8 := ping.Inches(pin8)
       inch9 := ping.Inches(pin9)                                            'change time to distance in inches 
       inch10 := ping.Inches(pin10)
      
                                  
    pri Pause(duration)
    
      'This function pauses program execution for approximately [noparse][[/noparse]duration] micro seconds
      'so 1_000_000 would be approximately one second.  Doesnt account for instruction
      'execution time overhead.
      
      if duration < 381
       duration := 381             'lower bound limit. anything lower than this, we
                                    'have to wait until the counter comes back around,
                                    'which is MUCH longer than [noparse][[/noparse]duration].
      waitcnt(((clkfreq / 1_000_000) * duration) + cnt)
    
    
    pri PulsOut(pin, duration)
    
      'similar to the BS2 command.  This function pulses the [noparse][[/noparse]pin] for [noparse][[/noparse]duration].
      'This is extremely useful for controlling servos and speed controllers.
      'To constantly make a servo move, you have to constantly be calling this
      'function (I.E. you cant set a value and have the servo stay at that value)
      
    
    pri pulsout(pin, us)
    
    if (pin => 0) and (pin =< 31) and (us > 0)
      us := (clkfreq / 1_000_000 * us) #> 381
      dira[noparse][[/noparse]pin]~~      'make pin an output
      outa[noparse][[/noparse]pin]~~      'make pin go high            
      waitcnt(us + cnt)  'pause execution
      outa[noparse][[/noparse]pin]~
    
    
    



    this is all of it sorry
  • hover1hover1 Posts: 1,929
    edited 2010-06-22 00:48
    In the future, you should·use the attachment manager and make an archive file with the propeller tool. That would include all the other objects used in your program.

    Sometimes those other objects are changed by mistake, and render your program unusable. It would help to diagnose the problem.

    Also, when posting code on the forum page, the forum software will sometimes corrupt the code when using the· "code tags".

    Jim


    ·

    Post Edited (hover1) : 6/22/2010 12:54:16 AM GMT
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-22 00:54
    oh ok thanks. Ill post one tomorrow morning, I am no longer at my lab.

    Thanks for the tip.
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-06-22 00:57
    I think you are refreshing the HB-25 too frequently. This is from the documentation:

    There is a hold-off time of 5 ms where the HB-25 will ignore incoming pulses. As a result, the unit should
    not be refreshed more frequently than about 5.25 ms + pulse time. Pulse time can be anywhere from
    0.8 ms to 2.2 ms. If the HB-25 receives a pulse outside of this range, it will temporarily shut off the
    motor until it receives a valid pulse.

    We still don't have all of you code. distance_back is not defined. If all the ping distances are greater than distance/distance_back you will send pulses too fast to the HB-25s. Instead of the PulsOuts in the else sections, call Forward I would change Forward to

    pub forward
    'pin 0 = left wheel pin 23 = right wheel
    PulsOut(0, 1_600)
    PulsOut(23, 1_600)
    pause(10_000)

    John Abshier
  • Mike GreenMike Green Posts: 23,101
    edited 2010-06-22 00:57
    Try making the stack areas bigger. 20 may be marginal. Try at least 30.

    Make the minimum pulse width or minimum pause = 400. Servos won't respond to anything less than 500us anyway.

    In what you've posted you have two declarations for pulsout since Spin ignores case. I don't know why the compiler didn't flag it.
  • hover1hover1 Posts: 1,929
    edited 2010-06-22 00:59
    I wish all my Parallax stuff wasn't packed away right now for a move, or I would fire it up to help further.
    Jim

    Darn Mike, I was going to mention the stack, but I got distracted.



    Post Edited (hover1) : 6/22/2010 1:13:26 AM GMT
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-22 17:14
    i havent tried the top few suggestions yet but i am posting my current code as described by hover.
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-22 17:35
    ok I tried added in those pauses and it seems to have helped and it ran for a good 2 minutes before eventually it got stuck moving in the last called move function and stopped pinging the sensors.

    I also replaced all the pulses with proper functions for right, left, and forward.



    pub movement_class
         
      repeat
      
        if inch1 < distance
           inches := inch1
           pause(10_000)  
           right_turn  'right
           pause(758_333)
        else
         forward
        
        if inch2 < distance
           inches := inch2
           pause(10_000)  
           right_turn
           pause(379_166)
        else
         forward
          
        if inch3 < distance
          inches := inch3
          pause(10_000)  
          left_turn  'left
          pause(2_275_000)
        else
         forward
         
        if inch4 < distance
           inches := inch4
           pause(10_000)  
           left_turn  'left
           pause(379_166)
        else
         forward
        if inch5 < distance
           inches := inch5
           pause(10_000)  
           left_turn   'left
           pause(758_333)
        else
         forward         
        if inch6 < distance_back
           inches := inch6
           pause(10_000)  
           left_turn   'left
           pause(1_516_666)
        else
         forward
       
        if inch7 < distance_back
          inches := inch7
          pause(10_000)  
          left_turn   'left
          pause(1_895_833) 
        else
         forward
    
        if inch8 < distance_back
           inches := inch8
           pause(10_000)  
           left_turn   'left
            pause(2_275_000)
        else
         forward
         
        if inch9 < distance_back
           inches := inch9
           pause(10_000)  
           right_turn 'right  
           pause(1_516_666)
        else
         forward
             
        if inch10 < distance_back
           inches := inch10
           pause(10_000)  
           right_turn 'right  
           pause(1_895_833)
        else
         forward
         
     
    
    
    
    PUB sensor_scan  
         
      repeat
       inch1 := ping.Inches(pin1)                                            'change time to distance in inches 
       inch2 := ping.Inches(pin2)
       inch3 := ping.Inches(pin3)                                            'change time to distance in inches 
       inch4 := ping.Inches(pin4)
       inch5 := ping.Inches(pin5)                                            'change time to distance in inches 
       inch6 := ping.Inches(pin6)
       inch7 := ping.Inches(pin7)                                            'change time to distance in inches 
       inch8 := ping.Inches(pin8)
       inch9 := ping.Inches(pin9)                                            'change time to distance in inches 
       inch10 := ping.Inches(pin10)
      
    pub forward
     
    'pin 0 = left wheel pin 23 = right wheel
    pause(10_000)  
    PulsOut(0, 1_600)
    PulsOut(23, 1_600)
    pause(10_000)  
    pub right_turn
    
    pause(10_000)      
    PulsOut(0, 1_300)
    PulsOut(23, 1_620)
    pause(10_000)                        
    
    pub left_turn
    pause(10_000)  
    PulsOut(0, 1_620)
    PulsOut(23, 1_300)
    pause(10_000)  
    pub stop
    
    pause(10_000)  
    PulsOut(23, 1_475)
     PulsOut(0, 1_500)  
    pause(10_000)       
    
    
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-06-22 19:44
    What happens when cog 0 finishes? Add the following line to Start and see what happens

    repeat

    I couldn't find in in the manual but I found in a PE Lab that the other cogs continue running.

    Making people finde part of the code in the zip file and another part of the code in the post is not conductive to getting help.

    However, the logic of you program probably doesn't work as you thing. Assume that inch1 is > distance and inch2 is < distance. I think you want to turn right. But what you will do is go forward then turn right. I think what you want is (summarized pseudo code)

    if inches1 < distance
    right_turn
    elseif inches2 < distance
    right_turn
    ...
    elseif inches10 < distance_back
    right_turn
    else
    forward

    John Abshier

    Post Edited (John Abshier) : 6/22/2010 7:55:34 PM GMT
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-22 20:12
    ok thanks ill give that a try. Sorry, I edited the code after I posted the zip file so I wanted it to be up to date.
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-22 20:22
    ok heres what I just ran, I took into account your logic corrections and it runs for about 20 seconds to 60 seconds before getting stuck in permanent forward motion.

    Ive reset it a few times and it seems to always get stuck in forward motion and all the ping sensors turn off.

    Post Edited (p00ndawg) : 6/22/2010 8:27:46 PM GMT
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-06-22 22:35
    I don't know why the ping sensors would turn off. But if you we traveling forward and the sensor_scan cog stopped, then the movement_class would continue forward forever. If you have a free pin or 2 you could wire up an led and toggle it at the top or bottom of the sensor_scan repeat loop. Likewise for the movement_class loop. The LED should flash forever. If they don't, I don't have a clue.

    John Abshier
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-22 23:25
    alright that sounds like a great debugging idea. Ive left the lab for today but ill make sure to try that tomorrow.
    It would seem to me however that the sensor_scan cog is stopping, because they all go blank and it just goes forward.
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-23 17:19
    ok this is what I did for the sensor scan method:
    PUB sensor_scan
    
       dira[noparse][[/noparse]15]~~ 'toggle led
    
                
      repeat
       inch1 := ping.Inches(pin1)                                            'change time to distance in inches 
       inch2 := ping.Inches(pin2)
       inch3 := ping.Inches(pin3)                                            'change time to distance in inches 
       inch4 := ping.Inches(pin4)
       inch5 := ping.Inches(pin5)                                            'change time to distance in inches 
       inch6 := ping.Inches(pin6)
       inch7 := ping.Inches(pin7)                                            'change time to distance in inches 
       inch8 := ping.Inches(pin8)
       inch9 := ping.Inches(pin9)                                            'change time to distance in inches 
       inch10 := ping.Inches(pin10)
        
        !outa[noparse][[/noparse]15]'toggle led
        waitcnt(3_000_000 + cnt) 'toggle led
    
    
    



    Im not sure if this is helpful because I dont have any 3 prong led's for the msr1 so I used the led's on the tsl230 color sensor lol, but it got stuck in forward motion and the led's turned off.


    Next I ran this for the movement class:

    
    pub movement_class
     
        dira[noparse][[/noparse]15]~~  'toggle led
     
      repeat
       
        !outa[noparse][[/noparse]15] 'toggle led
        waitcnt(3_000_000 + cnt)  'toggle led
      
        if inch1 < distance
           right_turn  'right
           pause(758_333)
           
        elseif inch2 < distance
           right_turn
           pause(379_166)
        
          
        elseif inch3 < distance
          left_turn  'left
          pause(2_275_000)
        
         
        elseif inch4 < distance
           left_turn  'left
           pause(379_166)
        
        elseif inch5 < distance
           left_turn   'left
           pause(758_333)
                 
        elseif inch6 < distance_back
           left_turn   'left
           pause(1_516_666)
        
       
        elseif inch7 < distance_back
          left_turn   'left
          pause(1_895_833) 
      
    
        elseif inch8 < distance_back
          left_turn   'left
          pause(2_275_000)
        
        elseif inch9 < distance_back
          right_turn 'right  
          pause(1_516_666)
      
             
        elseif inch10 < distance_back
           right_turn 'right  
           pause(1_895_833)
        else
         pause(10_000)
         forward
         pause(10_000)
      
         
    
    




    and when it got stuck the led kept blinking.

    Post Edited (p00ndawg) : 6/23/2010 5:26:41 PM GMT
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-23 23:04
    BAH GAWD RING THE DAMN BELL


    I found the bug!

    Thanks for all the help guys. Really appreciated!
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-06-24 01:20
    What was it? We would like to learn also.

    John Abshier
  • p00ndawgp00ndawg Posts: 70
    edited 2010-06-24 01:44
    oh sorry I was really excited. Im not entirely sure what the bug was, but the whole time I was using these ping sensors a couple of them were acting funny. 2 of them had an always on green led. They scanned fine however, and didnt really seem to be a problem. The lab assistant pointed them out to me, but like I said there really didnt seem to be a problem and we didnt think any of it. Well like I said earlier he tried helping us out and ran his code, and it worked fine, but what happened was he didnt actually use those two ping sensors. I decided to just disable them and see what happens, voila it started running fine. The pings were on p2 and p3, I swapped them from p2 and p3 with p1 and p4 and they started blinking correctly. We tested it for awhile and all the sensors were blinking correctly and it didnt seem as if the sensor cog was stopping.

    you live and you learn I guess.
Sign In or Register to comment.