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
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- | [reply] |
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
| [reply] |
|
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.
| [reply] |
|
Thanks, I never thought there would be module for Lego Robots!
| [reply] |
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!
| [reply] |
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.
| [reply] |
|
| [reply] |
|
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.
| [reply] |
|
|