Shop OBEX P1 Docs P2 Docs Learn Events
servo control --stamp selection — Parallax Forums

servo control --stamp selection

Brent12345Brent12345 Posts: 7
edited 2007-10-31 22:51 in General Discussion
Hello,

·I'm new to microcontrollers. I am building a·controller to control 5 servos for an apparatus··using two joysticks (2Xpotentiometers per joystick). I'm using a switch to toggle one of the joysticks between servo·motors (i.e joy1 controls either servo #1 or #2&3, Joy2 always controlls Servos 4&5). I am sending serial outputs to a 16 channel Parallax servo controller.

I have 3 devices with 5 servos each, and I will be switching the controller between each device (total of 15 servos). Currently, using a BS2, I have one·joystick controlling·two servos using RCtime and it seems to work well.

·My problem is that I don't have enough variables left to do what I want. Would it be better to utilize two BS2s or move to a different microcontroller such as a Javelin--I have a little bit of Java experience, but I'm not a programer.

·Thanks,

·Brent

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-10-31 19:17
    What's eating up your variable space? Can you show us the program you have so far? I'll bet there's a way to make everything fit.

    -Phil
  • Brent12345Brent12345 Posts: 7
    edited 2007-10-31 19:40
    The servos are set for continuous rotation. I basically just repeated the code to allow 4 servos to be controlled simultaneously with two joysticks.·The initialization was used to stop the servos for wandering on powerup. It works, but I may need to send a continuous feed. ·I know I can simplify the cuircit to reduce the VARs, but I was not getting the control I wanted with the joy stick. I still need to control LEDS, a button to toggle each device, and a switch to toggle·servos on one·of the joy sticks.·This simple approach seemed to work well--but·it consumes the VARS. I was considering using a while-do type loop to·monitor the joysticks and reduce vars that way...
    thanks for the help







    '
    [noparse][[/noparse]I/O Definitions]

    PotCw·· PIN· 0·· 'cw clock input
    PotCCW· PIN 1·· 'ccw pot input

    PotCw2· PIN· 2·· 'cw clock input
    PotCCW2 PIN 3·· 'ccw pot input

    PotCw3· PIN· 4·· 'cw clock input
    PotCCW3 PIN 5·· 'ccw pot input

    PotCw4· PIN· 6·· 'cw clock input
    PotCCW4 PIN 7·· 'ccw pot input


    '
    [noparse][[/noparse]Constants]

    Scale· CON $0068 ' to scale rc time value



    '
    [noparse][[/noparse]Variables]
    '
    Joy1-POT1
    rcRt· VAR Word·· 'rc reading right
    rcLf· VAR Word·· 'rc reading left

    sPos· VAR Word·· 'servo position

    pw··· VAR Word·· 'serial out servo position
    ch··· VAR Byte·· 'servo channel on servo controller --serial out
    ra··· VAR Byte·· 'servo rapping speed --serial out
    ·'
    POT2
    rcRt2· VAR Word·· 'rc reading right
    rcLf2· VAR Word·· 'rc reading left

    sPos2· VAR Word·· 'servo position

    pw2··· VAR Word·· 'serial out servo position
    ch2··· VAR Byte·· 'servo channel on servo controller --serial out
    ra2··· VAR Byte·· 'servo rapping speed --serial out
    '
    JOY2--POT3
    rcRt3· VAR Word·· 'rc reading right
    rcLf3· VAR Word·· 'rc reading left

    sPos3· VAR Word·· 'servo position

    pw3··· VAR Word·· 'serial out servo position
    ch3··· VAR Byte·· 'servo channel on servo controller --serial out
    ra3··· VAR Byte·· 'servo rapping speed --serial out
    '
    POT4
    rcRt4· VAR Word·· 'rc reading right
    rcLf4· VAR Word·· 'rc reading left

    sPos4· VAR Word·· 'servo position

    pw4··· VAR Word·· 'serial out servo position
    ch4··· VAR Byte·· 'servo channel on servo controller --serial out
    ra4··· VAR Byte·· 'servo rapping speed --serial out

    Ch_INI VAR Byte


    '
    [noparse][[/noparse]CONSTANTS]

    sDat· CON 15·· 'output pin for serial out
    baud· CON 396


    '
    [noparse][[/noparse]Initialization]
    initialize:··········· 'send stop pulse all 16 servo channels to prevent wandering
    ra = 0
    pw = 744



    FOR Ch_INI = 0 TO 15

    SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", Ch_INI, ra, pw.LOWBYTE, pw.HIGHBYTE, CR]
    NEXT
    GOTO Main
    END

    '
    [noparse][[/noparse]Program Code]


    ·Main:

    ·ra = 0
    ·ra2 = 0········· 'set servo rampping rate
    ·ch = 0········· 'set servo channel on servo control board
    ·ch2 = 1

    ·ra3 = 0
    ·ra4 = 0········· 'set servo rampping rate
    ·ch3 = 0········· 'set servo channel on servo control board
    ·ch4 = 1


    · HIGH PotCW
    · PAUSE 1
    · RCTIME PotCW, 1, rcRt

    · HIGH PotCCW
    · PAUSE 1
    · RCTIME PotCCW, 1, rcLf


    · HIGH PotCW2
    · PAUSE 1
    · RCTIME PotCW2, 1, rcRt2

    · HIGH PotCCW2
    · PAUSE 1
    · RCTIME PotCCW2, 1, rcLf2

    · HIGH PotCW3
    · PAUSE 1
    · RCTIME PotCW3, 1, rcRt3

    · HIGH PotCCW4
    · PAUSE 1
    · RCTIME PotCCW4, 1, rcLf4

    · rcRt = (rcRt */Scale)· MAX 700
    · rcLf = (rcLf */ Scale)· MAX 700
    · sPOS = RCLf - rcRt

    · rcRt2 = (rcRt2 */Scale)· MAX 700
    · rcLf2 = (rcLf2 */ Scale)· MAX 700
    · sPOS2 = RCLf2 - rcRt2

    · rcRt3 = (rcRt3 */Scale)· MAX 700
    · rcLf3 = (rcLf3 */ Scale)· MAX 700
    · sPOS3 = RCLf3 - rcRt3

    · rcRt4 = (rcRt4 */Scale)· MAX 700
    · rcLf4 = (rcLf4 */ Scale)· MAX 700
    · sPOS4 = RCLf4 - rcRt4

    · pw = 777 + spos
    · pw2 = 747 + spos2

    · pw3 = 777 + spos3
    · pw4 = 747 + spos4

    · SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch, ra, pw.LOWBYTE, pw.HIGHBYTE, CR]
    · PAUSE·· 20

    · SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch2, ra2, pw2.LOWBYTE, pw2.HIGHBYTE, CR]
    · PAUSE·· 20

    · SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch3, ra3, pw3.LOWBYTE, pw3.HIGHBYTE, CR]
    · PAUSE·· 20

    · SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch4, ra4, pw4.LOWBYTE, pw4· .HIGHBYTE, CR]
    · PAUSE·· 20

    · GOTO Main
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-10-31 20:21
    You can consider a BS2SX which has a 126byte scratchpad that you can use
    to store variables. You then use GET/PUT to retrieve/store values from/to the scratchpad.
    The BS2SX, like the BS2, only has 26 bytes of named variables.

    The javelin has a total ram of 32 kilobyte, that is for code + variables.
    You say you have a little java experience. Javelin java is much simpler
    than PC java so you should be able to program the javelin in no time.

    regards peter
  • Brent12345Brent12345 Posts: 7
    edited 2007-10-31 22:51
    Thanks everyone--I happen to have a BS2SX as well. I'll try using the scratchpad ram and see if I can all fit --otherwise I'll check out the Javelin.
Sign In or Register to comment.