Showing posts with label netduino. Show all posts
Showing posts with label netduino. Show all posts

Monday, 28 November 2011

Using the parallel port

Initially the plan for the tank was a NetDuino, but as we are not experts with microcontrollers, it seems like simply sending commands to the NetDuino via USB is not a common use. The USB is more suitable to load programs, not communication. It can definitely be done, but does not seem simple.


The new plan

This made us turn to more basic methods and I discovered the parallel port!
We found an old laptop in the garage that has 1x USB port and 1x parallel port.
So instead of using a small lightweight NetDuino, we plan on using a full blown computer!

The setup will (hopefully) include a Sinatra/Rails webapp running which will control the parallel port, and therefore control the motors for movement, firing, etc.
This webapp should be mobile browser friendly and with the help of a PCMCIA wifi card that has the ability to be put into master mode, the tank should broadcast its own wifi network so there is no reliance on being close to a router (for field tests).
The web interface should also provide a video stream from the webcam(s) so hypothetically you could control it without line of sight.

I did a simple test to see how easy using the parallel port from Ruby was and documented it over at my blog here:
http://blog.stevenocchipinti.com/2011/10/ruby-parallel-port-leds.html

It worked well, and because we intend on using Ruby on the server side it should be quite easy to setup control via a web page :)


Using /dev/port

The method I documented takes advantage of the /dev/port special file.
This provides a map of every IO port on the system and requires privileged access.
The address of the parallel port is pretty standard and google will generally suffice, but you can discover the address of this port by searching through /proc/ioport.

As mentioned in my blog post, there are 8 data pins, and using /dev/port makes turning these pins on and off really easy.
All you have to do is open the file for writing, seek to the address of the parallel port and write 1 byte (8 bits) where each bit corresponds to a pin. If you want to change the state of the port, you simply seek back and overwrite it again.

Here is my example script.

This method requires root access by default and can be dangerous if other parts of the file are tampered with, so linux provides another way of access the IO ports.


Using /dev/parport0

This method uses the Linux IOCTL mechanism.
I'm no expert with this stuff, but I have a much better understanding of how this works now than when I was just using /dev/port.
This method is similar, but there is a permissions system in place that requires the process that wants access to the parallel port to request it from the OS first.

First you need to open /dev/parport0 as a file for writing as usual, then you need issue an IOCTL to claim that port. Once you can claimed it for use, you can then issue other IOCTL commands for reading and writing and once your done, you need to issue an IOCTL to release it back to the OS again.

This is a bit more complicated that the last method, but it seems like the proper way to do it. IOCTL is a very Linux / C thing, but luckily the Ruby IO library contains a basic implementation.

Here is my example script.

As you can probably see, the IOCTL commands are just constants which I needed to look up to find. I found another Ruby example which is much more complete here.

Sunday, 22 May 2011

ThinkTank - Part I

Yesterday Rob and I had our first brainstorming session for The Tank.

After getting some inspiration from the Internet we started planning out the features for our first iteration, which basically included:
  • Proper (dual drive) tank tracks
  • Pan & Tilt turret
  • Pneumatic cannon
  • 2 web cams (turret and tank)
  • Wifi control

First point of discussion was the tank tracks.. which I had no idea how we were going to do that, then Rob found this instructable:
http://www.instructables.com/id/How-to-make-custom-and-strong-tank-tracks-for-very/

Which looks tough!
The only thing is we cant actually drive the chain with those bolts in the way (they use a roller blade wheel). What we really need is about 3 chains joined side-by-side. That way we could have the half-pipes (used as track from the tutorial) connected to the 2 outer chains, leaving the middle chain free to be connected to the driving gear.

The hard part is getting the 3 chains attached to each other, which Rob thinks we can actually disassemble the chain and replace each individual axle with a longer one, with spacers between the chain, forming quite a thick track... except its a massive job!
We would need to drill out each axle, replace it with a bigger one, then bash the ends to keep it riveted in working order.

We then found that we can get full working push bikes from the tip, with good chains on them for $5 each (but then we have to pay to bring them back to the tip). So thats the first thing we will have to try.

We briefly discussed how the cannon will work and a mechanism idea for rotating the turret, then how the Netduino will fit in the picture.

Ended up getting Anthony over as our Netduino consultant, and discussed how we can get motor speed control by using "Pulse Width Modulation" with the digital outputs of the Netduino and a BJT (transistor). Also got his help to set up a development environment on my machine, so I can play around :)

Pretty good first day of planning, with a few jokes thrown in (such as running the tank with a motorbike engine and flame-throwers.. which wont be happening, lol)