Society of Robots - Robot Forum

Software => Software => Topic started by: airman00 on November 06, 2008, 04:42:05 PM

Title: Linux for a Butler Robot
Post by: airman00 on November 06, 2008, 04:42:05 PM
I'm trying to do a shift from Chives running WinVista to running Linux.
I'm looking for any documentation or tutorial on programming in Linux. I plan to use the CMU Sphinx code for Speech Recognition. How about the other parts of the code , like controlling the motors through a serial port, etc.
Any links you'd recommend on getting started in programming in Linux ? Any language would be fine ( except assembly and hex , :P )

Thanks
Title: Re: Linux for a Butler Robot
Post by: Half Shell on November 06, 2008, 05:46:12 PM
I spent the summer working with/modifying Debian Linux for the embedded ARM procesor (just Debian, not the GUIed kind). The benefit of that was I had excellent package support on top of Linux's open hardware. I recommend that because Debian is an increasingly popular distribution, making package support immeasurably valuable.

I learned via trial by fire (I seem to do that a lot). Few references were useful to me, but reading through the files in /etc/ and reading general articles on how Linux works helps a bit.

Serial port control is ridiculously easy, as Linux views hardware as files. This means merely using python or C to open up /dev/ttyS0 (the typical COM1 on Linux) is trivial.

Also, most of the modifications, if any, on Linux that you do would be done in C. As for actually WRITING and executing your code, Python is by far the best. Serial ports are dealt with by PySerial, making all serial communication TRIVIAL at best. It will GREATLY speed up your development.

Finally, the joy of Linux also means SSH capabilities - the ability to modify, run, debug, and monitor your code from anywhere in the world!

If you name specific actions you want to do, I think it might be best to request specifically what you want to do so I can be more specific.
Title: Re: Linux for a Butler Robot
Post by: householdutensils on November 06, 2008, 08:31:57 PM
Linux is awesomesauce, I don't know about accessing serial ports, but accessing parallel ports via their memory address is super easy.

Code: [Select]

#include <stdio.h>



 /*This include will allow you to do port i/o operations. For libc5 you will need to include the asm/io.h file for the port i/o functions and the unistd.h file for the i/o permissions*/
#include <sys/io.h>


/*this defines the paraport variable as the memory address of the parallel port, you can find out this address using the dmesg command, there will be a line somewhere in the output with the base and range of each ports memory addresses. */
#DEFINE paraport 0x0378

int main()
{

/*This opens the port for use by the application. If you don't do this, you're application won't have permissions to access the port, and you're likely to get a seg fault. The first arg is the port base, the second num is the number of bytes you want to be allowed to work with, and the last number is 1 or 0 for on or off. You don't need to worry about the ports address range, it will all be sorted out from the base you provide*/
ioperm(paraport, 1, 1);

/*Here we output a full byte to the port, which turns all the data pins to high*/
outb(255, paraport);

sleep(5); /* 5 second sleep*/

outb(0, paraport); /*Turn the data pins to low*/

exit(1); /*Quit this mofo*/

}


Easy as pie. You can also read from the port with the inb(port) function.
Title: Re: Linux for a Butler Robot
Post by: airman00 on November 07, 2008, 06:49:16 AM
I think I'm going to use Python since thats what the CMU Sphinx Speech Engine uses.
Title: Re: Linux for a Butler Robot
Post by: Half Shell on November 07, 2008, 09:22:53 AM
In Python, Serial communication is even easier.


Load pySerial.

Then put

ser = ser = serial.Serial('/dev/ttyUSB0', baudrate=57600, bytesize=8, parity='N', stopbits=1, timeout=1)

That's it. Python handles the rest of the serial stuff (including timing and preventing sending too much info too quick) on its own. And much of that function isn't evne needed, it's just extra info from a program I just wrote the other day.
Title: Re: Linux for a Butler Robot
Post by: householdutensils on November 08, 2008, 07:22:04 AM
@airman00: I had a look at Chives on your website and it's probably the coolest thing I've ever seen (Would love to have a similar robot fetch be a cold one during the rugby!  ;D ) I was wondering if you could post your experience with CMU Sphinx once you've had a chance to play around with it as I've been looking at using Sphinx of PocketSphinx for speech recognition in my bot, but I'm not very clear on how all of it goes together. I've used SAPI 5.1 and C# for some home automation experiments, but the bot I'm building has a Mini-ITX board with a cf card acting as an HDD so I'm limited on space and I can't really afford a windows os.

