November 23, 2024, 11:15:48 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.


Switching Control between a Prop-1 and a RC Receiver

Started by robomaster-1, December 10, 2015, 02:44:15 AM

Previous topic - Next topic

robomaster-1

I am working on Character Head that I need to switch control between a Prop-1 and a Radio Control Receiver. I tried using a DPDT with the center off switch to switch the power between the Prop-1 and RC Receiver. The problem I am having is that the Prop-1 is powering the receiver making the switch useless. I need isolate the power between the two units. I have run out of Ideas. Do you have any suggestions?   
Tim J. Lewis
Magic and Technology

JackMan

A schematic or diagram of how you have everything wired would help to pinpoint the problem.

JonnyMac

December 10, 2015, 10:25:16 AM #2 Last Edit: December 10, 2015, 10:27:39 AM by JonnyMac
If the Prop-1 is providing power to the receiver, you can't turn it off.

I'm assuming that you want to control a servo from the receiver or the Prop-1? If this is the case I would suggest software switching. Here's an example. In this little program idea, the output from RC receiver that you would normally connect to a servo goes to P6 of the Prop-1. Connect the servo to P7, and connect a switch to P0.

When the switch is open P0 will read as low and the program will listen (with PULSIN) for the command pulse from the RC receiver, then echo it (with PULSOUT) to the servo.

When the switch is closed P0 will read as high and the program will allow you to set the value of pWidth to send to the servo.

Note that if you run the program below, closing the P0 switch will simply hold the servo at its present position, regardless of what the RC receiver is doing.

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


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

' Allows remote or local control of single servo channel. Output for RC
' receiver goes to P6. If P0 is low, output from RC receiver will be
' echoed to P7 (which connects to servo).
'
' If P0 is high, program sets position of servo (in pWidth)


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

SYMBOL  ServoOut        = 7                     ' SETUP = OUT or DN
SYMBOL  ServoIn         = 6                     ' SETUP = OUT or DN
SYMBOL  ServoCtrl       = PIN0                  ' ULN is pull-down


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0


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

SYMBOL  pWidth          = B2                    ' pulse width for servo


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

Reset:
  PINS = %00000000                              ' all off
  DIRS = %10000000                              ' P7 (servo) is output


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

Main:
  BRANCH ServoCtrl, (Remote_Control, Local_Control)


Remote_Control:
  PULSIN ServoIn, 1, pWidth                     ' get servo pos from RC
  PULSOUT ServoOut, pWidth                      ' echo to servo
  GOTO Main


Local_Control:

  ' setup pWidth for desired postion
  ' -- 60..240 for 180 servo, 100..200 for 90 servo

  PULSOUT ServoOut, pWidth                      ' update servo
  PAUSE 18                                      ' loop pad
  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office

robomaster-1

Here is a copy of the code to randomly move three servo. I am using a program that Vern Graner  wrote for random servo movement. I striped it down to just three servos and modified it to make the eyes blink and the Ears wiggle.





' {$STAMP BS1}
' {$PBASIC 1.0}

'------------------------------------------------------
' HEX Servo Random Movement Generator
' By Vern Graner April 29th, 2005
' Any questions to vern@graner.com
' R-04.29f
'------------------------------------------------------
' -First attempt for Prop-1 controller
'------------------------------------------------------
' Hardware setup:
' Servos connected to pins 0-5


'Declare Variables
'------------------------------------------------------
SYMBOL RESULT = W0 ' value can be 0 to 65535
SYMBOL  DEST1 = B2 ' value can be 0 to 255
SYMBOL   CUR1 = B3 ' value can be 0 to 255
SYMBOL  DEST2 = B4 ' value can be 0 to 255
SYMBOL   CUR2 = B5 ' value can be 0 to 255
SYMBOL  DEST3 = B6 ' value can be 0 to 255
SYMBOL   CUR3 = B7 ' value can be 0 to 255
SYMBOL  DEST4 = B8 ' value can be 0 to 255
SYMBOL   CUR4 = B9 ' value can be 0 to 255
SYMBOL  DEST5 = B10 ' value can be 0 to 255
SYMBOL   CUR5 = B11 ' value can be 0 to 255
SYMBOL  DEST6 = B12 ' value can be 0 to 255
SYMBOL   CUR6 = B13 ' value can be 0 to 255


