November 22, 2024, 05:37:07 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


coverting a servo comand from a r/c recvier to a on-off control

Started by reddragon, January 26, 2009, 03:09:20 PM

Previous topic - Next topic

reddragon

   
Jon ready what you have said I'm thinking about sticking with relays jest to be on the safe side. Sorry for asking you to write that code but I'm thankful that you help people with information. I have been thinking a looking over the code that you jest wrote and. Now that you said someting about the X and Y I'm thinking this. I might be wrong but this is what I'm thinking. when using a servo it has bi channels on one control stick such as left and right. I'm wondering if there is a code that could be made to convert one output in to two using the left and right for two on and off comands so in sated of four outputs it would be a total of eight outputs.
           
                                       Up as - output #1  and  Down as - output #2>   Left as - output #3  and  Right as - output #4

JonnyMac

Have a look at this -- you'll probably have to make adjustments (I can't test as I don't do RC stuff).

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2009 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  ServoIn2        = 7                     ' SETUP = DN (L/R)
SYMBOL  ServoIn1        = 6                     ' SETUP = DN (U/D)

SYMBOL  Out4            = PIN3                  ' Right
SYMBOL  Out3            = PIN2                  ' Left
SYMBOL  Out2            = PIN1                  ' Down
SYMBOL  Out1            = PIN0                  ' Up


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  pWidth          = B2


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00001111                              ' set outputs


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

Main:
  PAUSE 50


Check_UpDn:
  PULSIN ServoIn1, 1, pWidth
  IF pWidth > 170 THEN Y_Up
  IF pWidth < 130 THEN Y_Down

Y_Stick_Off:
  Out1 = IsOff
  Out2 = IsOff
  GOTO Check_LfRt

Y_Up:
  Out1 = IsOn
  Out2 = IsOff
  GOTO Check_LfRt

Y_Down:
  Out1 = IsOff
  Out2 = IsOn


Check_LfRt:
  PULSIN ServoIn2, 1, pWidth
  IF pWidth > 170 THEN X_Left
  IF pWidth < 130 THEN X_Right

X_Stick_Off:
  Out3 = IsOff
  Out4 = IsOff
  GOTO Main

X_Left:
  Out3 = IsOn
  Out4 = IsOff
  GOTO Main

X_Right:
  Out3 = IsOff
  Out4 = IsOn
  GOTO Main


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


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


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

reddragon

     I'm glad that its possable.Now to add the other stick do i jest write the same thing for the other stick. That way i will have the same forthe other control stick??now that i said that wont that be to much memory used or is there a short hand for that? I'm testing the one you wrote and it works well when i get done it is going to be y dead man for this up coming halloween.

JonnyMac

You only have eight outputs so you can't do this on the Prop-1; to get the same control from two sticks you'd need four inputs (2 sticks at 2 axis each) and four outputs for each stick -- that's 12 IO pins.
Jon McPhalen
EFX-TEK Hollywood Office

reddragon

ok can i use my dc-16 for the other out puts sciens its a on and off control board that would give me the outputs needed for the whole thing wouldnt it?

JonnyMac

I don't know... can you?   ;D  I can!  All kidding aside, why don't you give it a try and then let me help you after that -- the best way to learn prop programming is to do it!  Have fun!
Jon McPhalen
EFX-TEK Hollywood Office

reddragon

   Ok, Jon this is how far I get when I try to write a code useing dc16. I am not sure how to write it from this point on. I read the doc's and then I tried it. It is not good. I am confused on which comand to write and how to write it. I can do comands for prop1 put when I try to use it with dc16 I just get stuck. But I am trying to figure it out. I hit walls around every turn.


' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2009 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL  Sio                 = 7
SYMBOL  ServoIn3        = 3                     ' SETUP = DN (L/R)
SYMBOL  ServoIn2        = 2                     ' SETUP = DN (U/D)
SYMBOL  ServoIn1        = 1
SYMBOL  ServoIn0        = 0 
SYMBOL  Out4            = PIN4                  ' Right
SYMBOL  Out3            = PIN5                  ' Left
SYMBOL  Out2            = PIN6                  ' Down
SYMBOL  Out1            = PIN0                  ' Up


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  pWidth          = B2


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00001111                              ' set outputs
  serout sio, baud,("!!!!!! dc16",%00,"x")

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

Main:
  PAUSE 50


Check_UpDn:
  PULSIN ServoIn1, 1, pWidth
  IF pWidth > 170 THEN Y_Up
  IF pWidth < 130 THEN Y_Down

