Shop OBEX P1 Docs P2 Docs Learn Events
Help with coding errors! — Parallax Forums

Help with coding errors!

BotdocterBotdocter Posts: 271
edited 2010-04-02 21:02 in Propeller 1
Hey guys. I wrote this code, and can't get it right. Does anyone see what i'm doing wrong? I seem to have a problem with the AF_Pin and BF_Pin.
Any help is welcome!

CON
  _CLKMODE = XTAL1 + PLL16X
  _XINFREQ = 5_000_000

  
  PING_Pin = 16                 ''PING))) I/O Pin
  AF_Pin = 24
  BF_Pin = 26
  default_speed = 40
  
VAR
  long  range
  long  aspeed
  long  bspeed

  
OBJ
  PWM     : "PWM_32_v2.spin"
  ping    : "ping"
  BS2     : "BS2_Functions"
        
PUB Main | DutyCycle
 
    PWM.Start                   '' Initialize PWM cog. This Block Starts the PWM Object
    BS2.Start(31,30)
    
  repeat
      range := ping.Centimeters(PING_Pin)          ' Get Range In Millimeters
      IF range > 100
        range := 100

      aspeed := default_speed - range
      bspeed := default_speed - range             
                             


''    calculate the direction and speed of motor a
    IF range < 30 and range > 24
      repeat DutyCycle from 0 to 40
        PWM.Duty(AF_Pin,DutyCycle,5000)                                             ' Ramp Duty cycle up from 0 to 100               
        repeat 10000
      repeat 1500
                                                                     ' Hold at 100% for a little bit
      repeat DutyCycle from 40 to 0
        PWM.Duty(AF_Pin,DutyCycle,5000)                                             ' Ramp Duty cycle down from 100 to 0
        repeat 10000
      repeat 1500
      
      aspeed := 0
      bspeed := 0
      repeat 3000
            
    
       
        
 
       
''-------- This Block creates a 3-Phase 60Hz square wave on Pins 1,2, and 3 -----------
    PWM.Duty(AF_Pin,aspeed,16665)                                                       'Create a 60Hz 50% duty cycle on Pin1
    PWM.Duty(BF_Pin,bspeed,16665)                                                       'Create a 60Hz 50% duty cycle on Pin2


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor

a few motors and a whole lot of chaos!

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-04-02 14:38
    Is something supposed to be indented under repeat 1500 ???

    Or is that a way of creating a time delay?

    Post Edited (ElectricAye) : 4/2/2010 2:43:09 PM GMT
  • BotdocterBotdocter Posts: 271
    edited 2010-04-02 15:50
    Indeed it is to create a time delay..

    i want the bot to drive forward and and when it is withing 100cm range i want the speed to go down untill 25 cm. at 25 cm i want the bot to wait for a bit, and then drive one wheel forward to turn. then it goes from the top again.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-04-02 16:00
    Your comment says "Ramp Duty cycle up from 0 to 100" but your code appears to show it going only to 40 ???

    Your comment at the bottom says "Create a 60Hz 50% duty cycle on Pin1" but it looks like in your CON statement you have "AF_Pin = 24" ???

    Also, are you working in centimeters or, as your comment says, "Get Range In Millimeters" ???

    I doubt these are what are causing your problem, but it's just stuff that sticks out at me.
  • BotdocterBotdocter Posts: 271
    edited 2010-04-02 16:27
    Indeed the comments don't apply on the variables i changed them.

    But do you have any idea to get this working?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-04-02 16:41
    What happens when/if aspeed goes negative? Is that possible?

    I'm not a coding guru, but it might help the forum if you edit and repost your code to clean up the comments, etc. The last thing anyone wants to slog through is lots of "minor" things that cloud the problem.
  • mparkmpark Posts: 1,305
    edited 2010-04-02 16:41
    What's it doing and what is it supposed to do?
  • ratronicratronic Posts: 1,451
    edited 2010-04-02 16:53
    I think if your looking for a delay - repeat 1500 only gives about 4.3 msec's

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···································Fix it, if ain't broke!


    D Rat

    Dave Ratcliff N6YEE
  • BotdocterBotdocter Posts: 271
    edited 2010-04-02 19:06
    Ah thank you. I didn't know. I thought it would mean 1.5 sec.
    I will change that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • ratronicratronic Posts: 1,451
    edited 2010-04-02 19:34
    For a delay I would use waitcnt instead of repeat - every 80000000 = 1 second, i.e. - if you need 1.5 second delay use·· · waitcnt(120000000 + cnt)···· ··instead·of repeat.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···································Fix it, if ain't broke!


    D Rat

    Dave Ratcliff N6YEE

    Post Edited (ratronic) : 4/2/2010 7:39:20 PM GMT
  • BotdocterBotdocter Posts: 271
    edited 2010-04-02 20:10
    But does it pause the action or pause the entire program?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 Parallax Propeller Robot Control Board
    1 Memsic MX2125 accelerometer/ tilt
    1 Parallax Ping))) ultrasonic sensor

    a few motors and a whole lot of chaos!
  • hover1hover1 Posts: 1,929
    edited 2010-04-02 20:20
    Have you run through the PE Kit Labs? It would answer much of what you are asking.

    ·http://forums.parallax.com/showthread.php?p=617192

    And you must RTFM (Read The Fine Manual)

    ·http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/WebPM-v1.1.pdf
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-04-02 21:02
    Botdocter said...
    But does it pause the action or pause the entire program?

    Look up "waitcnt" in the Propeller Manual.

    www.parallax.com/Portals/0/Downloads/docs/prod/prop/WebPM-v1.1.pdf


    You can program the Propeller so that a Main program runs in a cog separately from a program inside another cog that is controlling an action but that's not what your code is showing.
Sign In or Register to comment.