November 22, 2024, 06:52:20 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Motion Tracking

Started by Jadams, November 23, 2009, 07:03:09 AM

Previous topic - Next topic

Jadams

Is it possible for a PIR to tell which direction the motion comes from?  I want to mount a device on a continuous rotation servo and point it in the direction of the motion.  Can I use multiple PIRs on a Prop I?

Thanks   
Jim Adams

JonnyMac

I don't think so.  The "problem" with PIRs is that they have a very wide viewing angle and have a binary output -- off or on.   There are some advanced acoustic sensors that can give a range of targets but these are not compatible with the Prop-1.
Jon McPhalen
EFX-TEK Hollywood Office

davisgraveyard

I had suggested on another thread whether you might be able to a Parallax Linescan sensor to determine motion and direction.

http://www.parallax.com/Store/Sensors/ColorLight/tabid/175/CategoryID/50/List/0/Level/a/ProductID/566/Default.aspx?SortField=ProductName%2cProductName

This produces 128 lines of data.  Seems like if you could determine movement by any data changing and then based on which side it comes from direction.   There is even some BS2 sample code that is provided?

Jeff

Jadams

The linescan sensor looks interesting but beyond my programing skills at this point.  I've attached 2 PIRs to my Prop 1 and am able to get the servo to move to in the direction I want.  Hopefully my skills will improve to use devices like the linescanner.

Thanks
Jim Adams

Jadams

I am going to try to use 3 PIRs to find the motion source.  I understand the drawbacks but this will be a learning project for me.  The table is controlled by a  Prop 1 connected to a HB-25 to a DC motor.  PIR 1&2 are fixed and mounted 180 degrees apart.  I am only interested in detecting 1/2 or the circle.  I can move the table CW or CCW depending on which  PIR was activated but need to tell it when to stop.  I will mount PIR3 on the table.  The plan is to move the table in the direction of the motion and stop when PIR3 detects the motion.  I have used your Servo_Tracker.BS1 and Sooky_Dad_4x.BS1 programs as help to get started.  Could you please help me with the code needed for the 3 PIRs?

Thanks

Jim Adams

JonnyMac

December 14, 2009, 03:29:12 PM #5 Last Edit: December 15, 2009, 12:36:56 PM by JonnyMac
Here's a framework to play with.  It scans the PIRs for 100ms.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Trigger1        = PIN7                  ' SETUP = DN
SYMBOL  Trigger2        = PIN6                  ' SETUP = DN
SYMBOL  Trigger3        = PIN5                  ' ULN acts as pull-down


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' B/R jumper removed


' -----[ Variables ]-------------------------------------------------------

SYMBOL  sensors         = B0
SYMBOL   pir1           =  BIT7                 ' on P7 (SETUP = DN)
SYMBOL   pir2           =  BIT6                 ' on P6 (SETUP = DN)
SYMBOL   pir3           =  BIT5                 ' on P5

SYMBOL  timer           = B2


' -----[ Initialization ]--------------------------------------------------

Reset:
 PINS = %00000000                              ' clear all
 DIRS = %00011111                              ' set output pins


' -----[ Program Code ]----------------------------------------------------

Main:
 ' do something every ~100ms (loop delay)

Scan_Sensors:
 sensors = %11100000                           ' assume active
 FOR timer = 1 TO 20
   sensors = sensors & PINS                    ' scan inputs
   PAUSE 5
 NEXT

Check_PIR1:
 IF pir1 = IsOff THEN Check_PIR2
   ' pir #1 code here


Check_PIR2:
 IF pir2 = IsOff THEN Check_PIR3
   ' pir #2 code here


Check_PIR3:
 IF pir2 = IsOff THEN Main
   ' pir #3 code here
   GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

Jadams

Jim Adams

JonnyMac

My pleasure.  I just noticed that I forgot to name the inputs in the IO section so I've updated the listing.
Jon McPhalen
EFX-TEK Hollywood Office

Jadams

Thanks again Jon,  the program works as I planned except for one glitch.  The program immeadiately goes to Motor_CW on startup.  Would you take a look and advise changes?  Also, when you post a program, how do you get everything to line up after you copy and past from the editor?

' =========================================================================
'
'   File......      Motion Tracking Program.bs1
'   Purpose... Move turrent to motion source
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  HB25Chk         = PIN7                  ' P7 in - no SETUP jumper
SYMBOL  HB25            = 7                     ' P7 control
SYMBOL  Trigger1        = PIN6                  ' SETUP = DN
SYMBOL  Trigger2        = PIN5                  ' SETUP = DN
SYMBOL  Trigger3        = PIN4                  ' ULN acts as pull-down

' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0


' -----[ Variables ]-------------------------------------------------------


SYMBOL  sensors         = B0
SYMBOL   pir1           =  BIT6                 ' on P6 (SETUP = DN)
SYMBOL   pir2           =  BIT5                 ' on P5 (SETUP = DN)
SYMBOL   pir3           =  BIT4                 ' on P4

SYMBOL  timer           = B2


' -----[ Initialization ]--------------------------------------------------
Startup:

IF PIN7 = 0 THEN Startup                ' Wait For HB-25 Power Up (P0)
PAUSE 5                                 ' Wait For HB-25 To Initialize
PULSOUT HB25, 150                       ' Stop Motor
PAUSE 20                                ' Wait 20 mS

PINS = %00000000                        ' clear all
DIRS = %10000001                        ' set output pins



