Shop OBEX P1 Docs P2 Docs Learn Events
4 servo control help — Parallax Forums

4 servo control help

GrampsGramps Posts: 117
edited 2010-08-15 18:44 in BASIC Stamp
Good morning to all,

This code does work, except it runs way too slow.

How do we speed it up?

Gramps

' {$STAMP BS2}
' {$PBASIC 2.5}

Initialize:
servo1 PIN 12 'servo pins 12 through 15 on BOE
servo2 PIN 13
servo3 PIN 14
servo4 PIN 15
'servo5 PIN
'servo6 PIN

Pot1 PIN 5
Pot2 PIN 6
Pot3 PIN 7
Pot4 PIN 8
'Pot5 PIN
'Pot6 PIN

time VAR Word(6)

PotIndex VAR Nib

CenterPots:
FOR PotIndex = 0 TO 5
time(PotIndex) = 500
NEXT

MainLoop:
PULSOUT servo1, time(0) '1-2ms
PULSOUT servo2, time(1) '1-2ms
PULSOUT servo3, time(2) '1-2ms
PULSOUT servo4, time(3) '1-2ms
'PULSOUT servo5, time(4) '1-2ms
'PULSOUT servo6, time(5) '1-2ms (6ms to 12ms + overhead for the PULSOUT command)
GOSUB OnePot
GOSUB OnePot
GOTO MainLoop

OnePot:
HIGH Pot1 + PotIndex
PAUSE 4
RCTIME Pot1 + PotIndex, 1, time(PotIndex)

time(PotIndex) = time(PotIndex) */ 550 ' Scale by 0.724 (X 256 for */).
time(PotIndex) = time(PotIndex) + 400 ' Offset by 500.

