A simple controller
This page is targetted at the SDP course. The SDP hardware is relatively simple and cannot provide the physical quantities (metres, newtons etc.) that are the normal basis of DevBot's API. Using the SDP hardware, therefore, involves bypassing the hardware-abstraction layer and calling device-specific functions directly.Contents
Device configuration
The following configuration file (simple_controller.config) creates named devices for a standard set of SDP hardware.
[aboard] Driver=sdp_aboard [pboard] Driver=sdp_pboard [motor0] Driver=sdp_motors Index=0 [motor1] Driver=sdp_motors Index=1 [motor2] Driver=sdp_motors Index=2 [motor3] Driver=sdp_motors Index=3
This configuration sets up the two IO boards and four motors the system supports. The motors implement the standard BotServoMotorInterface.
Accessing a non-standard sensor
A non-standard sensor, a sensor that does not generally return physical quantities, is a sensor that is not part of the DevBot interface system. These sensors can be accessed via their individual access methods which are defined in the sensor's header file in the driver/ directory.Utilising this "internal" function of the driver requires that you link the program against it. This can be achieved by adding a reference to .so file to the DRIVER_OBJS variable in the Makefile shown in Automating the build with GNU make e.g.
... # Drivers DRIVER_OBJS=$(CCROOT)/lib/devbot/sdp_aboard.so ...
Bringing it all together
Here's a simple example program (simple_controller.c) utilising the SDP sensors
/* The main libbot header */ #include <devbot/core/bot.h> /* Header for accessing BotServoMotor devices */ #include <devbot/servomotor.h> /* Header for accessing the active sensor board */ #include <devbot/driver/sdp_aboard.h> int main(int argc, char** argv) { int value = 0, index = 0; /* Initialize the library */ bot_initialize_from_file("simple_controller.config"); /* Grab one of the motors and set it spinning */ BotDevice *motor0 = bot_get_device("motor0"); bot_servomotor_set_velocity(motor0, 2); /* Now we'll use an aboard-specific call to retrieve sensor values*/ BotDevice *aboard = bot_get_device("aboard"); for (index = 0; index < 7; index++) { value = sdp_aboard_get_sensor(aboard, index); g_message("Sensor %d reading: %d", index, value); } /* Shutdown the library */ bot_shutdown(); return 0; }
(c) 2006 Edinburgh Robotics Ltd.
Generated on Fri Feb 2 11:24:07 2007 for libbot by doxygen 1.5.1