' -----[ Program Code ]----------------------------------------------------

Main:

Scan_Sensors:
  sensors = %01110000                           ' assume active
  FOR timer = 1 TO 20
    sensors = sensors & PINS                    ' scan inputs
    PAUSE 5
  NEXT

Check_PIR1:
  IF pir1 = IsOff THEN Check_PIR2
    GOSUB Motor_CW


Check_PIR2:
  IF pir2 = IsOff THEN Check_PIR3
   GOSUB Stop_Motor


Check_PIR3:
  IF pir3 = IsOff THEN Main
    GOSUB Motor_CCW

    GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

Stop_Motor:
  PAUSE 6                                       ' command hold-off
  PULSOUT HB25, 150                             ' center = stop
  PAUSE 1000                                    ' command hold-off
  PULSOUT HB25, 150                             ' insurance command
  RETURN

' -------------------------------------------------------------------------
  Motor_CW:
  PAUSE 6                                      ' command hold-off
  PULSOUT HB25, 180                            ' set speed/direction
  RETURN


' -------------------------------------------------------------------------
  Motor_CCW:
  PAUSE 6                                      ' command hold-off
  PULSOUT HB25, 140                            ' set speed/direction
  RETURN

' -----[ EEPROM Data ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jim Adams

JonnyMac

December 16, 2009, 12:21:24 PM #9 Last Edit: December 16, 2009, 12:23:05 PM by JonnyMac
You changed the DIRS setting and made P7 and output -- this is causing a false positive on PIR 1; for your program it should be %00000001.  This assumes that you have the HB25 connected to P0.

Above the message section you'll see a lot of buttons, look for the red "A".  When you click on this you'll insert font change tags that look like this (without the spaces):

[ font=Verdana ][ /font ]

Paste you code in between the tags and change Verdana to Courier New.

[ font=Courier New ]code here[ /font ]

Remember... I put the spaces in the tags so they'll not act like tags -- don't do anything except change the font name and paste you code between the tags.
Jon McPhalen
EFX-TEK Hollywood Office

Jadams

PIR1 works ok, starts and stops as planned.  When I trigger PIR 3 then Stop (PIR2) it gives a stop ,about .5 sec,  start, about .5 sec, then full stop.  I can't find the problem.  As always, your help is appreciated.



' =========================================================================
'
'   File...... Motion Tracking Program.bs1
'   Purpose... Move turrent to motion source
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Trigger1        = PIN7                  ' SETUP = DN
SYMBOL  Trigger2        = PIN6                  ' SETUP = DN
SYMBOL  Trigger3        = PIN5                  ' ULN acts as pull-down
SYMBOL  HB25            = PIN0                  ' I/O Pin For HB-25
' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0


' -----[ Variables ]-------------------------------------------------------


SYMBOL  sensors         = B0
SYMBOL   pir1           =  BIT7                 ' on P7 (SETUP = DN)
SYMBOL   pir2           =  BIT6                 ' on P6 (SETUP = DN)
SYMBOL   pir3           =  BIT5                 ' on P5
SYMBOL  timer           = B2

' -----[ Initialization ]--------------------------------------------------

GOSUB Stop_Motor

PINS = %00000000                    ' Clear all
DIRS = %00000001                    ' Set Pin 0 to Output

' -----[ Program Code ]----------------------------------------------------

Main:

Scan_Sensors:
  sensors = %11100000                           ' assume active
  FOR timer = 1 TO 20
    sensors = sensors & PINS                    ' scan inputs
    PAUSE 5
  NEXT

Check_PIR1:
  IF pir1 = IsOff THEN Check_PIR2
    GOSUB Motor_CCW


Check_PIR2:
  IF pir2 = IsOff THEN Check_PIR3
   GOSUB Stop_Motor


Check_PIR3:
  IF pir3 = IsOff THEN Main
    GOSUB Motor_CW

    GOTO Main

' -----[ Subroutines ]-----------------------------------------------------

Stop_Motor:
  PAUSE 6                                       ' command hold-off
  PULSOUT HB25, 150                             ' center = stop
  PAUSE 1000                                    ' command hold-off
  PULSOUT HB25, 150                             ' insurance command
  RETURN

' -------------------------------------------------------------------------
  Motor_CW:
  PAUSE 6                                      ' command hold-off
  PULSOUT HB25, 180                            ' set speed/direction
  RETURN


' -------------------------------------------------------------------------
  Motor_CCW:
  PAUSE 6                                      ' command hold-off
  PULSOUT HB25, 140                            ' set speed/direction
  RETURN

' -----[ EEPROM Data ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jim Adams

JonnyMac

We're all at a serious disadvantage not having your hardware to work with -- so we can only guess. 

I would start by adding GOTO Main at the end of the first two sections as well; it seems like this kind of program should only validate one sensor at a time. 
Jon McPhalen
EFX-TEK Hollywood Office

Jadams

I have the HB-25 driving a 12V PM motor at very low speed. (145 CW and 157 CCW)  The problem is I have no power.  Can I use the HB-25 in conjunction with KB speed controller?

Thanks
Jim Adams

JonnyMac

No power as in no torque?  I -- and perhaps others -- don't know what you mean by "KB speed controller."  Even if I did, that may be a better question for Parallax as the HB-25 is theirs.
Jon McPhalen
EFX-TEK Hollywood Office

Jadams

Yes, no torque or at least not enough for my application.  I will ask parallax.  Thanks
Jim Adams