robotics and C++ programming

Started by
20 comments, last by CProgrammer 20 years ago
Parallax.
EDIT: woops, already posted. I enjoyed working with some of their stuff.

[edited by - woodsman on April 12, 2004 4:46:06 PM]
If a plant cannot live according to its nature, it dies; so a man.
Advertisement
USB Stuff You might be intersted in this:

http://www.ftdichip.com/FTModule.htm

These things are a godsend for connecting USB robots, notice the one with built in PIC.
honayboyz: Clearly you''re fond of the BASIC stamp approach, but CProgrammer wants to drive it direct from the computer--that means nothing on the robot except the circuits to take the stuff coming from the computer and drive the motors. Don''t need the (somewhat costly) stamp.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Here we go, I knew I had some info on parport robot control.

The three printer ports are LPT1, LPT2 and LPT3. Their addresses are 3BCH, 378H, and 278H, respectively.

The pin config is as follows:
Pin #       Function1           Strobe2-9         Data bits 0-710          Acknowledge11          Busy12          PE (Out of paper)13          Printer on line14          Auto linefeed after carriage return15          Printer Error16          Initialize Printer17          Select/Deselect Printer18-25       Unused/Grounded   

Remember this was designed for a printer. If you have the actual plug set up so the bigger side is up, then the pins are like this:
13                                              1 (strobe)*   *   *   *   *   *   *   *   *   *   *   *   *  *   *   *   *   *   *   *   *   *   *   *   *  25                                          14   


This is a DB-25 connector, which is pretty common and hobby electronics stores will often carry stuff for working with them. The parport spits out 8 bits at a time and data bit 7 (pin 9) is the most significant; data bit 0 (pin 2) is the least significant. The strobe line toggles from HIGH to LOW during printing and back to HIGH again. You don't have to use it, but it can be useful to synchronize data and such.

You'll want 3 74367 ICs to work with this. These are TTL chips and need a +5V source; I'm sure there are CMOS versions.

Now, controlling something. I'm going to write this in BASIC, mostly because the book I'm using as I write this uses BASIC and I have no idea how to do this in any other language anyway. To interact with the port, we're going to use the BASIC OUT command. The form of the command is:
OUT port number ,value
It basically sets the value on the port's data lines. Suppose we hook a motor to data line 0 (that's pin 2 on the connector). We want to make pin 2 HIGH. First thing we do is reset the port:
OUT 888, 0
888 is the LPT we're using, and 0 sets all bits to LOW. Next, we'll set data line 0 to HIGH by sending binary 00000001:
OUT 888, 1
I'm assuming you know this whole binary to decimal thing--you are, after all, not new to coding. If you had 2 motors connected to lines 0 and 1, and you wanted to turn both on, you'd use:
OUT 888, 3
Since 3 is the result of 1 OR 2 (1 | 2 in C).

Realistically, the port is not going to be able to drive that motor. You'll need to set up something like this:
-----|   | <----transistor (MOSFET recommended)|   |-----| | || | || | |1 2 3  


Connect pin 2 to the actual parport. Connect pins 1 and 3 to the motor and +V (which way depends on NPN or PNP transistor). It's basically a standard power transistor setup, no surprises here.

That will allow you to drive your robot, at least basically. I'm going to do a bit of research on how to do this in a more modern language, probably C. It's undoubtedly possible, I just don't know how.

[EDIT] Oops, teh table fuxxor.

[edited by - Promit on April 12, 2004 5:39:29 PM]
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
For other various information:
The PC's Parallel Port

Important things I've found out so far:
NT will not allow direct port access. You need a kernel mode driver.
It looks like the C function outp is the same as BASIC's OUT. It's called _outp in VC++ but may be aliased, I haven't tested it.

This DLL embeds a kernel mode driver for NT systems in it, and is compatible with all Windows systems, from 95 to XP. It also has tutorials on working with the parport.

This MS article explains how to interface VB.NET with the parallel port, if you're into the NET languages.

