misc >> Controlling servos in BASIC

by Stompy1 » Wed, 19 Apr 2006 23:08:58 GMT

Hello,

I apologise in advance for this, if it is long and slightly confusing!

I'm relatively new at programming, but for my final year project I've
designed and built a pole climbing robot (No photos yet, but I have a
visualisation here:
http://img.photobucket.com/albums/v412/Stompy1/bodytemplatewithlid.jpg).
I've got a PICAXE microcontroller for the 'brains' of the robot and I'm
having difficulties getting off the ground.

Can anyone give me some help on programming BASIC to control servos?
The robot comprises of four servos, one for each arm, one for each
hand. One hand grips the pole and that arm pulls the robot up, while
the other hand is open and moves over it.
(http://img.photobucket.com/albums/v412/Stompy1/climbrobotclimb.png)
So, each arm servo moves from '-40 degrees to 40 degrees' and back
again, repeatedly, while the hand servos close to grip the pole as the
arm moves down. These are the most basic actions required to enable
climbing of the pole and I would like to know the best way of
programming this.

For the grippers, I have heard that servos can 'sense' when a certain
level of grip has been achieved by using the positioning sensor within
the servo to determine when the servo is no longer moving. Is this
true, and how can I programme this kind of functionality in? As in, the
gripper closes around the pole until a point when the servo is no
longer spinning (ie, the pole is stopping the gripper from closing
further). There is, of course, the option of using microswitches (and
other sensors) for pole sensing, etc, if this is not possible.

I hope this isn't too much, any help in servo programming would be
helpful, even if its just a description of how servos work and the
corresponding code.

Many thanks,

James


misc >> Controlling servos in BASIC

by Greg Neill » Thu, 20 Apr 2006 00:02:46 GMT



Sounds like you might want to lay your hands on a copy of
"Real Time Programming - Neglected Topics" by Caxton Foster.
It's an excellent hands-on, how-to guide for this sort of
thing.

He uses simple assembly language examples, but you can
probably implement in BASIC with the speed of today's
machines. Many BASIC's allow in-line assembly code, too.

Here's a link to Amazon:

http://www.amazon.com/gp/offer-listing/020101937X/ref=dp_olp_2/002-5230129-1572810? %5Fencoding=UTF8

misc >> Controlling servos in BASIC

by Stompy1 » Thu, 20 Apr 2006 03:15:02 GMT

Thank you, I've just checked my library, they've got a copy for me!

misc >> Controlling servos in BASIC

by shb*NO*SPAM* » Thu, 20 Apr 2006 09:14:32 GMT


If you get a servo controller that can be controlled via the
serial port, then you can control it to some degree with notepad
and batch files. I've got a site below with some simple servo
control stuff. You might also want to check the
comp.robotics.misc news group for robotic info.

http://www.geocities.com/zoomkat/ezservo.htm

misc >> Controlling servos in BASIC

by Stompy1 » Mon, 24 Apr 2006 23:50:35 GMT

Your website is very interesting, I particularily like the movable
webcam!
I've also withdrawn that book, very interesting also, but not answering
the low-level questions I have!

I'm at the stage where I can tell a servo to move to a specific
postion, I've also been fiddling with microswitches, so a press of the
switch causes the servo to do some stuff:


symbol RARM = 2


main: if pin3 = 0 then loop
goto main


loop: servo RARM,75
pause 1000
servo RARM,220
pause 1000
if pin3 = 1 then main
goto loop


(Its a little over-complicated, but only because I'm using it to
investigate how it works.)


The two things I would like to know are as follows:


1) How do I programme the servo to move more slowly?
2) I want a microswitch to - when depressed - interrupt the servo's
movement, regardless of its position (i.e: on my robot, a microswitch
has been mounted at the limit of its arm's gaits. The arm reaches the
limit, the microswitch is depressed, which means the servo must go back

again.

misc >> Controlling servos in BASIC

by Stompy1 » Mon, 24 Apr 2006 23:51:47 GMT

Your website is very interesting! I particularily like the movable
webcam!
I withdrew the book, but as interesting as it looks, its not answeing
the low level questions I've got!

I'm at the stage where I can tell a servo to move to a specific
postion, I've also been fiddling with microswitches, so a press of the
switch causes the servo to do some stuff:


symbol RARM = 2


main: if pin3 = 0 then loop
goto main


loop: servo RARM,75
pause 1000
servo RARM,220
pause 1000
if pin3 = 1 then main
goto loop


(Its a little over-complicated, but only because I'm using it to
investigate how it works.)


The two things I would like to know are as follows:


1) How do I programme the servo to move more slowly?
2) I want a microswitch to - when depressed - interrupt the servo's
movement, regardless of its position (i.e: on my robot, a microswitch
has been mounted at the limit of its arm's gaits. The arm reaches the
limit, the microswitch is depressed, which means the servo must go back

again.

misc >> Controlling servos in BASIC

by shb*NO*SPAM* » Tue, 25 Apr 2006 06:44:37 GMT


You move the servo in small increments with a slight pause in
between instead of one single move.


The change in limit switch status would have to be seen by the
program controlling the servo, which would then tell the servo to
go to a new position. Probably best to use a pc to do all the
controlling until the programming requirements are well
understood.

misc >> Controlling servos in BASIC

by david.williams » Wed, 26 Apr 2006 05:12:47 GMT

-> The two things I would like to know are as follows:


-> 1) How do I programme the servo to move more slowly?
-> 2) I want a microswitch to - when depressed - interrupt the servo's
-> movement, regardless of its position (i.e: on my robot, a microswitch
-> has been mounted at the limit of its arm's gaits. The arm reaches the
-> limit, the microswitch is depressed, which means the servo must go back

-> again.

You can only program what your hardware can do.

If your servo is basically a DC electric motor, then its speed can be
varied by varying the voltage of its power supply. Ideally, this would
involve having some sort of hardware that changes the voltage, and
sending a control signal from the computer to this hardware. Your
program would just determine what this control signal should be. That
should be easy. Alternatively, and rather more difficult, you might
make the computer turn the power to the motor on and off very rapidly -
many times per second - so the "average" voltage that the motor
receives is determined by the on:off (or "mark:space") ratio. To do
this, the computer would have to devote time to this task, maybe not
continuously, but at frequent intervals. This would make it more
difficult for the computer to pat attention to other tasks, such as
watching microswitches.

Another possibility is that your servo may contain a "stepping motor".
This is a machine that moves in small steps when its coils receive
changing voltages. The computer, os some other hardware, has to send a
*sequence* of voltages to the motor, and the speed of this determines
the speed of the motor. This allows very precise control, but needs
more complex programming than a simple motor.

Watching a microswitch so the motor can be stopped when it closes (or
opens) requires the computer to run the motor and watch the switch
essentially simultaneously. Some sort of interrupt coding can be used.
Alternatively, the program can alternate rapidly between the two tasks.
Or maybe the motor hardware can be such that the computer doesn't have
to do anything while the motor is running, only when it starts or
stops.

The basic point is that you must fully understand how your hardware
works and what its requirements are *before* you can start writing your
program. Preferably, you should design and build the hardware yourself,
so you will thoroughly understand it.

dow