Title: Re: Linux for a Butler Robot
Post by: Ro-Bot-X on November 08, 2008, 07:34:37 AM
For a Linux robotic project take a look at OAP (http://oap.sourceforge.net/). Also the book Linux Robotics (http://www.amazon.com/Linux-Robotics-Tab-Jay-Newman/dp/007144484X/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1226151189&sr=8-1) is worth reading, although the code is in Java, which I think is good since is platform independant, so you can use the same program in Windows or any flavour of Linux. I am also considering Linux as a robot OS, but since I have almost no experience with it, I can't decide which distro should I use. I have a 1GB CF card for this, so a full distro might not be possible. I will eighter buy a 8GB or 16GB CF card or a laptop HDD to house a dual boot XP and whatever Linux I'll end up with. I have tryed Gentoo, but it will not install on my hardware, also Ubuntu and Xubuntu. The problem is the VIA EPIA motherboard I guess, probably drivers have to be downloaded but I don't know how. For the moment I am going to use a 40GB regular HDD to see what I can do with it and how much power it uses. I can give you the link for the Java code from the Linux Robotics book if you want to take a look at it.
Title: Re: Linux for a Butler Robot
Post by: airman00 on November 08, 2008, 07:47:15 AM
the OAP looks awesome! Was it programmed in python or java?

Also , I don't really know where to start with learning to control robots in Linux. Any advice or links or anything? I'm very noobish in Linux and can barely do anything in it. I have the Ubuntu distro.
 
Quote
I learned via trial by fire (I seem to do that a lot). Few references were useful to me, but reading through the files in /etc/ and reading general articles on how Linux works helps a bit.
Also halfshell how long did it take you to learn python to the level that you can control a robot(like the iRobot create for example)?

RobotX, is there a Linux Robotics book that uses Python instead of Java?
Title: Re: Linux for a Butler Robot
Post by: householdutensils on November 08, 2008, 08:19:19 AM
For a Linux robotic project take a look at OAP (http://oap.sourceforge.net/). Also the book Linux Robotics (http://www.amazon.com/Linux-Robotics-Tab-Jay-Newman/dp/007144484X/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1226151189&sr=8-1) is worth reading, although the code is in Java, which I think is good since is platform independant, so you can use the same program in Windows or any flavour of Linux. I am also considering Linux as a robot OS, but since I have almost no experience with it, I can't decide which distro should I use. I have a 1GB CF card for this, so a full distro might not be possible. I will eighter buy a 8GB or 16GB CF card or a laptop HDD to house a dual boot XP and whatever Linux I'll end up with. I have tryed Gentoo, but it will not install on my hardware, also Ubuntu and Xubuntu. The problem is the VIA EPIA motherboard I guess, probably drivers have to be downloaded but I don't know how. For the moment I am going to use a 40GB regular HDD to see what I can do with it and how much power it uses. I can give you the link for the Java code from the Linux Robotics book if you want to take a look at it.

JVM ftw!!!!

Have you looked at puppy linux or Damn Small Linux? I tried both, DSL has issues with detecting certain storage devices and puppy has some issues with wireless cards, but both are <100mb (DSL has a strict <50mb policy), and both can be installed on a USB drive. Both also come with perl and C compilers (gcc or tcc) and Java. I installed Puppy on a CF card (Via a USB card reader and then booting offa CF-IDE adapter) with the included live install app.

The best thing about puppy is that it gets loaded into RAM during boot so that it's super fast. All your session info and files that are saved within the puppy file system get stored inside an image with an emulated ext2 file system. You can also store stuff on the media directly. Puppy also managed to detect a sata and 3 seperate IDE drives that I tired off the bat, even offering shortcuts to the mounted drives from the desktop.

I've settled on Xubuntu installed on a 4gb CF card, simply because of awesome device detection, and APT <3 but as that failed on your install, I suggest Puppy Linux as an alternative.

As your jamming some *nix, here's a few bash commands that might prove useful (You might already know them, but they were useful to me and took me a few googles to find so if you don't know them, they'll save you the trouble):

ifconfig - display network interfaces
dmesg - display a crap load of system information, including memory addresses of ports
df - check storage usage
top - check running processes, displays process id as well (PID) so that you can use the command 'kill PID' to force quit a process.

also, remember to check the man page for anything you're trying to get working. Some distros don't include the bash man db, if not, just google 'man object' and within the first couple of results will be a copy of the man page. (Where object means a program, script, or command  you wanna find info on)
Title: Re: Linux for a Butler Robot
Post by: Half Shell on November 08, 2008, 10:53:00 AM
How long it takes to know enough Python to control a robot? If you are using a serial port for your hardware, it takes about 5 minutes of practicing if you've ever programmed in your life before to get serial port hardware control finished and fine tuned in Python.

How long it takes to know enough Linux/C in order to modify your operating system for your robot? Depends...


As for what distro for a robot - I recommend Debian flavored distros simply because of package management. IF size is a problem, however, puppy and damn small linux are both excellent choices that can be loaded into practically any amount of memory.