Exemplo n.º 1
0
static PyObject *
Scan_update(Scan *self, PyObject *args, PyObject *kwds)
{
    PyObject * py_lidar = NULL;
    double hole_width_mm = 0;
    PyObject * py_velocities = NULL;

    static char* argnames[] = {"scans_mm", "hole_width_mm", "velocities", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds,"Od|O", argnames,
        &py_lidar, 
        &hole_width_mm,
        &py_velocities))
    {
        return null_on_raise_argument_exception("Scan", "update");
    }
    
    // Bozo filter on LIDAR argument
    if (!PyList_Check(py_lidar))
    {
        return null_on_raise_argument_exception_with_details("Scan", "update", 
            "lidar must be a list");
    }
    
    // Bozo filter on LIDAR argument list size
    if (PyList_Size(py_lidar) != self->laser.scan_size)
    {
        return null_on_raise_argument_exception_with_details("Scan", "update", 
            "lidar size mismatch");
    }
    
    // Default to no velocities
    double dxy_mm = 0;
    double dtheta_degrees = 0;
          
    // Bozo filter on velocities tuple
    if (py_velocities)
    {
        if (!PyTuple_Check(py_velocities))
        {
           return null_on_raise_argument_exception_with_details("Scan", "update", 
                "velocities must be a tuple");    
        }
        
        if (!double_from_tuple(py_velocities, 0, &dxy_mm) ||
            !double_from_tuple(py_velocities, 1, &dtheta_degrees))
            {
                return null_on_raise_argument_exception_with_details("Scan", "update", 
                    "velocities tuple must contain at least two numbers");    
               
            }
    }
    

    // Extract LIDAR values from argument
    int k = 0;
    for (k=0; k<self->laser.scan_size; ++k)
    {
        self->lidar_mm[k] = PyFloat_AsDouble(PyList_GetItem(py_lidar, k));
    }
    
    // Update the scan
    scan_update(
        &self->scan, 
        self->lidar_mm, 
        self->laser,
        hole_width_mm,
        dxy_mm,
        dtheta_degrees);
               
    Py_RETURN_NONE;
}
Exemplo n.º 2
0
int main(int argc, char** argv)
{
  if (argc != 3)
  {
    std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n";
    exit(-1);
  }
  char * mysqld_sock  = argv[1];
  const char *connectstring = argv[2];
  ndb_init();
  MYSQL mysql;

  /**************************************************************
   * Connect to mysql server and create table                   *
   **************************************************************/
  {
    if ( !mysql_init(&mysql) ) {
      std::cout << "mysql_init failed\n";
      exit(-1);
    }
    if ( !mysql_real_connect(&mysql, "localhost", "root", "", "",
			     0, mysqld_sock, 0) )
      MYSQLERROR(mysql);

    mysql_query(&mysql, "CREATE DATABASE ndb_examples");
    if (mysql_query(&mysql, "USE ndb_examples") != 0) MYSQLERROR(mysql);

    create_table(mysql);
  }

  /**************************************************************
   * Connect to ndb cluster                                     *
   **************************************************************/

  Ndb_cluster_connection cluster_connection(connectstring);
  if (cluster_connection.connect(4, 5, 1))
  {
    std::cout << "Unable to connect to cluster within 30 secs." << std::endl;
    exit(-1);
  }
  // Optionally connect and wait for the storage nodes (ndbd's)
  if (cluster_connection.wait_until_ready(30,0) < 0)
  {
    std::cout << "Cluster was not ready within 30 secs.\n";
    exit(-1);
  }

  Ndb myNdb(&cluster_connection,"ndb_examples");
  if (myNdb.init(1024) == -1) {      // Set max 1024  parallel transactions
    APIERROR(myNdb.getNdbError());
    exit(-1);
  }

  /*******************************************
   * Check table definition                  *
   *******************************************/
  int column_color;
  {
    const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
    const NdbDictionary::Table *t= myDict->getTable("api_scan");
    if(t == NULL) 
    {
      std::cout << "Dictionary::getTable() failed.";
      exit(-1);
    }
    Car car;
    if (t->getColumn("COLOR")->getLength() != sizeof(car.color) ||
	t->getColumn("BRAND")->getLength() != sizeof(car.brand))
    {
      std::cout << "Wrong table definition" << std::endl;
      exit(-1);
    }
    column_color= t->getColumn("COLOR")->getColumnNo();
  }

  if(populate(&myNdb) > 0)
    std::cout << "populate: Success!" << std::endl;
  
  if(scan_print(&myNdb) > 0)
    std::cout << "scan_print: Success!" << std::endl  << std::endl;
  
  std::cout << "Going to delete all pink cars!" << std::endl;
  
  {
    /**
     * Note! color needs to be of exact the same size as column defined
     */
    Car tmp;
    sprintf(tmp.color, "Pink");
    if(scan_delete(&myNdb, column_color, tmp.color) > 0)
      std::cout << "scan_delete: Success!" << std::endl  << std::endl;
  }

  if(scan_print(&myNdb) > 0)
    std::cout << "scan_print: Success!" << std::endl  << std::endl;
  
  {
    /**
     * Note! color1 & 2 need to be of exact the same size as column defined
     */
    Car tmp1, tmp2;
    sprintf(tmp1.color, "Blue");
    sprintf(tmp2.color, "Black");
    std::cout << "Going to update all " << tmp1.color 
	      << " cars to " << tmp2.color << " cars!" << std::endl;
    if(scan_update(&myNdb, column_color, tmp1.color, tmp2.color) > 0) 
      std::cout << "scan_update: Success!" << std::endl  << std::endl;
  }
  if(scan_print(&myNdb) > 0)
    std::cout << "scan_print: Success!" << std::endl  << std::endl;

  /**
   * Drop table
   */
  drop_table(mysql);

  return 0;
}