November 23, 2024, 02:05:38 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.


Electronic Speed Control

Started by Raisin-Toe, December 19, 2008, 04:47:55 PM

Previous topic - Next topic

Raisin-Toe

Hey, I was wondering how I could connect an Electronic Speed Controller (esc) to the Prop-1.

       Can the Prop-1 receive its power source from the esc? If not, do I just connect the signal wire of the esc to the prop-1, and use the normal power supply? ???

JonnyMac

Can you point me to some tech docs on the device you want to use/connect? -- it's presently a mystery to me (though I can guess what it does).
Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

Here is the esc that I will probabley use:
http://www.horizonhobby.com/Products/Default.aspx?ProdID=EFLA312B

An esc is used to control an electic motor, (this particular one is for a brushless motor). The battery connection goes through the esc; the esc distributes 8 volts to the controller.

In this picture you can see the wires more clearly:
http://www.rcuniverse.com/magazine/reviews/887/DR1_ESC1.jpg

The three wires to the right go to the brushless motor
Then on the left you can see the two battery wires, and the W,R, and B wires that would typicaly connect to a receiver, but in our case would connect to the prop-1.

Maybe I can find a diagram for you. :)

JonnyMac

December 19, 2008, 05:41:10 PM #3 Last Edit: December 19, 2008, 05:43:38 PM by JonnyMac
Good news, you can connect that dude to an output header (WRB) and use PULSOUT with the Prop-1.  When using PULSOUT with the Prop-1 the "standard" values are 100 (1ms) to 200 (2ms) -- a PULSOUT value of 150 (1.5ms) is used to center servo; perhaps that's the value used to stop the motor (as with the HB-25 from Parallax).

Just to be clear, you can use a Prop-1/2/SX to control the ESC, but you do not want to get power from the ESC into the controller -- that will make a big mess as it is a PWM signal and not a stead voltage.  The B wire on the WRB gives the Prop-1 common ground with the ESC, so I suggest you use separate power sources.
Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

December 19, 2008, 05:51:37 PM #4 Last Edit: December 19, 2008, 05:53:32 PM by Raisin-Toe
awsome! so do I disconect just the Red wire?

Raisin-Toe

 ??? ??? ???
Motor = 2


Pulsout Motor, 100
pause 500
return
??? ??? ???

Should that make my motor turn?

JonnyMac

I don't know -- you're going to need to get more specifics about your ESC.  For example, does it need to be refreshed every 20ms as would happen if connected to an RC receiver.  You might try this simple sweep loop to see if you get anything:

Main:
  FOR pos = 100 TO 200
    PULSOUT 0, pos
    PAUSE 19
  NEXT
  FOR pos = 200 TO 100 STEP -1
    PULSOUT 0, pos
    PAUSE 19
  NEXT
  GOTO Main


Of course, you need to define a variable (Bx) called "pos".
Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

 ;D Awsome!! it works! the motor goes up to full speed then descends all the way back down.

             Awsome ;D Thank you.

JonnyMac

Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

December 20, 2008, 01:59:11 PM #9 Last Edit: December 20, 2008, 02:12:04 PM by Raisin-Toe
OK, I've got all my code worked out for this project; exept I ran out of Space :o to finnish it!

Here is everything that was able to fit. Is there a way to minimize the code?

This code drives a robot car around.

A PING sensor will sit on the servo (Labled servo).

The car start by driving eather forword or back depending on the distants between an obsticle, and the car

every time the car comes out of reverse mode, it checks for which direction to go next. [moves ping servo left (checks distance), then right (checks distance), then faces forward].
Whatever direction is more open the car will take that direction

Now the code that I did't have room for was, I need to at least tell the car to turn the wheels the oposite way when it goes into reverse. That way it is able to get around an obsticle


Sorry If the code is a mess, I just steal everyone elses code, and reorganize it. :D

perhaps the code can be simplified if I can get rid of the inches conversion, and just use the 'rawDist'. I just don't understand how it works. ::)

' {$STAMP BS1}

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

DIRS = %00000111 ' P0 - p2 are outputs, all others inputs

SYMBOL  Ping            = 6                      ' Ping Sensor

SYMBOL Motor            = 0                     ' Car Motor
SYMBOL steering         = 1                    ' Steering Servo
SYMBOL Servo            = 2                     ' Ping Servo
' -----[ Constants ]-------------------------------------------------------


SYMBOL  Trigger         = 1                     ' 10 uS trigger pulse
SYMBOL  Scale           = 10                    ' raw x 10.00 = uS