'Pre set values in variables
'------------------------------------------------------
RESULT  = 11010     ' set initial "seed" value
CUR1    = 128        ' Set all current and destination values to match
DEST1   = 128        ' to force the cur=dest routines to generate a random
CUR2    = 128        ' destination for all servos on first pass
DEST2   = 128
CUR3    = 128
DEST3   = 128
'CUR4    = 50
'DEST4   = 50
'CUR5    = 50
'DEST5   = 50
'CUR6    = 50
'DEST6   = 50
'------------------------------------------------------

'Main loop begin
LOOP:


IF CUR1=DEST1 THEN FetchNewDest1   'If the servo has reached it's destination fetch a new one    Servo 0 (Eye Blink)
  GOTO NextTest1                   ' if not, skip to next test
FetchNewDest1:
  RANDOM RESULT                    'Use RANDOM to find a new destination
  RESULT=RESULT // 185             'Cut it down to a usable size
  DEST1=RESULT                     'Stuff the new destination into DEST variable
  DEST1=DEST1 MIN 110             'Set limits so servos do not exceed positional
  DEST1=DEST1 MAX 225            ' requiremenmts
'  DEBUG "Cur1=",#CUR1," Dest1=",#DEST1,CR
NextTest1:

IF CUR2=DEST2 THEN FetchNewDest2                                                        '        Servo 1  (Left Ear)
  GOTO NextTest2:
FetchNewDest2:
  RANDOM RESULT
  RESULT=RESULT // 200
  DEST2=RESULT
  DEST2=DEST2 MIN 145
  DEST2=DEST2 MAX 245
'  DEBUG "Cur2=",#CUR2," Dest2=",#DEST2,CR
NextTest2:

IF CUR3=DEST3 THEN FetchNewDest3                                                         '        Servo 2 (Right Ear)
  GOTO NextTest3
FetchNewDest3:
  RANDOM RESULT
  RESULT=RESULT // 200
  DEST3=RESULT
  DEST3=DEST3 MIN 110
  DEST3=DEST3 MAX 240
'  DEBUG "Cur3=",#CUR3," Dest3=",#DEST3,CR
NextTest3:



IF CUR1<DEST1 THEN PlusCur1        'Check to see if CUR is less than DEST
CUR1=CUR1-1                        'If NOT the decrement CUR
GOTO TestDone1                     'Jump out of the test
PlusCur1:
CUR1=CUR1+1                        'If SO then increment CUR
TestDone1:

IF CUR2<DEST2 THEN PlusCur2
CUR2=CUR2-1
GOTO TestDone2
PlusCur2:
CUR2=CUR2+1
TestDone2:

IF CUR3<DEST3 THEN PlusCur3
CUR3=CUR3-1
GOTO TestDone3
PlusCur3:
CUR3=CUR3+1
TestDone3:




'DEBUG CLS
'DEBUG "CUR1=",#CUR1," DEST1=",#DEST1,CR
'DEBUG "CUR2=",#CUR2," DEST2=",#DEST2,CR
'DEBUG "CUR1=",#CUR1," CUR2=",#CUR2,"CUR3=",#CUR3," CUR4=",#CUR4,CR

PULSOUT 0,CUR1  'send a pulse to the servo on P0 (Eye Blink) Servo 0
PULSOUT 1,CUR2  'send a pulse to the servo on P1 (Left Ear)  Servo 1
PULSOUT 2,CUR3  'send a pulse to the servo on P2 (Right Ear) Servo 2


PAUSE 20        'Use a value of 20 for slow servo motion, comment out for fastest motion
GOTO LOOP       'lets do it again!
Tim J. Lewis
Magic and Technology

JonnyMac

Please post your specification instead of code. There are many approaches to a problem -- by describing the problem in English versus one idea in code, you'll get better feedback. Remember, the root word of specification is specific. ;)
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

December 10, 2015, 02:19:04 PM #5 Last Edit: December 10, 2015, 09:03:59 PM by JonnyMac
After reviewing your posts in this thread, I came up with this.

In order to share control between the RC radio and the Prop-1, you're going to have to OR the signals from each device together -- you can do this with diodes (e.g., 1N4148) to keep things simple. If you decide to build a breakout board, you could use a 74HC32 quad OR-gate chip to do the job; this would give your up to four servos.

