Shop OBEX P1 Docs P2 Docs Learn Events
Ping Sensor With Servos — Parallax Forums

Ping Sensor With Servos

NWCCTVNWCCTV Posts: 3,629
edited 2014-09-03 22:55 in Accessories
I understand that Servo motors need a "refresh" about every 20 seconds or so. So, in the below code, how would I go about doing this so that they are not interrupted when using my Ping sensors? The code works fine for roughly 20 seconds and then just stops.
'' ***************************************
'' * Ping))) Demo with PST & LED's       *
'' * Author: Parallax Staff              *
'' * Copyright (c) 2006 Parallax, Inc.   *
'' * See end of file for terms of use.   *    
'' * Started: 06-03-2010                 *
'' ***************************************
{{
Code Description : In this example there are two LED's to indicate a distance. If the distance is further
 than 6 inches than LED 1 will turn on, and if the distance is closer than 6 inches than LED 2 turns on; while
 either LED 1 or 2 is on, the alternate LED will be off. There is a numerical display of the values in the
 Parallax Serial Terminal (PST) at 9600 baud (true).
}}
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
  PING_Pin      = 13                                          ' I/O Pin For PING)))
  LED1          = 0                                         ' I/O PIN for LED 1
  LED2          = 9                                          ' I/O PIN for LED 2
  ON            = 1
  OFF           = 0                                          
  Distlimit     = 6                                          ' In inches
  
VAR
  long  range
OBJ
 
  ping   : "ping"
  servo  : "PropBoe Servos"
PUB Start
  dira[LED1..LED2]~~
  outa[LED1..LED2]~
 
  waitcnt(clkfreq + cnt)
    
  repeat                                                ' Repeat Forever
 
    range := ping.Inches(PING_Pin)                      ' Get Range In Inches
  '    
   if range > Distlimit                                 ' Comparing range to a set value of 6 inches
     outa[LED1] := ON                                      ' P1 is on              
     outa[LED2] := OFF                                     ' P2 is off
     servo.Set(14,250)
     servo.Set(15,-250)
   elseif range < Distlimit                             ' If range is further than 6 inches
     outa[LED1] := OFF                                     ' P1 is off    
     outa[LED2] := ON                                      ' P2 is on
     servo.Set(14,-10)
     servo.Set(15,-10)
{{

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2014-09-03 19:30
    If the "PropBoe Servos" object is anything like servo32v7, then you don't need to worry about the timing, the object takes care of that for you.

    What happens when range is equal to DistLimit?

    I would change this:

    elseif range < Distlimit

    to this:

    else
  • Mike GreenMike Green Posts: 23,101
    edited 2014-09-03 19:38
    I'm not familiar with "PropBoe Servos". That must use a separate cog for servo pulse timing. If so, don't you have to initialize it before using it otherwise? The refresh for the servos has to occur every 20 milliseconds, not every 20 seconds.

    "ping" is written in Spin and I don't believe it uses a separate cog for timing.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-09-03 22:55
    I think I narrowed the issue down. I have the 2 servos, a Ping and an IR rcvr utilizing a 12V Wall wart. I think my Prop BOE is resetting because of this. Thanks for the tips though.
Sign In or Register to comment.