creating_devices_programmatically.c
This example is discussed in Creating devices programmatically
00001 /******************************************************************************* 00002 * Creating devices programmatically 00003 * 00004 * This example program illustrates how to use devbot without a device 00005 * configuration file. 00006 * 00007 *******************************************************************************/ 00008 00009 /* Include the main bot.h and speech interface definition as before */ 00010 #include <devbot/bot.h> 00011 #include <devbot/distance.h> 00012 00013 /* This time however we'll need to manipulate driver objects too */ 00014 #include <devbot/driver.h> 00015 00016 int main(int argc, char **argv) 00017 { 00018 /* 1. Initialize the devbot library */ 00019 bot_initialize(); 00020 00021 /* 2. Create a driver object 00022 * 00023 * This has the side effect of dynamically loading, initializing and 00024 * registering the driver */ 00025 BotDriver *driver = bot_get_driver("example"); 00026 00027 /* 3. Check that this process was successful 00028 * 00029 * Again, this is not necessary, but is good practice. */ 00030 if (!driver) 00031 { 00032 exit(1); 00033 } 00034 00035 /* 4. Now we'll create a distance measuring device using this driver */ 00036 BotDevice *rangefinder = bot_device_new(driver, "rangefinder", NULL, NULL); 00037 00038 /* 5. Check it was created successfully */ 00039 if (!(rangefinder && bot_device_get_interface(rangefinder, BotDistanceInterface))) 00040 { 00041 exit(1); 00042 } 00043 00044 /* 6. Retrieve and print the current distance */ 00045 g_message("Distance was: %lf", bot_distance_get_metre(rangefinder)); 00046 00047 /* 7. Since we're finished with it, we'll dispose of it */ 00048 bot_device_free(rangefinder); 00049 00050 /* 8. Shutdown the libarary */ 00051 bot_shutdown(); 00052 }
(c) 2006 Edinburgh Robotics Ltd.
Generated on Fri Feb 2 11:24:04 2007 for libbot by doxygen 1.5.1