November 21, 2024, 04:52:00 PM

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

  hi Jon
I'm useing a 5CH receiver and i what to convert it from a servo out put to a on - off control. we said that i will need to use a prop1 also a DC-16 to have all 5ch of control. also using the delay wold keep from false comans being sent. attn: to anyone whating to use a RC controller out of planes or  any type of receiver that uses a servo control pulse should use help its not as easy as you think Jon has told me stuff that is not what i was thinking so as Jon has said to me it can be done but it takes more thought and time then what you see and hear on robot sites it is not at all that easy. Jon is the man that knows this stuff and can help truest him after all he is the all knowing of this type of stuff. 
                                                                                                                                           thanks, Jon

JonnyMac

You could use the Prop-1 PULSIN command to read the servo signal and convert that to on/off for a motor.  It would be best if you added a dead-band so that you don't get motor cycling.  Here's an example

Main:
  PULSIN ServoIn, pWidth
  IF pWidth > 175 THEN Motor_On
  IF pWidth < 125 THEN Motor_Off
    GOTO Main

Motor_On:
  Motor = IsOn
  GOTO Main

Motor_Off:
  Motor = IsOff
  GOTO Main


Using PULSIN on the Prop-1 you should see a pulse width value between about 100 and about 200, with 150 when the joystick is centered.  If you study this code you'll see that when the joystick is between 125 and 175 nothing happens (we loop right back to Main); if the value is above 175 then we turn the motor on, if the value is below 125 we turn the motor off.
Jon McPhalen
EFX-TEK Hollywood Office

reddragon

 Hi Jon
   when i write that code it will not run  it is saying undefind symbol and it high lites servo in ?????

JonnyMac

You posed a theoretical question so I responded with a theoretical answer.  ;)

If I was really going to do this I'd use the code below -- it puts everything is a loop so I can use one small set of code to handle four inputs and outputs.

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


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


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


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

SYMBOL  Control4        = 7                     ' SETUP = out
SYMBOL  Control3        = 6                     ' SETUP = out
SYMBOL  Control2        = 5
SYMBOL  Control1        = 4
SYMBOL  ServoIn4        = 3                     ' servo pulse inputs
SYMBOL  ServoIn3        = 2
SYMBOL  ServoIn2        = 1
SYMBOL  ServoIn1        = 0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  servoPin        = B2
SYMBOL  ctrlPin         = B3
SYMBOL  pWidth          = B4


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %11110000                              ' set outputs (P4-P7)


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

Main:
  servoPin = 0                                  ' start at beginning

Measure_Pulse:
  ctrlPin = 4 + servoPin
  PULSIN servoPin, 1, pWidth                    ' measure servo pulse
  IF pWidth > 175 THEN Ctrl_On
  IF pWidth < 125 THEN Ctrl_Off
    GOTO Next_Pin

Ctrl_On:
  HIGH ctrlPin
  GOTO Next_Pin

Ctrl_Off:
  LOW ctrlPin

Next_Pin:
  servoPin = servoPin + 1
  IF servoPin < 4 THEN Measure_Pulse
    GOTO Main


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


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


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

JonnyMac

Just so you know, I don't have an RC system to test this program with!  It compiles, but you're going to have to hook it up and running on your end.
Jon McPhalen
EFX-TEK Hollywood Office

reddragon

  thanks Jon i thought that that was a test code to see what the peak was sorry 8) OK jest to make shire that the pins or right how should i hook them up on the receiver it ( ch, +5v, ground ) and on the prop controller it ( w, r, b ).  the reason I'm asking is. The receiver has 5V's coming out and i don't know if that will mess prop1 up or if there is a wight way to hook it on to the board or if i jest hook the output of the receiver to the prop1 servo headers. I'm whating to make shire so i don't sizzle any thing.??

reddragon

Quote from: JonnyMac on January 27, 2009, 04:58:38 PM
You posed a theoretical question so I responded with a theoretical answer.  ;)

If I was really going to do this I'd use the code below -- it puts everything is a loop so I can use one small set of code to handle four inputs and outputs.

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


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


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


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

SYMBOL  Control4        = 7                     ' SETUP = out
SYMBOL  Control3        = 6                     ' SETUP = out
SYMBOL  Control2        = 5
SYMBOL  Control1        = 4
SYMBOL  ServoIn4        = 3                     ' servo pulse inputs
SYMBOL  ServoIn3        = 2
SYMBOL  ServoIn2        = 1
SYMBOL  ServoIn1        = 0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  servoPin        = B2
SYMBOL  ctrlPin         = B3
SYMBOL  pWidth          = B4


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %11110000                              ' set outputs (P4-P7)


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

Main:
  servoPin = 0                                  ' start at beginning

Measure_Pulse:
  ctrlPin = 4 + servoPin
  PULSIN servoPin, 1, pWidth                    ' measure servo pulse
  IF pWidth > 175 THEN Ctrl_On
  IF pWidth < 125 THEN Ctrl_Off
    GOTO Next_Pin

Ctrl_On:
  HIGH ctrlPin
  GOTO Next_Pin