SYMBOL  RawToIn         = 889                   ' 1 / 73.746 (with **)
SYMBOL  RawToCm         = 2257                  ' 1 / 29.034 (with **)

SYMBOL  IsHigh          = 1                     ' for PULSOUT
SYMBOL  IsLow           = 0


' -----[ Variables ]-------------------------------------------------------
SYMBOL pos              = B9 ' servo position
SYMBOL delay            = B10
SYMBOL distance         = B11

SYMBOL  rawDist         = W1                    ' raw measurement
SYMBOL  inches          = W2
SYMBOL  inches_left     = W3

' -----[ Main Program ]----------------------------------------------------

Arm_motor:
  FOR pos = 150 TO 150
  PULSOUT motor, pos
  PAUSE 19
  NEXT
  GOSUB Get_Sonar
  inches = rawDist ** RawToIn
  IF inches < 11 THEN CRev


Run_motor:
  FOR pos = 170 TO 170
  PULSOUT motor, pos
  PAUSE 19
  NEXT
  GOSUB Get_Sonar
  inches = rawDist ** RawToIn
  IF inches < 11 THEN Stop_motor
  GOTO Run_Motor



Stop_Motor:
   FOR pos = 170 TO 100 STEP -1              ' ESC requires stop befor reverse
  PULSOUT motor, pos
  PAUSE 19
  NEXT
  GOTO Arm_motor                                    ' go back to Arm_motor to simplify code

CRev:
  FOR pos = 130 TO 130
  PULSOUT motor, pos
  PAUSE 19
  NEXT
  GOSUB Get_Sonar
  inches = rawDist ** RawToIn
  IF inches < 11 THEN CRev



' -----[ Steering ]--------------------------------------------------------

_Steering:
  GOSUB Check_Direction
  GOTO Run_Motor

Turn_Right:
  FOR pos = 150 TO 200
  FOR delay = 1 TO 2
  PULSOUT steering, pos
  PAUSE 10
  NEXT
  NEXT
  RETURN

Turn_Left:
  FOR pos = 150 TO 100 STEP -1
  FOR delay = 1 TO 2
  PULSOUT steering, pos
  PAUSE 10
  NEXT
  NEXT
  RETURN

' -----[ Direction servo ]-------------------------------------------------

Check_Direction:
  FOR pos = 150 TO 200                  ' Look Right
  FOR delay = 1 TO 2
  PULSOUT servo, pos
  PAUSE 10
  NEXT
  NEXT

  GOSUB Get_Sonar
  inches = rawDist ** RawToIn

  FOR pos = 200 TO 100 STEP -1
  FOR delay = 1 TO 2
  PULSOUT servo, pos
  PAUSE 10
  NEXT
  NEXT

 
  GOSUB Get_Sonar
  inches_left = rawDist ** RawToIn

FOR pos = 100 TO 150
  FOR delay = 1 TO 2
  PULSOUT servo, pos
  PAUSE 10
  NEXT
  NEXT

  IF inches >= inches_left THEN Sub_Right
  GOSUB Turn_Left
  RETURN

Sub_Right:
  GOSUB Turn_Right
  RETURN


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

Get_Sonar:
  LOW Ping                                      ' make trigger 0-1-0
  PULSOUT Ping, Trigger                         ' activate sensor
  PULSIN  Ping, IsHigh, rawDist                 ' measure echo pulse
  rawDist = rawDist * Scale                     ' convert to uS
  rawDist = rawDist / 2                         ' remove return trip

  RETURN

Raisin-Toe

I will need to use a battery for the power supply, will a 9.6V 650mAh work safely?

BigRez

Well, for one thing it looks like you've got some FOR...NEXT loops where you may not need them.  For example:

  FOR pos = 150 TO 150
  PULSOUT motor, pos
  PAUSE 19
  NEXT

does the same thing as

  PULSOUT motor, pos
  PAUSE 19

(without the for loop).  Setting up the FOR loop requires space.  You've got the above situation in the code a couple of times.  Then, you have another FOR loop with a nested loop. I'm not sure what the purpose of the second loop is but for example:


FOR pos = 150 TO 200
  FOR delay = 1 TO 2
  PULSOUT steering, pos
  PAUSE 10
  NEXT
  NEXT


Can be written as:

FOR pos = 150 TO 200
  PULSOUT steering, pos
  PAUSE 10
  PULSOUT steering, pos
  PAUSE 10
  NEXT

but if you're really just trying to double the pause there, you can have only one PULSOUT command and double the value of the pause.

