Friday, February 26, 2010

Using Python and Pygame to Display A Motion JPEG From the TRENDnet Wireless Internet Camera

1:  import time  
2:  import httplib  
3:  import base64  
4:  import StringIO  
5:  import pygame  
6:  from pygame.locals import *  
7:    
8:  class trendnet:  
9:    
10:      def __init__(self, ip, username='admin', password='admin'):  
11:    
12:          self.ip = ip  
13:          self.username = username  
14:          self.password = password  
15:          self.base64string = base64.encodestring('%s:%s' % (username, password))[:-1]  
16:    
17:      def connect(self):  
18:    
19:          h = httplib.HTTP(self.ip)  
20:          h.putrequest('GET','/cgi/mjpg/mjpeg.cgi')  
21:          h.putheader('Authorization', 'Basic %s' % self.base64string)  
22:          h.endheaders()  
23:          errcode, errmsg, headers = h.getreply()  
24:          self.file = h.getfile()  
25:    
26:      def update(self, window, size, offset):          
27:            
28:          data = self.file.readline()  
29:          if data[0:15] == 'Content-Length:':  
30:              count = int(data[16:])  
31:              s = self.file.read(count)      
32:              while s[0] != chr(0xff):  
33:                  s = s[1:]       
34:                    
35:              p = StringIO.StringIO(s)  
36:                
37:              try:  
38:                  campanel = pygame.image.load(p).convert()  
39:                  campanel = pygame.transform.scale(campanel, size)  
40:                  window.blit(campanel, offset)  
41:            
42:              except Exception, x:  
43:                  print x  
44:                    
45:              p.close()  
46:                
47:  if __name__ == '__main__':  
48:    
49:    pygame.init()  
50:    screen = pygame.display.set_mode((660,500), 0, 32)  
51:      
52:    pygame.display.set_caption('trendnet.py')  
53:      
54:    background = pygame.Surface((660,500))  
55:    background.fill(pygame.Color('#E8E8E8'))  
56:    screen.blit(background, (0,0))  
57:      
58:    camera = trendnet('192.168.1.103', 'admin', 'admin')  
59:    camera.connect()  
60:      
61:    while True:  
62:      
63:      camera.update(screen, (640,480), (10,10))  
64:      pygame.display.update()  
65:      
66:      for event in pygame.event.get():  
67:        if event.type == QUIT:  
68:          sys.exit(0)  
69:            
70:      time.sleep(.01)  

download code

Sunday, February 21, 2010

Pairing Xbee Wireless Modules


Xbee wireless modules offer a quick, easy and inexpensive way to provide wireless end-point connectivity in your projects.

While they do offer “no configuration needed for out-of-the-box RF communications” you will want to do some configuration to allow high speed communications with automatic resending of lost packets.

The easiest way to set the parameters of an Xbee modules is with the use of Digi's X-CTU software utility. X-CTU is a windows-based application designed to interact with Digi's RF products providing a simple GUI for firmware configuration.

For paring a set of 2 Xbee Modules the parameters we are concerned about are PANID (ATID), Destination Address Low (ATDL), 16-bit Source Address (ATMY) and Interface Data Rate (ATBD).

The PANID (ATID) or Personal Area Network ID is a number shared amongst each Xbee module in a network. Many Xbee modules could exist in the same area but only those that share a PANID can talk to each other. The default PANID is 3332 and should be avoided

The Destination Address Low (ATDL) sets the destination address of the Xbee module and the Source Address (ATMY) sets the address number of the Xbee module. For a pair of Xbee modules these should be set opposite of each other to enable automatic resending of lost packets.

The Data Rate (ATBD) or baud rate is the number of bits per second the Xbee module will send. Xbee modules must have matching baud rates for them to talk to each other. The default is 9600bps.

At the moment SA's Xbee modules are set to:

Xbee #1 – Computer Side
ATID = 4321
ATDL = 11
ATMY = 10
ATBD = 3 (9600bps)

Xbee #2 – Robot Side
ATID = 4321
ATDL = 10
ATMY = 11
ATBD = 3 (9600bps)

So far this configuration has been working well. I do plan to experiment with a higher baud rate soon as 9600bps is a bit slow. But for now all seems well.

Friday, February 19, 2010

Kodak Zi8 Pocket Video Camera

I have been in the market for a decent camcorder for a while now. All my previous video work has been through the built in iSight web cam built into my MacBook. Obviously that was not an idea setup. Poor quality vido, poor audio and awkward positioning being the main issues.

I wanted something that was small sized and portable, did not require a lot of gear, decent indoor video quality, and in the 200 dollar price range. The three cameras that fit these requirements included the Flip MinoHD, Creative Vado HD and the Kodak Zi8

Hands down the Kodak Zi8 really stands above the rest. Features including:
- 1080p video with 16:9 aspect ratio
- SD card slot
- External microphone jack
- Image stabilization
- Removable battery

I have uploaded a short test video to YouTube of SA walking that I took with the Zi8.



I plan to use this camera to keep this blog updated with my progress on Second Amendment, offer some coverage of the events I attend, generate some how-to and project videos and document any projects Team Upgrayd works on in the future.

Monday, February 15, 2010

Attending the CIRC Bot Brawl

On March 6th the Central Illinois Robotics Club will be hosting a robotics competition event.

Competitions at the event will include various sumo divisions, autonomous line flowing, autonomous maze completion, combat robots (1lb and 3lb divisions), best in show, and a few short Mech Warfare demonstrations.

I plan on attending and bringing along Second Amendment my quad mech to participate in the Mech Warfare demos. Also I will probably enter SA into the best in show competition. The focus of my best in show entry will be around inverse kinematics and walking gait sequences.

Date - March 6, 2010
Location - Lakeview Museum, Peoria, IL
CIRC Homepage
Bot Brawl 2010 Information

Improved Quad Walking Gait Sequence

Second Amendment's gait was functional and that is about it. It was clunky, mechanical looking and inefficient.

SA's gait was very simplistic. Basically alternating diagonal sets of legs would be raised and moved. While this works it is sloppy and prone to wondering (unable to walk in straight lines). Also, due to program structure, SA was unable to both walk and turn at the same time. These things had to be improved!

Enter the ripple gait. SA is now programed with an eight step ripple gait (leg up and forward, leg down, move body forward 6x). In addition it is now possible for him to turn while walking opening a great amount of possible body translations.

Monday, February 8, 2010

SA Shaping Up

Second Amendment is really coming together.



Just a quick rundown of everything that has happened from the last update:
Revised leg configuration
Test gun mount idea
Test ammo hopper
majority of mechanical components painted
optimized walk sequences
and more!