Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Hardware Programming and Perl

by Willman023 (Scribe)
on Oct 28, 2002 at 15:48 UTC ( [id://208527]=perlquestion: print w/replies, xml ) Need Help??

Willman023 has asked for the wisdom of the Perl Monks concerning the following question:

I'm Computer Engineering student interested in programming firmware/hardware using Perl. My first language being C++, where I could write an application for a PC, or code on firmware. I've since learned Perl and really like it! I have seen programs for AI written in Perl, and I read somewhere that Perl takes up alot of resources and needs significant processing power compared to BASIC/ASSEMBLY/C. I'll be taking a class next term where we will program a lego robot in C to maneuver a maze, would this be possible/efficient to do in Perl? Thanks

Replies are listed 'Best First'.
Re: Hardware Programming and Perl
by robartes (Priest) on Oct 28, 2002 at 15:59 UTC
    Well, that depends on what you're doing. Perl is an interpreted language (albeit one that is compiled before execution, for speed of execution), so if you're thinking of running Perl on some funny platform such as a Lego robot, you first need to get a Perl interpreter/compiler on it. That would make an interesting project :).

    If, on the other hand, you are progamming your robot by writing programs for a specific robot-controlling API on a PC somewhere that is connected to hardware that translates the API calls to commands to the robot, you might be able to write a Perl wrapper around this API, enabling you to control the beast in Perl. Of course, you would then be obliged to build a life-sized camel in Lego and drive it using Perl :).

    CU
    Robartes-

Re: Hardware Programming and Perl
by fglock (Vicar) on Oct 28, 2002 at 16:28 UTC

    would this be possible/efficient to do in Perl?

    Sure. See LEGO-RCX module.

    everything from controlling the motors, reading sensors, modifying program variables, and getting data form the DataLog

      I doubt they are using Mindstorms. Typically, Universities use a kit of sensors and motors (with a C API) that just "happen" to connect nicely to Legos.
      Thanks, I never thought there would be module for Lego Robots!
Re: Hardware Programming and Perl
by hiseldl (Priest) on Oct 28, 2002 at 16:24 UTC

    Another approach you could use is to create a 'C' code generator that parses a file with a list of actions and generates the 'C' code necessary to perform those actions. 'Advanced Perl Programming' By Sriram Srinivasan, has a chapter about this and if you go to the examples section, you can download the code for 'jeeves' which is the code generator that he wrote about.

    You may be able to use Inline::C to run these routines too.

    --
    hiseldl
    What time is it? It's Camel Time!

Re: Hardware Programming and Perl
by dbp (Pilgrim) on Oct 28, 2002 at 18:10 UTC

    Check out Inline::C. You can use it to write a Perl module that wraps the C API for your robot. As long as you can get Perl and Perl modules installed on the machine your program will execute on, you should be golden. My former roomate took a similar class while we were in University and all the processing was done offboard on a laptop. They were doing a lot of vision work, which, for some reason, is really easy to do in Matlab. They had no problem using Matlab's C interface to control the robot.

    As to your question about resources: Perl typically uses more memory and runs slower than an equivalent C program, but this only typically matters if you are doing a lot of iteration or dealing with a massive amount of data. I've done a fair amount of AI-related development in Perl and have found the reduced development time was more than a fair trade-off for the slight speed deficit. That said, I'd be careful doing hard-core search in Perl. I ran into a lot of trouble doing heurisitic search in a program that played stratego. To milk any sort of performance in these problems you'll need to know a lot about subroutine calls, recursion, and parameter passing in Perl. I ended up forking off a C process to do the search, but I would have wrapped the code using Inline::C if I'd known how to do so at the time.

    Check out XS Info for more information about calling C from Perl. The original question referenced XS, but there is a good deal of Inline::C info in the node as well.

      Your probably right about the lego sensors and all, I don't think they use mindstorms. But alot of good suggestions, Inline::C is probably the way to go if I really want to develop in perl. If all the processing is done off board that really answers the gist of my question. I think when I take this class I'm gonna first do it in C, and then in perl to compare the speed difference. It should be interesting to program hardware in perl!
      Thanks dbp for all of your input!

      Where there's a Willman, there's a way!

        I'd be interested in the comparison, as I bet many fellow monks might. Also, if you get a working module put together, it might be a nice addition to CPAN, especially if the robotics kit your school uses is a common one.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://208527]
Approved by Tanalis
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-23 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found