Y_Stick_Off:
  Out1 = IsOff
  Out2 = IsOff
  GOTO Check_LfRt

Y_Up:
  Out1 = IsOn
  Out2 = IsOff
  GOTO Check_LfRt

Y_Down:
  Out1 = IsOff
  Out2 = IsOn


Check_LfRt:
  PULSIN ServoIn2, 1, pWidth
  IF pWidth > 170 THEN X_Left
  IF pWidth < 130 THEN X_Right

X_Stick_Off:
  Out3 = IsOff
  Out4 = IsOff
  GOTO Main

X_Left:
  Out3 = IsOn
  Out4 = IsOff
  GOTO Main

X_Right:
  Out3 = IsOff
  Out4 = IsOn
  GOTO Main


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


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


' -----[ User Data ]-------------------------------------------------------

JonnyMac

Give this a try -- may need adjustments.

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


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP

SYMBOL  Y2              = 3                     ' servo pulse inputs
SYMBOL  X2              = 2
SYMBOL  Y1              = 1
SYMBOL  X1              = 0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  ctrlBits        = B0
SYMBOL  pWidth          = B2


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

Reset:
  SEROUT Sio, Baud, ("!DC16", %00, "X")
  PAUSE 5


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

Main:
  SEROUT Sio, Baud, ("!DC16", %00, "L", ctrlBits)
  SEROUT Sio, Baud, ("!DC16", %00, "P", 6, BIT5)        ' remove for v1.5


' Stick #1

Check_Y1:
  PULSIN Y1, 1, pWidth
  IF pWidth > 170 THEN Y1_Up
  IF pWidth < 130 THEN Y1_Down

Y1_Stick_Off:
  BIT0 = IsOff
  BIT1 = IsOff
  GOTO Check_X1

Y1_Up:
  BIT0 = IsOn
  BIT1 = IsOff
  GOTO Check_X1

Y1_Down:
  BIT0 = IsOff
  BIT1 = IsOn

Check_X1:
  PULSIN X1, 1, pWidth
  IF pWidth > 170 THEN X1_Left
  IF pWidth < 130 THEN X1_Right

X1_Stick_Off:
  BIT2 = IsOff
  BIT3 = IsOff
  GOTO Check_Y2

X1_Left:
  BIT2 = IsOn
  BIT3 = IsOff
  GOTO Check_Y2

X1_Right:
  BIT2 = IsOff
  BIT3 = IsOn


' Stick #2

Check_Y2:
  PULSIN Y2, 1, pWidth
  IF pWidth > 170 THEN Y2_Up
  IF pWidth < 130 THEN Y2_Down

Y2_Stick_Off:
  BIT4 = IsOff
  BIT5 = IsOff
  GOTO Check_X2

Y2_Up:
  BIT4 = IsOn
  BIT5 = IsOff
  GOTO Check_X2

Y2_Down:
  BIT4 = IsOff
  BIT5 = IsOn

Check_X2:
  PULSIN X2, 1, pWidth
  IF pWidth > 170 THEN X2_Left
  IF pWidth < 130 THEN X2_Right

X2_Stick_Off:
  BIT6 = IsOff
  BIT7 = IsOff
  GOTO Main

X2_Left:
  BIT6 = IsOn
  BIT7 = IsOff
  GOTO Main

X2_Right:
  BIT6 = IsOff
  BIT7 = IsOn
  GOTO Main


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


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


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

reddragon

Quote from: JonnyMac on February 05, 2009, 04:10:34 PM
You would need two outputs per motor; one for direction, one for on-off -- and the code would have to change.  Depending on the size of your motors you might consider the Parallax HB-25 motor controller that you can attach right to your RC receiver.

Or you can use a couple relays to create a simple h-bridge; I've done it like this:



In this diagram OUT0 controls the motor on and off; OUT1 controls forward or reverse.
jon im making the bords for this set up  now tht i look at it its a stander relay on out 0 and then an doubel trow relay on out 1 am i right?

JonnyMac

The direction control relay needs to be double-pole double-throw -- the power on can be single-pole, single through (though it would be easiest just to buy two DPDT relays).
Jon McPhalen
EFX-TEK Hollywood Office

reddragon

its a all go code it works like a charm there was some changes to my remote but besides that it works to the T. Thanks Jon
to anyone whating to do this. This code will work for all heli-max controller and receiver..  Note: you might have to change some numbers but it will work..