You have to power the RC radio from the Prop-1. You can kill the radio power and enable local control of the servos using a DPDT switch. This diagram should clarify things.



Here's an adaptation of my original code idea and the desire to randomize the servos. The way this code works you should allow the radio to center the servos befor switching to Prop-1 control so that the servos don't jump to far and fast which could create a mechanical problem.

Note, too, that it doesn't take any effort craft and neatly format a program that is easy to read and maintain. I have moved all servo behaviors to constants and removed the "magic numbers."

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


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Servo3          = 2
SYMBOL  Servo2          = 1
SYMBOL  Servo1          = 0


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  S1_Min          = 110                   ' servo settings
SYMBOL  S1_Max          = 225
SYMBOL  S1_Speed        = 1

SYMBOL  S2_Min          = 140
SYMBOL  S2_Max          = 245
SYMBOL  S2_Speed        = 1

SYMBOL  S3_Min          = 110
SYMBOL  S3_Max          = 240
SYMBOL  S3_Speed        = 1

SYMBOL  Center          = $9696                 ' $96 = 150 (1.5ms)


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

SYMBOL  s1Values        = W1
SYMBOL   s1pos          =  B2
SYMBOL   s1dest         =  B3

SYMBOL  s2Values        = W2
SYMBOL   s2pos          =  B4
SYMBOL   s2dest         =  B5

SYMBOL  s3Values        = W3
SYMBOL   s3pos          =  B6
SYMBOL   s3dest         =  B7

SYMBOL  span            = B8                    ' for calculating new dest

SYMBOL  lottery         = W5                    ' random #


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

Power_Up:
  lottery = 1225                                ' seed random #

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00000111                              ' P2..P0 are outputs

  s1Values = Center                             ' set pos & dest to 150
  s2Values = Center
  s3Values = Center


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

Main:
  RANDOM lottery                                ' stir random #
  BRANCH Trigger, (Reset, S1_Update)


S1_Update:
  IF s1pos > s1dest THEN S1_Rev
  IF s1pos = s1dest THEN S1_New

S1_Fwd:
  s1pos = s1pos + S1_Speed MAX S1_Max
  GOTO S2_Update

S1_Rev:
  s1pos = s1pos - S1_Speed MIN S1_Min
  GOTO S2_Update

S1_New:
  RANDOM lottery                                ' re-stir random #
  span = S1_Max - S1_Min + 1                    ' span for this servo
  s1dest = lottery // span + S1_Min             ' range is S1_Min..S1_Max


S2_Update:
  IF s2pos > s2dest THEN S2_Rev
  IF s2pos = s2dest THEN S2_New

S2_Fwd:
  s2pos = s2pos + S2_Speed MAX S2_Max
  GOTO S3_Update

S2_Rev:
  s2pos = s2pos - S2_Speed MIN S2_Min
  GOTO S3_Update

S2_New:
  RANDOM lottery
  span = S2_Max - S2_Min + 1
  s2dest = lottery // span + S2_Min


S3_Update:
  IF s3pos > s3dest THEN S3_Rev
  IF s3pos = s3dest THEN S3_New

S3_Fwd:
  s3pos = s3pos + S3_Speed MAX S3_Max
  GOTO Refresh_Servos

S3_Rev:
  s3pos = s3pos - S3_Speed MIN S3_Min
  GOTO Refresh_Servos

S3_New:
  RANDOM lottery
  span = S3_Max - S3_Min + 1
  s3dest = lottery // span + S3_Min


Refresh_Servos:
  PULSOUT Servo1, s1pos
  PULSOUT Servo2, s2pos
  PULSOUT Servo3, s3pos
  PAUSE 15
  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office

robomaster-1

Jon,

I want to thank you for your help. I got it working using the diodes to the the OR of the pins to the servos. I will post some pictures of the setup at a later time. It has been a while since worked with the Prop-1. Thank You.
Tim J. Lewis
Magic and Technology

robomaster-1

I am having a problem with the speed variables if I put any number in there other than 1 than that servo stops moving. I need to have the servos move faster and the speed  function is not working at all. I have to have this working by Monday. I am going to something and I an not sure if it going to work. This is what each of the three servo are controlling Servo 1 is the Eye Blink, Servo 2 Left Ear wiggle, Servo 3 is Right Ear Wiggle. I really need servo 1 to move faster as of now the eye blink is to slow.  Thank You for your help.
Tim J. Lewis
Magic and Technology

