Rose-Hulman Robotics Team

Changeset 510

Show
Ignore:
Timestamp:
06/03/09 18:31:27 (3 years ago)
Author:
mosttw
Message:

Work on vision code

Location:
trunk/software
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/software/rb/auto.py

    r508 r510  
    2020import time 
    2121from math import pi 
    22 from collections import defaultdict 
    2322 
    2423from rb.core.logging import log_debug, log_info, log_warn, log_error, log_die 
    2524from rb.utils import points_to_vec, rad_delta 
    26 from rb.vision import Camera 
     25from rb.vision import GRASS, OBSTACLE 
    2726 
    2827from time import sleep 
     
    6867 
    6968        def navigate_course(self): 
    70                 values = [0.1, 0.1, 0.1, 0.1] 
     69                counts = [0.1, 0.1, 0.1, 0.1] 
    7170 
    7271                # count points `in front' of us 
    73                 for point in self.points: 
    74                         if (-10 < point[0] and point[0] < 10 and point[0] < 10): 
    75                                 values[point[2]] += 1 
     72                for x, y, type in self.points: 
     73                        if -10 < x < 10: 
     74                                counts[type] += 1 
    7675 
    77                 if (values[Camera.GRASS] < 10): 
    78                         print "Auto.navigate_course: Not enough data, aborting"  
    79                         return False; 
     76                if counts[GRASS] < 10: 
     77                        print "Auto.navigate_course: Not enough clear area; aborting"  
     78                        self.controller.drive.setspeed(0, 0) 
    8079 
    8180                # If it's `mostly' clear 
    8281                print "Auto.navigate_course: values = ", values  
    83                 if (values[Camera.GRASS]/values[Camera.OBSTICLE]) > 2: 
     82                if (counts[GRASS]/counts[OBSTACLE]) > 2: 
    8483                        # go forward 
    8584                        print "Auto.navigate_course: Moving forward"  
    8685                        self.controller.drive.setspeed(0.5, 0.5) 
    8786                else: 
    88                         print "Auto.navigate_course: Obsticle detected"  
     87                        print "Auto.navigate_course: Obstacle detected" 
     88                        self.controller.drive.setspeed(0, 0) 
    8989                        # TODO: 
    9090                        # count points on left/right 
     
    9595                Update the output based on `current_data`. 
    9696                ''' 
     97                # This is old code --- very old 
    9798                SPEED = .75 
    9899                if self.accel is not None: 
  • trunk/software/rb/vision/__init__.py

    r508 r510  
    55from time import sleep 
    66 
     7# TODO: import these from the C enum 
     8GRASS    = 0 
     9OBSTACLE = 1 
     10LINE     = 2 
     11IGNORE   = 3 
     12 
     13DTREE    = 0 
     14HARD     = 1 
     15 
     16COLORS = { 
     17    GRASS    : [0,   255, 0  ], 
     18    OBSTACLE : [255, 0,   0  ], 
     19    LINE     : [255, 255, 255], 
     20    IGNORE   : [0,   0,   255], 
     21} 
     22 
    723class Camera(object): 
    8         # TODO: import these from the C enum 
    9         GRASS    = 0 
    10         OBSTICLE = 1 
    11         LINE     = 2 
    12         IGNORE   = 3 
    13  
    14         DTREE    = 0 
    15         HARD     = 1 
    16          
    17         COLORS = { 
    18                 GRASS    : [0,   255, 0  ], 
    19                 OBSTICLE : [255, 0,   0  ], 
    20                 LINE     : [255, 255, 255], 
    21                 IGNORE   : [0,   0,   255], 
    22         } 
    23  
    2424        def __init__(self, controller): 
    2525                self.running = True 
     
    4646        win = gtk.Window() 
    4747        image = gtk.Image() 
    48         _vision._init(TRUE, Camera.DTREE) 
     48        _vision._init(True, DTREE) 
    4949        points, pixbuf = _vision._get_points() 
    5050        image.set_from_pixbuf(pixbuf) 
  • trunk/software/rb/vision/classify.h

    r484 r510  
    66enum { 
    77        RB_GRASS, 
    8         RB_OBSTICLE, 
     8        RB_OBSTACLE, 
    99        RB_LINE, 
    1010        RB_IGNORE  , 
  • trunk/software/rb/vision/classify_hard.c

    r479 r510  
    3030        /* Mark outputs */ 
    3131        CvMat *output = cvCreateMat(size.height, size.width, CV_8U); 
    32         cvSet(output, cvRealScalar(RB_OBSTICLE), NULL); 
     32        cvSet(output, cvRealScalar(RB_OBSTACLE), NULL); 
    3333        cvSet(output, cvRealScalar(RB_GRASS),    grass_mask); 
    3434        cvSet(output, cvRealScalar(RB_LINE ),    line_mask); 
  • trunk/software/rbconfig.py

    r509 r510  
    33''' 
    44 
    5 from rb.vision import Camera 
     5from rb.vision import DTREE, HARD  
    66 
    77name = 'RATT' # Human-readable robot name 
     
    2323# This is just the path to the CGI script, without the querystring parameters 
    2424fake_ccam = True 
    25 classifier = Camera.HARD 
     25classifier = HARD 
    2626ccam_url = "http://192.168.0.226/admin-bin/ccam.cgi" 
    2727