Showing posts with label parallax. Show all posts
Showing posts with label parallax. Show all posts

Wednesday, 12 January 2011

On the importance of centering the servos

LEDs and Resistors
Circuit Built
Servos connected.


The next exercise in the manual is looking using an actual circuit on the breadboard, programmatically making two Light Emitting Diodes (LEDs)flash on and off.

This may seem like fairly basic stuff to some of you, and indeed it is, but thats exactly what I was looking for really. I have lots of theoretical knowledge and oodles of ideas, but actual hands on practical experience with electronics and circuits is pretty thin on the ground for me. If you are reading this after having dug through the archives of the blog to find out where it all started and you find this is a bit humbug for you, feel free to zip ahead. Those of you reading each post as I post it, well, you'll just have to put up with my learning pace.

The manual tells me I will need two red LEDs and two 470 ohm resistors for this test circuit, so digging into the box of bits I recieved, I found the little bag of electronics components and using the excellent instructions within the manual, identified the parts I needed.

Before anyone thinks this manual is similar to a recipe book, which tells you to add ingredients without telling you why, let me put things right.

While I had a fair idea of the concept of resistors and LEDs and so on, the purpose of each of them was never really clear to me. I had no idea that an LED can be compared to a one way valve for electricity, and similarly, I had no clue of what a resistor is used for. Some people might say the clue is in the name and to a point they would be right.

My point is, this manual is doing a fair job of giving me a practical grounding in the basics of electronics, which can only be a good thing.

Back to it.

The good news is, I didn't screw up the circuit. There is no bad news, this seems to be working well so far.

As you can see in the second picture, the LEDs are on, nothing seems to be visibly broken and I'm alive to type this. There were in fact a few different things to do in the exercise, mainly to do with making das blinkenflashen lights. It all worked, so thats good.

Next exercise is connecting the servo motors, which is going to be fun.

Simple enough to connect the servos, just had to change a jumper setting and connect the leads to the correct pins on the BOE. The next activity is centering the servos, as they will have left the factory in a workable but unknown state. Centering the servos puts them back to a known position, so circuits can use them with some precision.

Hmm, just shows what happens when you get cocky, part of centering the servos involves using a screwdriver on a potentiometer within the casing of the servo. I rather foolishly assumed it to be the handy phillips head screw in the middle of the servo horn and spent a few minutes cursing the thing for doing nothing. Still, got them done, no damage done.

Here is the code used to center these particular servos. Whether its the same for all servos I dont know yet. Interesting to find out though.

' P13 for manual centering

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

DEBUG "Program running!"

DO
  PULSOUT 13, 750
  PAUSE 20
LOOP

So, so far so good. I'll stop for a bit now and when I come back, it looks like we are mostly looking at mathematics and getting comfortable with using PBASIC. 

Time Control

Parallax Continuous Rotation Servos
Just to have an idea what sort of things we are looking at to start with from the manual, I'll occasionally post some of the code the exercise is asking me to perform.

The exercise I just finished is early in chapter 2, and is getting the concept of control flow and timing using the BOE and the BASIC Stamp microcontroller. Here is the code:

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

DEBUG "Start Timer..."

PAUSE 1000
DEBUG CR, "One second elapsed"

PAUSE 2000
DEBUG CR, "Three seconds elapsed"

DEBUG CR, "Done"

END
 As you can see, there isn't anything terribly magical about this. The programming language used is a specialised form of the BASIC language. Specifically, it is known as Parallax Beginners All-purpose Simple Instruction Code. Compared to Java, Python, Ruby and the .NET programming languages, BASIC and its variants operates at a significantly lower level.

The reason time control is important, is because when we are operating the servos (pictured) we are essentially sending digital signals to an analogue device. Because we are operating at such a low level, we can't simply give the device a goal and expect it to get on with it, we actually have to teach it how to use itself. When we want these servos to actually start moving, what we really need to be doing is telling the microcontroller how long to supply electricity to the servo in order to make it function. When electricity is applied to the servo, the control horn rotates.

In order to precisely control the servo, we need to have some fairly fine control over how long we apply power to it, right?

In the program listing above, the numbers are referring to milliseconds, or thousandths of a second. 1000 milliseconds = 1 second.

The word DEBUG is simply an instruction to the microcontroller to send the text in quotes back to the terminal, the CR simply represents a carriage return.

The statements with a single quote in front of them are compiler directives. All I know at this stage is, those two are necessary.

The program above, when run, produces the following output:
Start Timer...
One second elapsed
Three seconds elapsed
Done
Pretty much as expected, so far so good.

Gets more interesting when you consider that while a thousanth of a second seems like it passes pretty quickly, two millionths of a second is the base time granularity of the BASIC Stamp 2 (BS2).

Pretty well blew me away when I found that out.

I mean, we all know computers are quick, but have you ever stopped to consider exactly how quick? Divide a second by one thousand, you have a millisecond. Divide that millisecond by a thousand, you have a microsecond, also referred to as μs. Thats not "us" with an unusual accent.

According to that bastion of incontrovertible truth, Wikipedia, it takes 5.4 microseconds for light to travel 1 mile in a vacuum. In addition, the length of a day increases by 15 microseconds due to the tidal pull of the moon, but 2.68 microseconds was subtracted from the length of the day as a result of the 2004 Indian Ocean earthquake.

Who measures these things?

In any case, two of those microseconds is theoretically the shortest period of time I can apply power to those servos. In reality, I dont think anything would move in 2 microseconds, but when I actually get to that part of the book, I'll have a go and let you know.

Tuesday, 11 January 2011

Unboxing? Sorta kinda.


I was originally going to do a grand unboxing of the bot, but I'm actually so keen to get into it, I'm not going to bother.

Instead, I'm going to go through the exercises included in the impressive looking manual "Robotics with the Boe-bot" which accompanied the bot. Hundreds of pages long, I've looked at the first few chapters and am already impressed with what this little bot can do, I fully expect that once I'm finished these exercises, I'll be doing some interesting experiments.

In the picture, you can see the manual, the Board of Education experiment board (BOE), the BASIC Samp 2 module, the rubber feet for the BOE and the stylish and really rather classy Parallax screwdriver.

Keep in mind here please, I'm going between posting these entries on my phone as well as posting them on my computer and I'm using different software for each method. If there are any formatting inconsistencies on these early posts, thats why.

Update:

Having finished chapter 1 of the manual, I have to say I'm impressed. While I'm hardly any kind of expert in these things, the guys at Parallax have included enough FlashenBlinken lights on the board to let me know I'm making progress with the simple stuff.

The first chapter had me revisiting a few topics I already had some knowledge of, but I've resisted the urge and pushed through with the stuff on ASCII numbers and basic commands like using

DEBUG
to output back to the computer rather than commands like
cout
or my "native"
System.out.println("Yes, I was taught java as a first language");


Probably a good idea to get the basics, no matter how impatient I am. Hopefully doing some more tonight, chapter 2 is about connecting up the servos!

Parallax Boe-bot kit.

Frosty piss!

That's slashdot for first post. Since I'm posting this from my mobile phone, it isn't going to be a huge post.

At the weekend, I ordered a this kit from active-robots.co.uk, for the low price of £126 + p&p, all up around £135.

Included in the kit is the BASIC Stamp 2 microcontroller, Parallax Board of Education electronics development board and electronics components including passive sensors and servos required to build the Boe-bot.

I have a specific project in mind once I have completed the exercises included in this kit, but I'll get into that later. For the moment, I'll be blogging mainly about what I'm doing with this robot, with the occasional rant about politics or the popular media. I'll tag things though so you can avoid those bits though.