[edited by - Promit on April 12, 2004 5:49:08 PM]
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
To elaborate a little on what I said (and what Promit is saying), you''re right, interfacing is sort of tricky now. In the real mode days you could just write to the memory address that represented your parallel port (eg 0x378), and the values you wrote would appear on the ports pins as voltages ( ~0V for a logical low and ~5V for a logical high, relative to one of the ground pins). There were even ASM opcodes meant especially for this: IN and OUT. However, those days are long gone, because XP does not allow direct memory access for programs that don''t run in kernal mode. I''m actually kind of surprised that the code promit posted works (are you using a pre Win98 PC, promit?) To do a similar thing in C++, the easiest way is to download the dll/lib I linked to. The dll contains a kernal mode device driver embedded in it, which is allowed direct access to the parallel port. Just include the static lib in your project, and copy in the function declarations from the sample code. Then you can call them as you would IN and OUT.


quote:Original post by CProgrammer
A SDK that comes with the necessary hardware. Basically come controller that is plugged into the serial or parallel port and communicates with my programm through an SDK.



You don''t need one; you can do both input and output yourself over a parallel or serial port. I''m sure they exist however, and if you want to get out of some soldering/learning of circuits it might be a big timesaver to have one. Unfortunately, I don''t know much about them so I can''t help you there
-david
The BASIC code I posted was merely an example of what would be going on in the port, and how to control it. That code will not work under any NT based system unless your BASIC implementation actual provides a kernel mode driver. I don't know if this is generally the case; I haven't tested that code in years myself, and it was merely an example pulled from an old robotics book I have.

The DLL linked by Muse and again by me (oops ) provides newer versions of the outp and inp functions that use a kernel mode driver in that DLL. In other words, it works in NT based systems.

Muse is right in pointing out the voltages on those lines. I should have put them in myself, just forgot. I also found some general info indicating that you can expect a maximum current supply of about 1 mA per data line from a parport. You'll need significantly more to drive a motor which has any load on it.

Now it's simply a question of physically building it. There's a diagram here of how to interface the 74367 chips with the parport, but I'm not about to try to draw it in ASCII. Lucky for you, however, I have a scanner. (Somebody remind me to get Tazmanland access...I can't guarantee this image will exist forever.)


You know, writing all this makes me a little depressed. I was interested in robotics in 7th grade--five years ago. But it was difficult to get parts and EE/CE/robotics books are useless at any but the college level. That was when I decided to code instead. Cheaper, easier, more resources, and less trips to radio shack. Maybe I should try again...my major will be CE next year, after all...

[edited by - Promit on April 12, 2004 8:10:09 PM]
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
If you don''t want ANY logic on the robot itself you can only control 8 servos in 1 direction (on or off). For this use the parallel port. To do anything more advanced I don''t see any other way then to use microcontroller(s) or stamp(s) and program that(those) to control the individual motors/servos. It doesn''t need to be advanced, just addressing. Depending on the number of IO ports (n) on the uC you can control (n-2)/2 servos. Serial input needs 2 in ports and each motor needs 2 out ports.
Or you could use premade motor controller kits, but they use microcontrollers as well, so my point is still valid
quote:Original post by frostburn
If you don''t want ANY logic on the robot itself you can only control 8 servos in 1 direction (on or off).


Sure you can. You simply have to use a smarter method, and you''ll need some control electronics on the board. There''ll be logic on the thing; it just won''t be someething as serious as a microcontroller or a BASIC stamp. Some relatively simple logic circuits, a couple ICs, and you''ve got 256 different messages you can send to the robot. Admittedly it''s not as simple, and you''re going to start adding more and more on-board circuitry, but you don''t need a stamp.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Promit, frostburn, Muse:
My deepest thanks to you all. I think I really got the necessary overview to get me going now.
A special thanks to Promit for the in depth description on using the parallel port (very creative). This method definetely seems like a good option I could work with.
I definetely want a laptop as the brain. For the computational capabilities, the memory and the hard drive space. And last but not least the screen which, if neately integrated into the design should function as a ''face''. Plus the OS of the laptop will give many more benefits.
I suppose if the limits of the parallel port should become a problem one could also think of using a microcontroller as something like a router. Have the microcontroller constantly connected to the laptop and then still have the laptop function as brain. What do you guys think of this design?
Oh and Promit, I know what you mean on coding being practical. I''m giving robotics a go now, you should to
With your enthusiasm you''ll definetly get something cool going.

Robots are great.
-CProgrammer

This topic is closed to new replies.

Advertisement