Update of /cvsroot/libphidget/libphidget/src/examples
In directory usw-pr-cvs1:/tmp/cvs-serv9737
Modified Files:
servo_example.cc
Log Message:
Added second example
Index: servo_example.cc
===================================================================
RCS file: /cvsroot/libphidget/libphidget/src/examples/servo_example.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** servo_example.cc 12 Sep 2002 02:06:44 -0000 1.2
--- servo_example.cc 12 Sep 2002 03:02:22 -0000 1.3
***************
*** 1,4 ****
--- 1,5 ----
#include <CPhidgetManager.h>
#include <CServo.h>
+ #include <CServoController.h>
#include <unistd.h>
***************
*** 13,16 ****
--- 14,18 ----
void cleanup()
{
+ printf("cleanup\n");
CPhidgetManager::release();
}
***************
*** 39,50 ****
void example1()
{
! // Request servo #0 from the servo controller we previously found
! CServo servo(CUID(servoPhidgetID.serial(),0));
! // Center it
! servo.position(.5);
! // Wait for it to move
! sleep(1);
cleanup();
--- 41,87 ----
void example1()
{
! printf("example 1 - Easy way to control a servo\n");
! // We have this brace to make sure all the stack objects get destroyed before we call cleanup,
! // cleanup will throw an exception when it is called and objects are still out in the "world"
! {
! printf(" Request servo #0 from the servo controller\n");
! CServo servo(CUID(servoPhidgetID.serial(),0));
! printf(" Center it.\n");
! servo.position(.5);
!
! printf(" Wait for it to move before we destroy the servo object (and thus by default disable the servo).\n");
! sleep(1);
! }
!
! cleanup();
! }
!
! /**
! * The easiest way to use a servo controller
! */
! void example2()
! {
! printf("example 2 - Easy way to use a servo controller\n");
!
! // We have this brace to make sure all the stack objects get destroyed before we call cleanup,
! // cleanup will throw an exception when it is called and objects are still out in the "world"
! {
! printf(" Request servo controller\n");
! CServoController servoController(servoPhidgetID);
!
! printf(" Name:%s\n",servoController.name());
! printf(" Servo Count:%d\n",servoController.servoCount());
!
! printf(" Randoming moving all servos.\n");
! for (int t=0;t<servoController.servoCount();t++)
! {
! servoController.servo(t,true)->position((rand()%1000)/1000.0);
! }
!
! printf(" Wait for them to move.\n");
! sleep(1);
! }
cleanup();
***************
*** 71,74 ****
--- 108,112 ----
example1();
+ example2();
}
catch(const exception &e)
|