Ctrl_Off:
  LOW ctrlPin

Next_Pin:
  servoPin = servoPin + 1
  IF servoPin < 4 THEN Measure_Pulse
    GOTO Main


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


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


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

im having troubel controling the the wheels is there a way to adjest the code to have fordward and backwards and left and right. i keep running in to things so this would help? thanks Jon

JonnyMac

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 McPhalen
EFX-TEK Hollywood Office

reddragon

 I'm not for sure but i have a h- bridge controller its called a L298 motor driver its made my solarbotics and that is the one that i have. so how would i set that up with your board it has a diagram of how to hook it to a microcontroler??????????

JonnyMac

You'll need to get me their docs before I can help -- and I can make no guarantees since I don't have one to test.
Jon McPhalen
EFX-TEK Hollywood Office

reddragon

Quote from: JonnyMac on February 06, 2009, 01:40:42 AM
You'll need to get me their docs before I can help -- and I can make no guarantees since I don't have one to test.
here is the link to the data sheet >http://info.hobbyengineering.com/specs/SOLARBOTICS-KCMD-L298_Compact_motor_driver.pdf thanks i do have a dc-16 if more outputs are needed?

reddragon


JonnyMac

How many motors do you want to control?  If using the Prop-1 and that H-Bridge you can control exactly two motors.  The program will not be as straightforward because you have to convert the X and Y joystick values to logical commands that would allow you to drive the motors -- I suggest you start there.  If you agree, I'll write a demo program.

You should always start small on projects like this; trying to get to the "full" project in one fell swoop is often a recipe for heartache, and as I can't fully test any code that I write for you, writing one gigantic program that you may not understand is really not the best use of our time.  Agreed?
Jon McPhalen
EFX-TEK Hollywood Office

reddragon

 i will be useing two motors so that would work and you are write small steps work better i have been sick so i have been thinking a studying the tank driving and that seames to be the eazy way to go so thanks for the help jon.

JonnyMac

Okay, here's a program that I *think* will work with that controller.

CAVEAT EMPTOR: I do not have that part to test with and this is beyond the normal scope of the kind of things we do -- be very very careful.  Do not test the robot with the wheels on the floor -- mount it off the floor so you can watch the wheels spin to make sure they're going in the right direction.

WARNING: This program is for use as-is, with no guarantee or warranty of any kind.  Use at your own risk; EFX-TEK will not be responsible for damage to the motor controller, Prop-1, or robot.

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


' -----[ Program Description ]---------------------------------------------
'
' Motor control connections:
'
'  LM (left motor): P3 and P2
'
'   Stop = %xxxx00xx
'   Fwd  = %xxxx01xx
'   Rev  = %xxxx10xx
'
'  RM (right motor): P1 and P0
'
'   Stop = %xxxxxx00
'   Fwd  = %xxxxxx01
'   Rev  = %xxxxxx10


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


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

SYMBOL  ServoIn2        = 7                     ' SETUP = DN  (left/right)
SYMBOL  ServoIn1        = 6                     ' SETUP = DN  (fwd/rev)


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  pWidthY         = B2
SYMBOL  pWidthX         = B3


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

Reset:
  PINS = %00000000                              ' stop motors
  DIRS = %00001111


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

Main:
  PAUSE 100
  PULSIN ServoIn1, 1, pWidthY
  PULSIN ServoIn2, 1, pWidthX


Check_YStick:
  IF pWidthY < 130 THEN Check_Forward
  IF pWidthY > 170 THEN Check_Reverse


  ' y-stick is in dead zone
  ' -- if x-stick displaced, spin in place

Check_Spin:
  IF pWidthX < 130 THEN Spin_Right
  IF pWidthX > 170 THEN Spin_Left


Robot_Stop:
  PINS = %00000000                              ' LM = X, RM = X
  GOTO Main


Spin_Right:
  PINS = %00000110                              ' LM = F, RM = R
  GOTO Main


Spin_Left:
  PINS = %00001001                              ' LM = R, RM = F
  GOTO Main


  ' y-stick is pushed forward
  ' -- adjust based on x displacement

Check_Forward:
  IF pWidthX < 130 THEN Fwd_Right
  IF pWidthX > 170 THEN Fwd_Left


Full_Forward:
  PINS = %00000101                              ' LM = F, RM = F
  GOTO Main


Fwd_Right:
  PINS = %00000100                              ' LM = F, RM = X
  GOTO Main


Fwd_Left:
  PINS = %00000001                              ' LM = X, RM = F
  GOTO Main


  ' y-stick is pulled back
  ' -- adjust based on x displacement

Check_Reverse:
  IF pWidthX < 130 THEN Rev_Right
  IF pWidthX > 170 THEN Rev_Left


Full_Reverse:
  PINS = %00001010                              ' LM = R, RM = R
  GOTO Main


Rev_Right:
  PINS = %00001000                              ' LM = R, RM = X
  GOTO Main


Rev_Left:
  PINS = %00000010                              ' LM = X, RM = R
  GOTO Main


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


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


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


Jon McPhalen
EFX-TEK Hollywood Office