Making just these few changes will give you a little breathing room.  I'm still looking at the code to see what better things can be done, but of course, when Jon answers, you'll get a lot of breathing room.   :D

JonnyMac

Give this code a look.  As BigRez pointed out you got some inefficiencies -- a FOR-NEXT loop with the same start and end values runs only once and is a waste of code space.  The program below seems to do everything you're doing and only uses about 60% of the EEPROM.  Please study it carefully before running it; since I don't have your hardware I may be assuming things incorrectly.

' =========================================================================
'
'   File......
'   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...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Ping            = 6                     ' Ping Sensor

SYMBOL  Servo           = 2                     ' Ping Servo
SYMBOL  Steering        = 1                     ' Steering Servo
SYMBOL  Motor           = 0                     ' Car Motor


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

SYMBOL  Trigger         = 1                     ' 10 uS trigger pulse
SYMBOL  Scale           = 10                     ' raw x 10 us

SYMBOL  RawToIn         = 889                   ' 1 / 73.746 (with **)
SYMBOL  RawToCm         = 2257                  ' 1 / 29.034 (with **)

SYMBOL  Pulse2In        = 4445                  ' pulse to inches

SYMBOL  IsHigh          = 1                     ' for PULSOUT
SYMBOL  IsLow           = 0


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

SYMBOL  speed           = B2
SYMBOL  sonarPos        = B3
SYMBOL  steeringPos     = B4
SYMBOL  hold            = B5

SYMBOL  dLeft           = W4
SYMBOL  distance        = W5


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

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


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

Arm_Motor:
  PULSOUT Motor, 150
  PAUSE 19
  GOSUB Get_Sonar
  IF distance < 11 THEN C_Rev

Run_Motor:
  PULSOUT Motor, 170
  PAUSE 19
  IF distance < 11 THEN Stop_motor
    GOTO Run_Motor

Stop_Motor:
  FOR speed = 170 TO 100 STEP -1
    PULSOUT Motor, speed
    PAUSE 19
  NEXT
  GOTO Arm_Motor

C_Rev:
  PULSOUT Motor, 130
  PAUSE 19
  GOSUB Get_Sonar
  IF distance < 11 THEN C_Rev
    GOTO Arm_Motor


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

Get_Sonar:
  LOW Ping                                      ' force 0-1-0 pulse
  PULSOUT Ping, Trigger                         ' activate sensor
  PULSIN  Ping, IsHigh, distance                ' measure echo pulse
  distance = distance ** Pulse2In               ' convert to inches
  RETURN

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

Steer_Me:
  GOSUB Check_Distance
  IF distance > dLeft  THEN Go_Right
  IF dLeft > distance THEN Go_Left
  RETURN

Go_Right:
  IF steeringPos >= 200 THEN Right_Exit
    PULSOUT Steering, steeringPos
    steeringPos = steeringPos + 1
    PAUSE 19
    GOTO Go_Right

Right_Exit:
  RETURN

Go_Left:
  IF steeringPos <= 100 THEN Left_Exit
    PULSOUT Steering, steeringPos
    steeringPos = steeringPos - 1
    PAUSE 19
    GOTO Go_Left

Left_Exit:
  RETURN

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

Check_Distance:
  IF sonarPos <= 100 THEN Measure_Left
    PULSOUT Servo, sonarPos
    PAUSE 19
    sonarPos = sonarPos - 1
    GOTO Check_Distance

Measure_Left:
  GOSUB Get_Sonar
  dLeft = distance

Check_Right:
  IF sonarPos >= 200 THEN Measure_Right
    PULSOUT Servo, sonarPos
    PAUSE 19
    sonarPos = sonarPos + 1
    GOTO Check_Right

Measure_Right:
  GOSUB Get_Sonar
  RETURN

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


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


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


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


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

Raisin-Toe

Thanks you both very much :), I was able to fit in the rest of my code, to turn the wheels opposite when the motor reverses. I've still got some bugs to work out though.

Thank you so much for the help Jon, but I've got to look at your program tomarrow, my mind is tangled with IF THEN GOTO GOSUB :o Turn_Right, pulsout Motor, 100 . . . Car must go that way after Get_Sonar 100 is the same as pos but now pos  = 200 . . . comand in wrong place . . .

I realy need to do some more programming in my spare time.

JonnyMac

Yes, it's best to learn to program during "fun time" so that when you have a project you can just sit down and knock it out.  If you'll describe what your program wants to do I can be more helpful.
Jon McPhalen
EFX-TEK Hollywood Office