• Advertisement

Archived

This topic is now archived and is closed to further replies.

robotics and C++ programming

This topic is 5061 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well basically I want to get into making a robot using a laptop as brain. I will be writing the Programm in C++. Now i''ll need some usb devices or the like to connect the robot to Servos, LED''s etc. Anybody have a good place to get started on the subject. Or even better a Starter Kit I can order that holds all the necessary components. Thanks in Advance. -CProgrammer

Share this post


Link to post
Share on other sites
Advertisement
Lego makes some very nice kits. I''ve worked with two of their products, the RCX mini controller and Handy Board w/ expansion. I really dont know much about their availability or price because they''re custom versions that were issued to us for a student robotics competition. Anyways, they both connect through the serial port of your computer. The handyboard connects directly, but the RCX uses an IR port (which connects to your serial port). Their native language is InteractiveC, which is very much like regular C with only a few twists, and even includes a library very much like the C standard library. Not quite C++ like you had asked, but similar enough to keep you happy I think.

All of this can probably be researched further at Lego''s website.

Share this post


Link to post
Share on other sites
Actually I already have a Mindstorm set.
I''m planning to build a real robot. I already have someone who will do the engeneering part. We have a workshop with the necessary tools to build the thing. Basically what I need now is the gadgets, such as SERVOS, LEDS etc. and the hardware and software to connect it to my laptop, which will make the laptop function as brain. I dont want to use microcontrollers.
-CProgrammer

Share this post


Link to post
Share on other sites
I imagine the main problem will be designing the interface between the compy and the robo. Serial and parallel ports were popular for this back in the day...if those still exist. They''re well documented and there''s a lot of resources on writing custom drivers and such. THe only thing is that you''ll need a decent comp/electrical engineer to get stuff going so the robot responds correctly to the comp''s commands. The ports won''t be able to drive the systems directly, but some bounceless switches, a couple motor controllers, some power transistors (MOSFETs maybe), and you should be in business.

Share this post


Link to post
Share on other sites
I''ve driven a stepper motor off my parallel port, using a freeware driver (I think you can find it here). I also recommend jameco electronics for basic supplies; good selection and I believe good service too (though since I haven''t had any order problems it''s hard to say).

Good luck on your project.

Share this post


Link to post
Share on other sites
Glad to see somebody else is intrested in robotics here. I use an old Nokia as a brain, and its sends messages to a cell phone decoder on my pc.



Sharp Basic - Coming summer 2004!
Sign Up For Sharp Basic Beta Testing!!!

[edited by - DerAngeD on April 11, 2004 11:18:09 PM]

Share this post


Link to post
Share on other sites
For like 160 bucks or something you can get 8 servos and a controller. Buy 2 remote control cars (used maybe) that have a pwm speed controller, basicaly a remote control that you can push the stick forward and go half speed, but that is of decent quality), Take the 2 motors the controllers, make a frame with a caster either in front and back in the center or 2 in the back on each corner. Hook the 2 motor controllers up to 2 of the servo controller ports, buy a basic stamp (Get the most expensive one so u have lots of inputs later). Buy 2 2 way rf transceivers from the same site. Hook the 2nd one up to a serial cord. Bust out some quickbasic or maybe there is a way to resource the serial port in c++. I know for the parallel port you need a special ocx in VB. Write your base code to set up variables and build serial packets, then start making communication code to talk to the basic stamp. Then start programming the basic stamp to set up a few variables addressed by the transceiver to control servo reutines for the motors. Then you have 6 servos to make arms and probably 32 or so i/o lines which can be expanded by using a demultiplexer? Hope that helps.


edit: my bad this is the part that always pissed me off when i was trying to experiment, where? Jameco Is great for all kinda of electronics and some robotics specificaly, they buy all their parts from Robot Store. For metals, bearings, gears, motors, springs, Grainger that may not be spelled correctly. Parallax makes the basic stamps and transceivers (basic stamp 2 at least for later expansion, sip-solid antena transceivers). Good luck, keep us posted.

edit 2: fixed links.
[edited by - honayboyz on April 11, 2004 11:59:45 PM]

[edited by - honayboyz on April 11, 2004 12:00:59 AM]

[edited by - honayboyz on April 11, 2004 12:04:34 AM]

Share this post


Link to post
Share on other sites
Check out this site: FerretTronics

They have a bunch of stuff based on using serial communications.

If you want to go wireless I think you can google for the keywords: saw transceiver

Share this post


Link to post
Share on other sites
Wow thanks for all the replies guys.
DerAnged: Thats a neat idea. So basically you have a wireless connection to the computer through the nokia. If you got any details on this technic I''d be very interested.

Jameco looks good I''ll have a look at that.

I definetly agree that connecting the robot to the computer will be the major problem. I really didnt want to get into programming my own drivers. I just like the experience in that field. However any sites on the subject may change that.

I imagined there to be something like the following. if there is please tell me:
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.
I could then connect the SERVOS etc to the controller in its various ports(pins).
I know something like this wouldnt be too cheap, but im willing to invest a bit.
Any ideas here.

FerretTronics looks interesting in regards to this. I''ll have a look at that and all the other sites shortly.

Thanks again
-CProgrammer

Share this post


Link to post
Share on other sites



Motors and wheels.
Servo Controller
Speed controller.(x2, there are 2 on ebay, same type)
Basic Stamp

There are no robotic all in one kits except something like this, which is very expensive (Clickity).


A book I suggest you read and warship is Build your own Universal Computer Interface -Bruce Chubbs

[edited by - honayboyz on April 12, 2004 9:27:11 AM]

Share this post


Link to post
Share on other sites
Parallax.
EDIT: woops, already posted. I enjoyed working with some of their stuff.

[edited by - woodsman on April 12, 2004 4:46:06 PM]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 # Function
1 Strobe
2-9 Data bits 0-7
10 Acknowledge
11 Busy
12 PE (Out of paper)
13 Printer on line
14 Auto linefeed after carriage return
15 Printer Error
16 Initialize Printer
17 Select/Deselect Printer
18-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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
quote:
Original post by Promit
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.


Duh

Obviously it would be possible to get more than 8 channels if you used a lot of AND, OR, NOT, XOR gates, but I''d go with the uC in that case, or maybe a combination. But then AND, OR, NOT, XOR ports are by definition logic. It''s also possible to avoid using ICs, but you need a lot of transistors..

Share this post


Link to post
Share on other sites
I''m pretty sure there are some chips which have a 4-bit input and will make one of their 16 output pins HIGH depending on what''s coming in at the inputs. I don''t know the specific chip, though.

Share this post


Link to post
Share on other sites

  • Advertisement