JonnyMac

December 13, 2015, 01:38:23 PM #8 Last Edit: December 13, 2015, 02:57:04 PM by JonnyMac
The correction was very easy once I thought about it for a second: instead of limiting the servo range to the physical limits of each servo (which works when you have a speed resolution of 1), you have to limit to the current destination value. That way, if adding or subtracting the speed value overshoots the destination, the MIN and MAX operators will force the overshot value to the destination, and a new cycle will start.

I dug up a servo and ran this with a shunt on P6 (local control) and a speed value of 3 for Servo1 -- it works.

' =========================================================================
'
'   File...... servo3x_random.bs1
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 13 DEC 2015
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Servo3          = 2
SYMBOL  Servo2          = 1
SYMBOL  Servo1          = 0


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  S1_Min          = 110                   ' servo settings
SYMBOL  S1_Max          = 225
SYMBOL  S1_Speed        = 3

SYMBOL  S2_Min          = 140
SYMBOL  S2_Max          = 245
SYMBOL  S2_Speed        = 1

SYMBOL  S3_Min          = 110
SYMBOL  S3_Max          = 240
SYMBOL  S3_Speed        = 1

SYMBOL  Center          = $9696                 ' $96 = 150 (1.5ms)


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

SYMBOL  s1Values        = W1
SYMBOL   s1pos          =  B2
SYMBOL   s1dest         =  B3

SYMBOL  s2Values        = W2
SYMBOL   s2pos          =  B4
SYMBOL   s2dest         =  B5

SYMBOL  s3Values        = W3
SYMBOL   s3pos          =  B6
SYMBOL   s3dest         =  B7

SYMBOL  span            = B8                    ' for calculating new dest

SYMBOL  lottery         = W5                    ' random #


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

Power_Up:
  lottery = 1225                                ' seed random #

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00000111                              ' P2..P0 are outputs

  s1Values = Center                             ' set pos & dest to 150
  s2Values = Center
  s3Values = Center


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

Main:
  RANDOM lottery                                ' stir random #
  BRANCH Trigger, (Reset, S1_Update)


S1_Update:
  IF s1pos > s1dest THEN S1_Rev
  IF s1pos = s1dest THEN S1_New

S1_Fwd:
  s1pos = s1pos + S1_Speed MAX s1dest           ' limit to destination
  GOTO S2_Update

S1_Rev:
  s1pos = s1pos - S1_Speed MIN s1dest           ' limit to destination
  GOTO S2_Update

S1_New:
  RANDOM lottery                                ' re-stir random #
  span = S1_Max - S1_Min + 1                    ' calculate span for this servo
  s1dest = lottery // span + S1_Min             ' set new destination


S2_Update:
  IF s2pos > s2dest THEN S2_Rev
  IF s2pos = s2dest THEN S2_New

S2_Fwd:
  s2pos = s2pos + S2_Speed MAX s2dest
  GOTO S3_Update

S2_Rev:
  s2pos = s2pos - S2_Speed MIN s2dest
  GOTO S3_Update

S2_New:
  RANDOM lottery
  span = S2_Max - S2_Min + 1
  s2dest = lottery // span + S2_Min


S3_Update:
  IF s3pos > s3dest THEN S3_Rev
  IF s3pos = s3dest THEN S3_New

S3_Fwd:
  s3pos = s3pos + S3_Speed MAX s3dest
  GOTO Refresh_Servos

S3_Rev:
  s3pos = s3pos - S3_Speed MIN s3dest
  GOTO Refresh_Servos

S3_New:
  RANDOM lottery
  span = S3_Max - S3_Min + 1
  s3dest = lottery // span + S3_Min


Refresh_Servos:
  PULSOUT Servo1, s1pos
  PULSOUT Servo2, s2pos
  PULSOUT Servo3, s3pos
  PAUSE 15
  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office

robomaster-1

Thanks Jon I will try that out. Here a link on the Head being test out.
Thank You for all your help and Merry Christmas.



https://www.youtube.com/watch?v=ItqgcAtki1Q
Tim J. Lewis
Magic and Technology