Rose-Hulman Robotics Team

Changeset 508

Show
Ignore:
Timestamp:
06/03/09 18:09:23 (3 years ago)
Author:
spenceal
Message:

* Starting Gui tab for auto
* Adding fake_ccam' and classifier' to rbconfig

Location:
trunk/software/rb
Files:
1 added
8 modified

Legend:

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

    r490 r508  
    2424from rb.core.logging import log_debug, log_info, log_warn, log_error, log_die 
    2525from rb.utils import points_to_vec, rad_delta 
     26from rb.vision import Camera 
    2627 
    2728from time import sleep 
     
    6768 
    6869        def navigate_course(self): 
    69                 # TODO: import these from the C enum 
    70                 RB_GRASS       = 0 
    71                 RB_OBSTICLE    = 1 
    72                 RB_LINE        = 2 
    73                 RB_IGNORE      = 3 
    7470                values = [0.1, 0.1, 0.1, 0.1] 
    7571 
     
    7975                                values[point[2]] += 1 
    8076 
    81                 if (values[RB_GRASS] < 10): 
     77                if (values[Camera.GRASS] < 10): 
    8278                        print "Auto.navigate_course: Not enough data, aborting"  
    8379                        return False; 
     
    8581                # If it's `mostly' clear 
    8682                print "Auto.navigate_course: values = ", values  
    87                 if (values[RB_GRASS]/values[RB_OBSTICLE]) > 2: 
     83                if (values[Camera.GRASS]/values[Camera.OBSTICLE]) > 2: 
    8884                        # go forward 
    8985                        print "Auto.navigate_course: Moving forward"  
  • trunk/software/rb/controller.py

    r503 r508  
    4343                self.data_queue = Queue() 
    4444                self.init_drive() 
    45                 #self.init_camera() 
     45                self.init_camera() 
    4646                #self.init_gps() 
    4747                #self.init_microstrain() 
    4848 
    49                 self.transcript = TranscriptLogger('/tmp/rblog.txt', 
    50                                                         self.drive, self.gps, self.microstrain) 
     49                #self.transcript = TranscriptLogger('/tmp/rblog.txt', 
     50                #                                       self.drive, self.gps, self.microstrain) 
    5151 
    5252                self.set_navigator('laptop') 
  • trunk/software/rb/gui/gui.glade

    r485 r508  
    11<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
    22<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> 
    3 <!--Generated with glade3 3.4.5 on Wed May  6 22:08:34 2009 --> 
     3<!--Generated with glade3 3.4.5 on Wed Jun  3 20:52:53 2009 --> 
    44<glade-interface> 
    55  <widget class="GtkWindow" id="window"> 
     
    277277            </child> 
    278278            <child> 
    279               <widget class="GtkLabel" id="auto_body"> 
    280                 <property name="visible">True</property> 
    281                 <property name="label" translatable="yes">TODO</property> 
     279              <widget class="GtkAlignment" id="auto_body"> 
     280                <property name="visible">True</property> 
     281                <child> 
     282                  <placeholder/> 
     283                </child> 
    282284              </widget> 
    283285              <packing> 
    284286                <property name="position">4</property> 
    285                 <property name="tab_expand">True</property> 
    286287              </packing> 
    287288            </child> 
  • trunk/software/rb/gui/gui.py

    r482 r508  
    3030from rb.gui.speedgraph import SpeedGraph 
    3131from rb.gui.camera     import Camera 
     32from rb.gui.auto       import Auto 
    3233 
    3334 
     
    7980                self.raw_orient_dir = self.compass.new_direction(RAW_ORIENT_BLUE, pi / 2) 
    8081                self.speed_graph = SpeedGraph(self.controller.drive) 
     82                self.auto = Auto() 
    8183                self.camera = Camera() 
    8284                self.builder.get_object("speed_body").add(self.speed) 
    8385                self.builder.get_object("compass_body").add(self.compass) 
    8486                self.builder.get_object("speed_graph").add(self.speed_graph) 
     87                self.builder.get_object("auto_body").add(self.auto) 
    8588                self.builder.get_object("camera_body").add(self.camera) 
    8689                 
     
    108111                elif type == 'vision_points': 
    109112                        points, pixbuf = data 
     113                        self.auto.points = points 
    110114                        self.camera.pixbuf = pixbuf 
    111115                        self.camera.queue_draw() 
  • trunk/software/rb/gui/gui.xml

    r485 r508  
    11<?xml version="1.0"?> 
    2 <!--Generated with glade3 3.4.5 on Wed May  6 22:08:34 2009 --> 
     2<!--Generated with glade3 3.4.5 on Wed Jun  3 20:52:53 2009 --> 
    33<interface> 
    44  <object class="GtkAdjustment" id="adjustment1"> 
     
    288288            </child> 
    289289            <child> 
    290               <object class="GtkLabel" id="auto_body"> 
    291                 <property name="visible">True</property> 
    292                 <property name="label" translatable="yes">TODO</property> 
    293               </object> 
    294               <packing> 
    295                 <property name="position">4</property> 
    296                 <property name="tab_expand">True</property> 
    297               </packing> 
     290              <object class="GtkAlignment" id="auto_body"> 
     291                <property name="visible">True</property> 
     292                <child> 
     293                  <placeholder/> 
     294                </child> 
     295              </object> 
    298296            </child> 
    299297            <child type="tab"> 
  • trunk/software/rb/vision/__init__.py

    r490 r508  
    11from thread import start_new_thread 
    22 
     3import rbconfig 
    34from rb.vision import _vision 
    45from time import sleep 
    56 
    67class 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 
    724        def __init__(self, controller): 
    825                self.running = True 
    926                self.controller = controller 
    10                 _vision._init_classifier() 
    11                 #_vision._init_capture() 
     27                _vision._init(rbconfig.fake_ccam, rbconfig.classifier) 
    1228                start_new_thread(self._main, ()) 
    1329 
     
    3046        win = gtk.Window() 
    3147        image = gtk.Image() 
    32         _vision._init_classifier() 
     48        _vision._init(TRUE, Camera.DTREE) 
    3349        points, pixbuf = _vision._get_points() 
    3450        image.set_from_pixbuf(pixbuf) 
  • trunk/software/rb/vision/_vision.c

    r498 r508  
    6565}  
    6666 
     67static PyObject* 
     68_init(PyObject *self, PyObject *args) 
     69{ 
     70        int fake_ccam, classifier_num; 
     71        if (!PyArg_ParseTuple(args, "bb", &fake_ccam, &classifier_num)) 
     72                return NULL; 
    6773 
    68 /* TODO: define some constants for the types of points */ 
    69 static PyObject* 
    70 _init_classifier(PyObject *self, PyObject *args) 
    71 { 
     74        /* Init ccam */ 
     75        if (!fake_ccam) { 
     76                printf("Initializing capture\n"); 
     77                cam = cvCreateCameraCapture(0); 
     78                if (cam == NULL) 
     79                        return PyErr_SetFromErrno(PyExc_IOError); 
     80        } 
     81 
     82        /* Init classifier */ 
    7283        printf("Initialzing classifier\n"); 
    73         classifier = classifier_new(RB_DTREE); 
     84        classifier = classifier_new(classifier_num); 
    7485        classifier_add_data_from_files(classifier, 
    7586                        "rb/vision/data/classes/input.jpeg", 
     
    7788        classifier_train(classifier); 
    7889        return Py_None; 
    79 } 
    80  
    81 static PyObject* 
    82 _init_capture(PyObject *self, PyObject *args) 
    83 { 
    84   if (!PyArg_ParseTuple(args, "")) { 
    85     return NULL; 
    86   } 
    87   printf("Initializing capture\n"); 
    88   cam = cvCreateCameraCapture(0); 
    89   if (cam == NULL) { 
    90     return PyErr_SetFromErrno(PyExc_IOError); 
    91   } 
    92   return Py_None; 
    93 } 
    94  
    95 IplImage *capture() 
    96 { 
    97   cvGrabFrame(cam); 
    98   return cvRetrieveFrame(cam); 
    9990} 
    10091 
     
    121112        CvSeq    *seq; 
    122113         
    123         // Release the global interpreter lock.  No messing with Python objects without it, though! 
    124         // This creates a new block, so we need to declare variables above to access them after we 
    125         // reacquire the GIL. 
     114        // Release the global interpreter lock.  No messing with Python objects 
     115        // without it, though!  This creates a new block, so we need to declare 
     116        // variables above to access them after we reacquire the GIL. 
    126117        Py_BEGIN_ALLOW_THREADS 
    127118 
    128         //input       = capture(); 
    129         input       = get_image("rb/vision/data/classes/input.jpeg"); 
     119        input       = get_image(cam); 
    130120        transformed = transform_image(input, 0.25); 
    131121        classes     = classifier_predict(classifier, transformed); 
     
    150140 
    151141        cvReleaseMemStorage(&seq->storage); 
    152         //cvReleaseImage(&input); // Don't free captured images 
     142        cvReleaseImage(&input); // Don't free captured images 
    153143        cvReleaseImage(&transformed); 
    154144        cvReleaseMat(&classes); 
     
    163153        {"_get_points", _get_points, METH_VARARGS, 
    164154         "Return a list of points corresponding to obstacles and lines"}, 
    165         {"_init_classifier", _init_classifier, METH_VARARGS, 
    166          "Initialize the classifier using predefined training images"}, 
    167         {"_init_capture", _init_capture, METH_VARARGS, 
    168          "Initialize the camera capture device"}, 
     155        {"_init", _init, METH_VARARGS, 
     156         "Initialize the classifier and camera capture device"}, 
    169157        {NULL, NULL, 0, NULL} // sentinel 
    170158}; 
  • trunk/software/rb/vision/vision.c

    r490 r508  
    2929#include "classify.h" 
    3030 
    31 IplImage *get_image() 
    32 { 
    33         const char *file = "rb/vision/data/classes/input.jpeg"; 
    34         IplImage *image = cvLoadImage(file, 1); 
    35         if (!image) { 
    36                 printf("Could not load image file: %s\n", file); 
    37                 return NULL; 
    38         } 
    39         return image; 
     31 
     32IplImage *get_image(CvCapture *cam) 
     33{ 
     34        if (cam) { 
     35                cvGrabFrame(cam); 
     36                return cvRetrieveFrame(cam); 
     37        } else { 
     38                const char *file = "rb/vision/data/classes/input.jpeg"; 
     39                IplImage *image = cvLoadImage(file, 1); 
     40                if (!image) { 
     41                        printf("Could not load image file: %s\n", file); 
     42                        return NULL; 
     43                } 
     44                return image; 
     45        } 
    4046} 
    4147