4 servo control help
Gramps
Posts: 117
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.
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
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.
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.
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.
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
...
...
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
If it doesn't:
Unplug the USB device. Reinstall the USB device driver. Plug in the USB device. That should fix it.
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
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
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.
http://www.sciencedaily.com/releases/2010/08/100804081227.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
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
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
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
Parallax Servo Controller (#28023) Rev B
16-Channel Servo Control with Ramping
Nice! Might be useful.
Gramps
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
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.
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.......