Events and functions

C, C++, and Visual C++

Events and functions

Postby Xap » Wed Apr 27, 2011 11:22 am


I'm newbie on programming so I don't know where is the problem. I need to use an stepper and an 8/8/8 to one project.

I have this code:

Code: Select all

int ID, state;
CPhidgetStepperHandle stepper;
CPhidgetAdvancedServoHandle servo;
CPhidgetInterfaceKitHandle interfacekit;

//Stepper variables//////
int result;
const char *err;
double minAccel, maxVel, maxCurr;
int stopped;

int stepper_create(int ID)
   __int64 curr_pos;
   //Declare an stepper handle
   CPhidgetStepperHandle stepper = 0;

   //Create the stepper object

   //Open the device for connections (Set serialNo --> -1 if doesn't work)
   CPhidget_open((CPhidgetHandle)stepper, ID);

   //Get the program to wait for an stepper device to be attached
   printf("Waiting for Phidget to be attached....");
   if((result = CPhidget_waitForAttachment((CPhidgetHandle)stepper, 10000)))
      CPhidget_getErrorDescription(result, &err);
      printf("Problem waiting for attachment: %s\n", err);

   //Read event data

   //This example assumes stepper motor is attached to index 0

   //Set up some initial acceleration, velocity and current values
   CPhidgetStepper_getAccelerationMin(stepper, 0, &minAccel);
   CPhidgetStepper_setAcceleration(stepper, 0, minAccel);

   CPhidgetStepper_getVelocityMax(stepper, 0, &maxVel);
   CPhidgetStepper_setVelocityLimit(stepper, 0, maxVel/3);

   CPhidgetStepper_getCurrentLimit(stepper, 0, &maxCurr);
   CPhidgetStepper_setCurrentLimit(stepper, 0, 1.25);

   //Display current motor position if available
   if(CPhidgetStepper_getCurrentPosition(stepper, 0, &curr_pos) == EPHIDGET_OK)
      printf("Motor: 0 > Current Position: %lld\n\n", curr_pos);

   //CPhidgetStepper_setCurrentPosition(stepper, 0, 0);
   CPhidgetStepper_setTargetPosition(stepper, 0, 0);

   stopped = PFALSE;
      CPhidgetStepper_getStopped(stepper, 0, &stopped);

   return 0;

//Step 0: Position 0 - also engage stepper
int stepper_step0()

   CPhidgetStepper_setTargetPosition(stepper, 0, 1000);
   CPhidgetStepper_setEngaged(stepper, 0, 1);
   stopped = PFALSE;
      CPhidgetStepper_getStopped(stepper, 0, &stopped);
   return 0;

int main(int argc, char *argv[])
//interfacekit_state(index, state);
return 0;

For now, I'm running it without the interfacekit events. The point is that the motor doesn't rotate to 1000, but the program goes in stepper_step0() function (I've tried to put in a printf).

Sorry for my english and thank you very much in advance.

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 1 guest