PotIndex = PotIndex + 1
PotIndex = PotIndex // 5
RETURN

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'What is your life?"
"It is even a vapor that appears for a
little time and then vanishes away."
Saint James 61 A.D.

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2010-08-02 13:09
    Why are you doing "GOSUB OnePot" twice?

    And we TOLD you a BS2 could only control 3 servo's -- it just doesn't have enough processing power for more. A BS2sx or greater might handle it, or definitely a Propeller.
  • GrampsGramps Posts: 117
    edited 2010-08-02 13:13
    Why are you doing "GOSUB OnePot" twice?

    Typo..............

    Grms

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'What is your life?"
    "It is even a vapor that appears for a
    little time and then vanishes away."
    Saint James 61 A.D.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-02 13:18
    The RCTIME statement can take up to 131ms to execute depending on the RC time constant of whatever is connected to the Stamp's I/O pin. Figure that out and make it smaller, and the program will go faster. You've got 4 to 8ms already tied up in PULSOUT statements plus two RCTIME statements. The RC time constants will need to be less than 6ms to meet your 20ms overall time limit for the main loop.
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2010-08-02 15:37
    allanlane5,
    Why are you doing "GOSUB OnePot" twice? ... this was an easy way to test for two POTs for every iteration of the servo.


    Gramps,
    How do we speed it up? ... you need to optimize the R and C values so that the RCTIME command spends as little time as possible reading the POT. and/or reduce the two GOSUBs mentioned earlier down to one GOSUB.

    You could also (with a smaller CAP value) reduce the command that reads PAUSE 4 to something like PAUSE 1


    Note:
    In changing the RC constant, you will also need to change the Scale and Offset formula, So a DEBUG only version without sending a PULSOUT signal and just looking at the raw returned values will be necessary.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • allanlane5allanlane5 Posts: 3,815
    edited 2010-08-02 15:43
    You could also read the pots every other time, or every third time --

    PotTime VAR BYTE

    PotTime = 0
    ...
    ...
    PotTime = Pot Time + 1
    IF PotTime = 3 THEN
    · PotTime = 0
    · GOSUB OnePot
    ELSE
    · PAUSE 10 ' or whatever value makes it work...
    ENDIF
    ...
    ...
  • GrampsGramps Posts: 117
    edited 2010-08-02 21:44
    Now we've somehow crashed the USB port so the BS editor will not find it.
    Rebooting didn't help.


    How do we fix this?



    Gramps


    >

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'What is your life?"
    "It is even a vapor that appears for a
    little time and then vanishes away."
    Saint James 61 A.D.

    Post Edited (Gramps) : 8/3/2010 12:30:21 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2010-08-03 13:27
    Unplug the USB device. Reboot. Plug in the USB device. It should find the right loader at that point.

    If it doesn't:
    Unplug the USB device. Reinstall the USB device driver. Plug in the USB device. That should fix it.
  • GrampsGramps Posts: 117
    edited 2010-08-04 00:55
    Unplug the USB device. Reboot. Plug in the USB device. It should find the right loader at that point.


    That did not work...........

    If it doesn't:
    Unplug the USB device. Reinstall the USB device driver. Plug in the USB device. That should fix it.


    How to reinstall the device driver?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'What is your life?"
    "It is even a vapor that appears for a
    little time and then vanishes away."
    Saint James 61 A.D.
  • ercoerco Posts: 20,256
    edited 2010-08-04 03:31
    Gramps: You need to insert the CD with the driver files. Got CD? Maybe you can download them, too.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • lancee7lancee7 Posts: 1
    edited 2010-08-04 08:08
    Hi,
    Nakapagsimulate na po kami.
    At nakuha na namin yung mga errors namin.
    May mali sa code namin pero naagapan din.

    If you're interested 'eto po yung gumanang code:

    Code:

    //*-._.-.-._.-.-._.-.-._.-.
    #include <eZ8.h> // |
    #include "servo.h" // |
    #include "gpio.h" // |
    #include "timer.h" // |
    //*_.-._.-.-._.-.-._.-.-._.

    // Default user flash optionbits.
    FLASH_OPTION1 = 0xFF;
    FLASH_OPTION2 = 0xFF;

    //Global Variable .-._.-.

    char subtmr=10;
    unsigned char t1=0;
    unsigned char t2=0;
    unsigned char t3=0;
    unsigned char t4=0;
    unsigned char t5=0;
    int lt1; //|
    //-._.-._.-._.-._.-._.-._.

    unsigned char test_variable = 0;

    void idle(unsigned char);
    void test_all_motor();
    void another();

    //Main Program-._.-._.-._.-
    void main ()
    {

    init_gpio(); //Default Initialization of I/O Ports
    DI(); //Disable Interrupts
    init_timer0(); //Default Initialization of Timer0
    EI(); Enable Interrupts
    idle(10); //nop for 1 sec to wake up the servo sequencer
    servo_ON(1);

    while(1)
    {
    test_all_motor();
    test_variable++;
    if(test_variable==5) another();
    } // end of while
    } // End of main program

    void idle(unsigned char delay)
    {
    t1=delay;
    while(t1);
    }

    void test_all_motor()
    {
    move(1,-90,1);
    move(2,-90,1);
    move(3,-90,1);
    move(4,-90,1);
    move(5,-90,1);
    move(6,-90,1);
    move(7,-90,1);
    move(8,-90,1);
    idle(5);
    move(1,0,1);
    move(2,0,1);
    move(3,0,1);
    move(4,0,1);
    move(5,0,1);
    move(6,0,1);
    move(7,0,1);
    move(8,0,1);
    idle(5);
    move(1,90,1);
    move(2,90,1);
    move(3,90,1);
    move(4,90,1);
    move(5,90,1);
    move(6,90,1);
    move(7,90,1);
    move(8,90,1);
    idle(5);
    return 0;
    }

    void another()
    {
    move(1,45,1);
    move(2,45,1);
    move(3,45,1);
    move(4,45,1);
    move(5,45,1);
    move(6,45,1);
    move(7,45,1);
    move(8,45,1);
    idle(5);
    move(1,-45,1);
    move(2,-45,1);
    move(3,-45,1);
    move(4,-45,1);
    move(5,-45,1);
    move(6,-45,1);
    move(7,-45,1);
    move(8,-45,1);
    idle(5);
    test_variable = 0;
    return 0;
    }


    Changes:
    - Nilagyan ng ; yung pagkatapos sa test_variable++.
    - Nilipat yung EI(); pagkatapos ng init_timer0();

    Tanong:
    Tama po ba yung code?
    Pede po ba itong code sa Zilog?
    Para san po ba yung FLASH_OPTION1 = 0xFF; FLASH_OPTION2 = 0xFF;?
    Pede po bang makahingi ng sample source code na gumagamit ng Sequencer at Controller (yung meron sanang communication gamit yung UHF at computer)?
    Any suggestion po para mapaliit yung code?

    Sorry po kung naabala at salamat po in advance...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    gw2 gold

    Post Edited (lancee7) : 8/4/2010 8:13:00 AM GMT
  • GrampsGramps Posts: 117
    edited 2010-08-04 12:07
    Google actually translated this at

    http://www.electronicslab.ph/forum/index.php?topic=18529.0

    Gramps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'What is your life?"
    "It is even a vapor that appears for a
    little time and then vanishes away."
    Saint James 61 A.D.
  • ercoerco Posts: 20,256
    edited 2010-08-05 15:33
    Gramps, you gotta get past that USB problem and get Shadow-Bot going if you·hope to keep up with them dang·DARPA boys and get a government grant for 34 million dollars!

    http://www.sciencedaily.com/releases/2010/08/100804081227.htm




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • GrampsGramps Posts: 117
    edited 2010-08-05 15:45
    @erco,
    Nice arm!!!! WOW!!! Jaw dropping!!

    I think we have $400 in this one so far............

    "Weighs 9 pounds"

    We are around 50 pounds or so................

    At this point we're moving ahead with the control harness and wiring a Prop servo controller.
    OBC is writing Prop code for a demo of the arm at UPConvention in Ohio end of this month.
    So we may be testing with a Prop instead of a stamp, hopefully, this week.


    Gramps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'What is your life?"
    "It is even a vapor that appears for a
    little time and then vanishes away."
    Saint James 61 A.D.

    Post Edited (Gramps) : 8/5/2010 3:50:20 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2010-08-05 17:35
    Wow, I had no idea prosthetics had gotten to that point. I live "down the road" about 20 miles from JHU-APL, amazing what they get up to. Johns-Hopkins is also a large medical University, so bio-mechanicals would be right up their alley.
  • GrampsGramps Posts: 117
    edited 2010-08-05 17:42
    Providing nearly as much dexterity as a natural limb, the MPL is capable of unprecedented mechanical agility and is designed to respond to a user's thoughts.



    Incredible!!!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'What is your life?"
    "It is even a vapor that appears for a
    little time and then vanishes away."
    Saint James 61 A.D.
  • ercoerco Posts: 20,256
    edited 2010-08-05 20:19
    A Prop is good. I still say a Stamp·should be·up to the task of controlling more than 4 servos, depending on the load. I've started building a BS2E-controlled multi-servo (5 or 6 DOF) robot arm (small by Gramps' standards!), will advise when I have something to show. I have a few "stupid servo tricks" up my sleeve.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • GrampsGramps Posts: 117
    edited 2010-08-05 22:28
    We're going to need a high torque servo like this one:

    http://www3.towerhobbies.com/cgi-bin/wti0001p?&I=LXUZ89&P=M

    at 133 oz in at 6v, this guy is powerful!

    is here a cheaper one someplace?.


    Gramps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'What is your life?"
    "It is even a vapor that appears for a
    little time and then vanishes away."
    Saint James 61 A.D.

    Post Edited (Gramps) : 8/5/2010 10:56:51 PM GMT
  • GrampsGramps Posts: 117
    edited 2010-08-06 08:36
    OBC sent me a servo controller. It's this one:

    Parallax Servo Controller (#28023) – Rev B
    16-Channel Servo Control with Ramping

    Nice! Might be useful.


    Gramps
  • GrampsGramps Posts: 117
    edited 2010-08-09 20:42
    First post on the new system.
    Rapping up the bot arm to take to Ohio next week.
    Rather then buying a new hippo servo, we converted the wrist rotation servo to continuous duty and stuck in a 6:1 gear. Works nice now!


    Gramps
  • ercoerco Posts: 20,256
    edited 2010-08-11 09:22
    So the robot's continuous wrist servo is always slowly rotating (6:1) unless you keep your wrist centered? Interesting ergonomics. If God intended man to have continuously rotating wrists, he would have made us that way!
  • GrampsGramps Posts: 117
    edited 2010-08-11 18:31
    We wanted the wrist servo to only turn 180 degrees so it will track the human wrist in the control harness. That's why we removed the pot from inside the servo body and mounted it on the larger gear as seen in the photo.
    800 x 600 - 52K
  • ercoerco Posts: 20,256
    edited 2010-08-15 00:07
    Gramps: I'm probably too late with this thought, I think you're wrapping up Shadow Bot to take somewhere (UPENE perhaps?). I'm doing a lot of servo work for a new magazine article, which includes a very simple servo driver circuit that reads a pot and positions a servo accordingly. It's a very simple hardware circuit (no Stamp, no Prop, no Servo controller) that uses one LM556 timer and some caps & resistors, and a 10K pot for each servo. I just breadboarded the circuit tonite, it's very simple and works quite well. It drives the servo to each mechanical stop (about 180 degrees). I'm sure it's been done many times before, but I had fun designing it myself with all the great info at http://www.kpsec.freeuk.com/555timer.htm .

    I'm not sure how far you took Shadow Bot. With a processor, you could teach the arm a sequence and have it stored for playback, that's a great thing. In your thread, you only mentioned driving it "live", reading 4 pots and driving 4 servos. If that's all you need for now, you could use a hardware solution like mine (4 independent circuits, but they are simple). Let me know if this is of any interest, I'll make a schematic in the next day or so.
  • GrampsGramps Posts: 117
    edited 2010-08-15 18:44
    yes we're packed and heading for Ohio (UPENE) in the morning.
    Your idea is great. Please post it on the thread later. I love simple solutions.
    We're also interested in learning more about using servos and would like to read your article when published!
    "Live" control as well as auto-mode is in the plan.
    This arm is step one of a planned 6 foot balance-bot with telepresence, using my scooter frame for a base, an ongoing project that i expect to tinker with for the next several years. Already have learned some things and hope to design the second arm to be even more useful then this one.

    Thanks for your input!


    Gramps
    P.S. OBC said this photo reminded him of that hand that would come out of it's box and grab a penny.......
    800 x 600 - 72K
Sign In or Register to comment.