Home Products Shop Articles Applications Learning Zone About Us

  • Up


















  • Lego + PC-Control + Plain English
    (Lego Maze Solver Using a Servo Hawk )

    Submitted by Gerry & Chuckles Rzeppa, Kentucky, USA

     
        Hello! My name is Chuckles Rzeppa. I'm ten years old. This is a picture of me with my mom and dad:  And yes, my parents are really old. My mom was 57 when she gave birth to me. But that's a different story.
        This story is about how we used a PC-Control Multi-Servo Hawk Starter Kit to automate a Lego Maze.

    This is the starter kit:                                                    And this is the Lego Maze:










         

        My dad wanted to do a Rubik's Cube Solver, but since this was my first computer automation project, my mom thought we should start with something easier. "A small success," she said, "is more impressive than a big failure." So we went with the maze.

    We started by putting together the Lego Frame just like the instructions said. That was easy because I've put together a lot of Lego stuff. When we were done it looked like this -->



      The front knob makes the frame tilt left and right; the side knob makes it tilt forward and backwards. Then we planned our maze using the built-in what-you-see-is-what-you-get page editor that comes with the Plain English programming system.

    This is what the plan looked like:


    That was fun, but it was more fun to actually build the maze out of Lego. I added a castle and a tunnel and some houses and trees to make it less boring. My dad said that was okay because great engineering should be "fair as well as functional." He means that it should not just work, it should look cool, too. Here's the maze sitting in the Lego frame:
        We tried it out by hand with a little orange ball. It worked great. But I thought it would. As I said before, I've built a lot of Lego stuff. On to the exciting part. We built a platform the same size as the Lego frame with places for the battery pack, the Hawk servo board, and two servos. We didn't need the third servo that came with the kit, but it was nice to know we had a spare.We connected the servos to Lego axles and gears so they would mesh with the knobs on the Lego frame when we set it on top of our platform. The hard part was finding pieces to connect the servos to the Lego axles. My dad was suprised that he couldn't find them on the internet. He said, "The great thing about standards, Chuckles, is that there are so many to choose from." Then he laughed a little, but he looked sad. He drilled out some Lego pieces to make them fit. We also put some little screws in four corner pieces so the Lego frame wouldn't slide around when we put it on top of the platform.  After everything was in place, we connected the battery pack to the circuit board with a small screwdriver. My dad really liked the built-in switch on the battery pack. Then we plugged in the servos. The only hard part was figuring out that the brown wire should have been black. This is what it looked like when we were done:


    And this is what it looked like when we put the Lego frame and maze on top:



    Pretty cool, even if I do say so myself. And that's it for the hardware. Time to code up the software.

        My dad said we should start by telling the computer about our hardware, so we got back into the Plain English programming system and he told me what to type. My dad believes that the best way to learn something is to imitate someone who already knows what he's doing rather than try to reinvent the wheel all by yourself. Anyway, this is what I typed: 
    click to enlarge (opens in new window)


        Then my dad said we'd be needing some low-level helper routines to talk to the Hawk servo board. There were only three of them, but it took us a while to figure them out because the Hawk servo manual is crammed in with all the other Hawk manuals in one big file. My dad didn't like that, but he got over it pretty quickly because, he said, the documentation was very clear and complete. Anyway, he talked and I typed:
    click to enlarge (opens in new window)



      I compiled it to make sure there weren't any mistakes. (The "Compile" command is under the "C" menu.) It was all good. But I didn't know what a DLL was, so I asked. "It's a Dynamic Link Library, son," he said, which cleared things right up. NOT! And then he went on: "It's a library of compiled routines that somebody else wrote so we don't have to. The routines get linked in with our code, dynamically, each time our program is run." I still didn't know what he was talking about, but I wasn't going to push it. I'm not sure kids under 12 should have to know about such things.  click to enlarge (opens in new window)
      "Now," he said, "we need some mid-level helper routines to actually turn those knobs by setting the servos." More talk, more typing (I'm a very good typer, by the way):

    "And finally," he said, "we need some high-level helper routines so we can tell the computer WHAT we want it to do instead of wrestling with HOW to do it. So we can solve the problem without thinking about knobs and servos at all." Again, he talked and I typed. There were more high-level routines than you can see in the picture below, but they were all the same except for the "lefts" and the "rights" and the "forwards" and "backwards". I'm sure you get the idea:
    click to enlarge (opens in new window)



        I asked my dad what the "waits" were for and he said that controlling things with computers is a lot like telling jokes: you have to have good timing. Then he showed me on the maze how we first have to use one knob to get the ball rolling down a path before we use the other knob to make it lean to one side or the other. That's what all those short waits are for. Then he showed how the ball would bounce a little when it hit the end of a path, and I understood what all those long waits were for.
    "Are we done?" I asked.  "No," he said. "But we're almost there. Give me the keyboard, take the frame off the platform, put a ball on the maze, and grab those knobs." I did. "Now," he said, "tell me what you're thinking -- not what you're DOING, but what you're THINKING -- as you solve the maze, step by step." "Tilt the board forward and right," I said, and he typed it in. "Tilt the board left and forward," I said, and he typed some more. "Tilt the board backward and right," I said, and... well, I'm sure you get the idea. When I was done we added a couple of lines at the top of the routine to get started right, and couple of lines in the middle and at the end, just for fun:
    click to enlarge (opens in new window)


    The moment of truth had arrived. We turned on the battery pack, put the frame on the platform, and ran the program (the "Run" command is under the "R" menu). This is what appeared on the screen (and what we heard the computer say) as the program solved the maze:
    click to enlarge (opens in new window)




        It was AWESOME! We called Mom to see it and she thought it was AWESOME, too. But then she wanted to know why we used the PC-Control stuff instead of Lego Mindstorms. I could see that my dad was about start numbering things as he spoke, so I went to the kitchen and put some Bagel Bites into the microwave. I could hear him in the background...
        "First, this is better than Mindstorms because we can code and run on the same machine. No cross-compiling, no downloads, etc. And because we're working with a PC -- desktop or laptop or tablet -- we don't have to wrestle with a dippy little Lego "brick" or a teensy 8-bit processor. We get lots of speed, gigabyes of memory, unlimited storage, a huge, full-color display, a built-in camera, a complete sound system including text-to-speech, and so forth, all for free (since we needed a computer to code on in any case)."My mom nodded.

    "Secondly, we can connect as many peripherals as we need: motors, sensors, switches, whatever. And we can control them all with a single program. And we can hook them up with inexpensive wires and standard connectors (USB, RJ14, etc)."  My mom nodded.

    "Finally, we can program in the same language that we all hear, and speak, and think in, all day, every day -- Plain English."  My mom had nodded off. But thanks to the Bagel Bites, I was still awake. And I was pretty sure I got the gist of it: bigger and better than Mindstorms. Sweet.

    Chuckles Rzeppa
    Lego Master, Programming Apprentice
    and PC-Control Padawan.






     

    EDITOR: Gerry Rzeppa is the author of a new programming language called "Plain English" and used it with the PC Control DLL function library to create this application. Gerry has indicated that he can be reached at the following e-mail address if you have any questions...

    gerry.rzeppa@pobox.com

     

    11144  













    PC Control Ltd:  All articles are publish as submitted in good faith but we do not accept any responsibility for the authenticity or content of these articles. Any article breaching copyright will be removed from this website as soon as we are made aware.

    Featured
    Items

     
    Just Text:
    New Software
    for the MotorBee



    ConText
    Control by Text


    Security Camera:
    A new article
    by Brian M



    Microscope Control:
    A new article
    by Harald K. A.



     Use our boards with
    Raspberry Pi.


    Pi-Mobile:
    A new article
    by Ava L (UK)