Exemplo n.º 1
0
int main(int argc, char* argv[]) {

    int result, numOutputs = 3, state = 0; 
    const char *err, *ptr;
    CPhidgetInterfaceKitHandle phid = 0;

    LocalErrorCatcher(CPhidgetInterfaceKit_create(&phid));
    
    LocalErrorCatcher(CPhidget_set_OnAttach_Handler((CPhidgetHandle) phid, AttachHandler, NULL));
    LocalErrorCatcher(CPhidget_set_OnDetach_Handler((CPhidgetHandle) phid, DetachHandler, NULL));
    LocalErrorCatcher(CPhidget_set_OnError_Handler((CPhidgetHandle) phid, ErrorHandler, NULL));

//    printf("Phidget Simple Playground (plug and unplug devices)\n");
//    printf("Opening...\n");
    LocalErrorCatcher(CPhidget_open((CPhidgetHandle) phid, -1));
    LocalErrorCatcher(CPhidget_waitForAttachment((CPhidgetHandle) phid, 100000));

    CPhidget_getDeviceType((CPhidgetHandle)phid, &ptr);
    CPhidgetInterfaceKit_getOutputCount(phid, &numOutputs);
//    printf("%s\n", ptr);

    printf("Turning power on\n");			    
    CPhidgetInterfaceKit_setOutputState(phid, 0, 1);
	
	printf("done\n");
    LocalErrorCatcher(CPhidget_close((CPhidgetHandle) phid));
    LocalErrorCatcher(CPhidget_delete((CPhidgetHandle) phid));

    return 0;
}
CPhidgetInterfaceKitHandle InitializeTempSensors(int n_tempsensors, int* sensor_channels, int rate_tempsensors) {
	int result;
	const char *err;

	/* If ifKit is already defined, return. */
	if (ifKit != NULL) {
		return ifKit;
	}

	/* Create the InterfaceKit object */
	CPhidgetInterfaceKit_create(&ifKit);

	/* Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error. */
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)ifKit, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)ifKit, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)ifKit, ErrorHandler, NULL);

	/* Open the interfacekit for device connections */
	CPhidget_open((CPhidgetHandle)ifKit, -1);

	LOG(logINFO) << "Waiting for interface kit to be attached...";
	if((result = CPhidget_waitForAttachment((CPhidgetHandle)ifKit, 5000))) {
		CPhidget_getErrorDescription(result, &err);
		LOG(logERROR) << "Problem waiting for attachment:" << err;
		return 0;
	}

	/* Set the data input rates of the interface kit potentiometers */
	for (int i = 0; i < n_tempsensors; i++) {
		CPhidgetInterfaceKit_setDataRate(ifKit, sensor_channels[i], rate_tempsensors);
	}

	return ifKit;
}
Exemplo n.º 3
0
int Create_Text_LCD()
	/*-----------------
		creation du handler pour le display du kit LCD
		------------------*/
{
	int err2;
	const char *errStr;

	CPhidgetTextLCD_create(&txt_lcd);

	CPhidget_set_OnAttach_Handler((CPhidgetHandle)txt_lcd,
			LCD_AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)txt_lcd,
			LCD_DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)txt_lcd,
			LCD_ErrorHandler, NULL);
	//open the TextLCD for device connections
	CPhidget_open((CPhidgetHandle)txt_lcd,lcd_display_number);

	//get the program to wait for an TextLCD device to be attached
	if((err2 = CPhidget_waitForAttachment((CPhidgetHandle)txt_lcd,
					10000)))
	{
		CPhidget_getErrorDescription(err2, &errStr);
		printf("Problem waiting for attachment Texte LCD: %s\n", errStr);
		return 0;
	}
	return 1;
}
Exemplo n.º 4
0
int Create_KIT1()
	/*-----------------
		creation du handler pour le kit interface 1
		------------------*/
{
	int err;
	const char *errStr;

	CPhidgetInterfaceKit_create(&IFK);
	CPhidgetInterfaceKit_set_OnInputChange_Handler(IFK, IFK_InputChangeHandler, 
			NULL);
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)IFK, IFK_AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)IFK, IFK_DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)IFK, IFK_ErrorHandler, NULL);
	CPhidgetInterfaceKit_set_OnSensorChange_Handler(IFK,IFK_SensorChangeHandler,
			NULL);
	//ouverture du kit interface
	CPhidget_open((CPhidgetHandle)IFK,kit_number);
	//wait 5 seconds for attachment
	if((err = CPhidget_waitForAttachment((CPhidgetHandle)IFK, 5000)) 
			!= EPHIDGET_OK)
	{
		CPhidget_getErrorDescription(err, &errStr);
		printf("Error waiting for attachment IFK1: (%d): %s\n",err,errStr);
		return 0;
	}
	//pour faire marcher les boutons stop et inhibit
	CPhidgetInterfaceKit_setOutputState(IFK,true_inhibit_number, 1);
	return 1;
}
Exemplo n.º 5
0
void Phidget::registerHandlers(void)
{
  CPhidget_set_OnAttach_Handler(handle_, AttachHandler, this);
  CPhidget_set_OnDetach_Handler(handle_, DetachHandler, this);
  CPhidget_set_OnError_Handler(handle_, ErrorHandler, this);
  cout << "Registered handles" << endl;
}
bool attach(
    CPhidgetPHSensorHandle &phid,
    int serial_number)
{
    int result;
    const char *err;

    //create the PH Sensor object
    CPhidgetPHSensor_create(&phid);

    //Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
    CPhidget_set_OnAttach_Handler((CPhidgetHandle)phid, AttachHandler, NULL);
    CPhidget_set_OnDetach_Handler((CPhidgetHandle)phid, DetachHandler, NULL);
    CPhidget_set_OnError_Handler((CPhidgetHandle)phid, ErrorHandler, NULL);

    //Registers a callback that will run if the PH changes by more than the PH trigger.
    //Requires the handle for the PHSensor, the function that will be called, and a arbitrary pointer that will be supplied to the callback function (may be NULL).
    CPhidgetPHSensor_set_OnPHChange_Handler(phid, PHChangeHandler, NULL);

    //open the PH Sensor for device connections
    CPhidget_open((CPhidgetHandle)phid, -1);

    //get the program to wait for an PH Sensor device to be attached
    ROS_INFO("Waiting for PH Sensor to be attached....");
    if ((result = CPhidget_waitForAttachment((CPhidgetHandle)phid, 10000))) {
        CPhidget_getErrorDescription(result, &err);
        ROS_INFO("Problem waiting for PH Sensor attachment: %s\n", err);
        return false;
    }
    else return true;
}
Exemplo n.º 7
0
int encoder_simple()
{
	int result;
	const char *err;
	file=fopen("/home/dune/dataSaved/essai1/encoder","w");
	//Declare an encoder handle
	CPhidgetEncoderHandle encoder = 0;

	//create the encoder object
	CPhidgetEncoder_create(&encoder);
	//Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)encoder, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)encoder, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)encoder, ErrorHandler, NULL);

	//Registers a callback that will run if an input changes.
	//Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetEncoder_set_OnInputChange_Handler(encoder, InputChangeHandler, NULL);

	//Registers a callback that will run if the encoder changes.
	//Requires the handle for the Encoder, the function that will be called, 
  //and an arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetEncoder_set_OnPositionChange_Handler (encoder, PositionChangeHandler, NULL);

	CPhidget_open((CPhidgetHandle)encoder, -1);

	struct timeval now ;

	//get the program to wait for an encoder device to be attached
	printf("Waiting for encoder to be attached....");
	if((result = CPhidget_waitForAttachment((CPhidgetHandle)encoder, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return 0;
	}
	gettimeofday(&now,NULL);
	encTime0 = now.tv_sec + ((double)now.tv_usec)/1000000.0;
	encTime1 = encTime0 ;

	//Display the properties of the attached encoder device
	display_properties(encoder);

	//read encoder event data
	printf("Reading.....\n");

	//keep displaying encoder data until user input is read
	printf("Press any key to end\n");
	getchar();

	//since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created
	printf("Closing...\n");
	CPhidget_close((CPhidgetHandle)encoder);
	CPhidget_delete((CPhidgetHandle)encoder);
	fclose(file);
	//all done, exit
	return 0;
}
Exemplo n.º 8
0
LoadCellData::LoadCellData(char *sDirectoryContainer, char *sDataHeader)
{
	loadCellConfigFile = fopen("C:\\config\\loadcell_calibration.txt","r");
	
	bInSingleTrial = false;
	bClosingFile = false;
    	strcpy_s(this->sDirectoryContainer, sDirectoryContainer);
	strcpy_s(this->sDataHeader, sDataHeader);
	fileOpenCounter = 0;
    	bIsRecording = false;

	if (loadCellConfigFile != NULL) {
		for (int i = 0; i < numChannels; i++) {
			fscanf(
				loadCellConfigFile, 
				"%lf %lf\n", 
				&loadCellIntercept[i],
				&loadCellSlope[i]
			);
		}
	}
	else {
		MessageBoxA(
			NULL, 
			"Could not find load cell config file in C:\\config",
			"", 
			MB_OK
		);
	}

	CPhidgetBridge_create(&bridge1);
	CPhidgetBridge_create(&bridge2);

	CPhidget_set_OnAttach_Handler((CPhidgetHandle)bridge1, AttachHandlerBridge, NULL);
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)bridge2, AttachHandlerBridge, NULL);

	CPhidget_open((CPhidgetHandle)bridge1, 293182);
	CPhidget_open((CPhidgetHandle)bridge2, 341581);

	hIOMutex = CreateMutex(NULL, FALSE, NULL);
	kill = 0;
	delayThread = 10;

	_beginthread(LoadCellData::staticLoadCellCallback, 0, this);
}
int tempsensor_simple()
{
	int result;
	const char *err;

	//Declare an temperature sensor handle
	CPhidgetTemperatureSensorHandle temp = 0;

	//create the temperature sensor object
	CPhidgetTemperatureSensor_create(&temp);

	//Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)temp, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)temp, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)temp, ErrorHandler, NULL);

	//Registers a callback that will run if the Temperature changes by more than the Temperature trigger.
	//Requires the handle for the Temperature Sensor, the function that will be called, and a arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetTemperatureSensor_set_OnTemperatureChange_Handler(temp, TemperatureChangeHandler, NULL);

	//open the temperature sensor for device connections
	CPhidget_open((CPhidgetHandle)temp, -1);

	//get the program to wait for an temperature sensor device to be attached
	printf("Waiting for TemperatureSensor to be attached....");
	if((result = CPhidget_waitForAttachment((CPhidgetHandle)temp, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return 0;
	}

	//Display the properties of the attached accelerometer device
	display_properties(temp);

	//read temperature sensor event data
	printf("Reading.....\n");

	//keep displaying temperature sensor event data until user input is read

	//modify the sensor sensitivity, index 1 is the thermocouple sensor, index 0 is the onboard or ambient sensor
	printf("Setting sensitivity of the thermocouple to 2.00. Press any key to continue\n");
	getchar();

	CPhidgetTemperatureSensor_setTemperatureChangeTrigger (temp, 1, 2.00);

	printf("Press any key to end\n");
	getchar();

	//since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created
	printf("Closing...\n");
	CPhidget_close((CPhidgetHandle)temp);
	CPhidget_delete((CPhidgetHandle)temp);

	//all done, exit
	return 0;
}
Exemplo n.º 10
0
int main(int argc, char* argv[]) {
  // Set up a SIGINT handler.
  signal(SIGINT, catch_sigint);

  // Create the InterfaceKit object.
  CPhidgetInterfaceKitHandle ifKit = 0;
  CPhidgetInterfaceKit_create(&ifKit);

  // Register device handlers.
  CPhidget_set_OnAttach_Handler((CPhidgetHandle)ifKit, attach_handler, NULL);
  CPhidget_set_OnDetach_Handler((CPhidgetHandle)ifKit, detach_handler, NULL);
  CPhidget_set_OnError_Handler((CPhidgetHandle)ifKit, error_handler, NULL);

  // Open the interfacekit for device connections.
  CPhidget_open((CPhidgetHandle)ifKit, -1);

  // Wait for a device attachment.
  fprintf(stderr, "waiting for interface kit to be attached....\n");
  int result;
  const char *err;
  if ((result = CPhidget_waitForAttachment((CPhidgetHandle)ifKit, 10000))) {
    CPhidget_getErrorDescription(result, &err);
    fprintf(stderr, "problem waiting for attachment: %s\n", err);
    return 0;
  }

  // Check some properties of the device.
  const char *device_type;
  int num_outputs;
  CPhidget_getDeviceType((CPhidgetHandle)ifKit, &device_type);

  CPhidgetInterfaceKit_getOutputCount(ifKit, &num_outputs);
  if ((strcmp(device_type, "PhidgetInterfaceKit") != 0)) {
    fprintf(stderr, "unexpected device type: %s\n", device_type);
    return 1;
  }
  if (num_outputs != 4) {
    fprintf(stderr, "unexpected number of device outputs: %d\n", num_outputs);
    return 1;
  }

  while (1) {
    double time = get_time_in_seconds();
    double factor = 1;
    int l0_state = fmod(time * factor, 20) < 10;
    int l1_state = fmod(time * factor, 20) >= 10;
    CPhidgetInterfaceKit_setOutputState(ifKit, 0, l0_state);
    CPhidgetInterfaceKit_setOutputState(ifKit, 2, l1_state);
    usleep(100000);
  }

  fprintf(stderr, "shutting down...\n");
  CPhidget_close((CPhidgetHandle)ifKit);
  CPhidget_delete((CPhidgetHandle)ifKit);

  return 0;
}
Exemplo n.º 11
0
int ph_simple()
{
	int result;
	const char *err;

	//Declare an PH Sensor handle
	CPhidgetPHSensorHandle ph = 0;

	//create the PH Sensor object
	CPhidgetPHSensor_create(&ph);

	//Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)ph, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)ph, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)ph, ErrorHandler, NULL);

	//Registers a callback that will run if the PH changes by more than the PH trigger.
	//Requires the handle for the PHSensor, the function that will be called, and a arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetPHSensor_set_OnPHChange_Handler(ph, PHChangeHandler, NULL);

	//open the PH Sensor for device connections
	CPhidget_open((CPhidgetHandle)ph, -1);

	//get the program to wait for an PH Sensor device to be attached
	printf("Waiting for PH Sensor to be attached....");
	if((result = CPhidget_waitForAttachment((CPhidgetHandle)ph, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return 0;
	}

	//Display the properties of the attached textlcd device
	display_properties(ph);

	//read led event data
	printf("Reading.....\n");

	//increase the sensitivity
	printf("Increasing sensitivity to 10.00, Press any key to continue\n");
	getchar();

	CPhidgetPHSensor_setPHChangeTrigger (ph, 10.00);

	//end
	printf("Press any key to end\n");
	getchar();

	//since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created
	printf("Closing...\n");
	CPhidget_close((CPhidgetHandle)ph);
	CPhidget_delete((CPhidgetHandle)ph);

	//all done, exit
	return 0;
}
Exemplo n.º 12
0
JNIEXPORT void JNICALL
Java_com_phidgets_Phidget_enableAttachEvents(JNIEnv *env, jobject obj,
  jboolean b)
{
	jlong gr = updateGlobalRef(env, obj, nativeAttachHandler_fid, b);
	CPhidgetHandle h = (CPhidgetHandle)(uintptr_t)(*env)->GetLongField(env,
	    obj, handle_fid);

	CPhidget_set_OnAttach_Handler(h, b ? attach_handler : 0,
	    (void *)(uintptr_t)gr);
}
Exemplo n.º 13
0
int spatial_simple()
{
    int result;
    const char *err;

    //Declare a spatial handle
    CPhidgetSpatialHandle spatial = 0;

    //create the spatial object
    CPhidgetSpatial_create(&spatial);

    //Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
    CPhidget_set_OnAttach_Handler((CPhidgetHandle)spatial, AttachHandler, NULL);
    CPhidget_set_OnDetach_Handler((CPhidgetHandle)spatial, DetachHandler, NULL);
    CPhidget_set_OnError_Handler((CPhidgetHandle)spatial, ErrorHandler, NULL);

    //Registers a callback that will run according to the set data rate that will return the spatial data changes
    //Requires the handle for the Spatial, the callback handler function that will be called,
    //and an arbitrary pointer that will be supplied to the callback function (may be NULL)
    CPhidgetSpatial_set_OnSpatialData_Handler(spatial, SpatialDataHandler, NULL);

    //open the spatial object for device connections
    CPhidget_open((CPhidgetHandle)spatial, -1);

    //get the program to wait for a spatial device to be attached
    printf("Waiting for spatial to be attached.... \n");
    if((result = CPhidget_waitForAttachment((CPhidgetHandle)spatial, 10000)))
    {
        CPhidget_getErrorDescription(result, &err);
        printf("Problem waiting for attachment: %s\n", err);
        return 0;
    }

    //Display the properties of the attached spatial device
    display_properties((CPhidgetHandle)spatial);

    //read spatial event data
    printf("Reading.....\n");

    //Set the data rate for the spatial events
    CPhidgetSpatial_setDataRate(spatial, 16);

    //run until user input is read
    printf("Press any key to end\n");
    getchar();

    //since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created
    printf("Closing...\n");
    CPhidget_close((CPhidgetHandle)spatial);
    CPhidget_delete((CPhidgetHandle)spatial);

    return 0;
}
Exemplo n.º 14
0
int MotorController::regHanlders(void)
{
    printf("MotorController::regHandlers\n");

	#if (!DEBUG_MODE_PC)
	int result;
	const char *err;
	#endif

	//Declare a motor control handle
	motorCtrlHandle = 0;

	//create the motor control object
	CPhidgetMotorControl_create(&motorCtrlHandle);

	//Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)motorCtrlHandle, MotorAttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)motorCtrlHandle, MotorDetachHandler, NULL);
	CPhidget_set_OnError_Handler( (CPhidgetHandle)motorCtrlHandle, MotorErrorHandler,  NULL);

	//Registers a callback that will run if an input changes.
	//Requires the handle for the Phidget, the function that will be called, and a arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetMotorControl_set_OnInputChange_Handler(motorCtrlHandle, MotorInputChangeHandler, NULL);

	//Registers a callback that will run if a motor changes.
	//Requires the handle for the Phidget, the function that will be called, and a arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetMotorControl_set_OnVelocityChange_Handler(motorCtrlHandle, MotorVelocityChangeHandler, NULL);

	//Registers a callback that will run if the current draw changes.
	//Requires the handle for the Phidget, the function that will be called, and a arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetMotorControl_set_OnCurrentChange_Handler(motorCtrlHandle, MotorCurrentChangeHandler, NULL);

	//open the motor control for device connections
	CPhidget_open((CPhidgetHandle)motorCtrlHandle, -1);

	//get the program to wait for a motor control device to be attached
	printf("Waiting for MotorControl to be attached....\n");
	#if (!DEBUG_MODE_PC)
	if ((result = CPhidget_waitForAttachment((CPhidgetHandle)motorCtrlHandle, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return 0;
	}
	#endif

	//Display the properties of the attached motor control device
	MotorDisplayProperties(motorCtrlHandle);

	//all done, exit
	return 0;
}
Exemplo n.º 15
0
bool attach(CPhidgetSpatialHandle &phid,
			int serial_number,
			int data_rate)
{
    int result;
    const char *err;

    //create the spatial object
    CPhidgetSpatial_create(&phid);

    // Set the handlers to be run when the device is
	// plugged in or opened from software, unplugged or
	// closed from software, or generates an error.
    CPhidget_set_OnAttach_Handler((CPhidgetHandle)phid,
								  AttachHandler, NULL);
    CPhidget_set_OnDetach_Handler((CPhidgetHandle)phid,
								  DetachHandler, NULL);
    CPhidget_set_OnError_Handler((CPhidgetHandle)phid,
								 ErrorHandler, NULL);

    // Registers a callback that will run according to the
	// set data rate that will return the spatial data changes
    // Requires the handle for the Spatial, the callback
	// handler function that will be called, 
    // and an arbitrary pointer that will be supplied to
	// the callback function (may be NULL)
    CPhidgetSpatial_set_OnSpatialData_Handler(phid,
											  SpatialDataHandler,
											  NULL);

    // open the spatial object for device connections
    CPhidget_open((CPhidgetHandle)phid, -1);

    // get the program to wait for a spatial device
	// to be attached
    ROS_INFO("Waiting for spatial to be attached.... \n");
    if ((result =
		 CPhidget_waitForAttachment((CPhidgetHandle)phid,
									10000))) {
        CPhidget_getErrorDescription(result, &err);
        ROS_INFO("Problem waiting for attachment: %s\n", err);
        return 0;
    }
    else {
		//Set the data rate for the spatial events
		CPhidgetSpatial_setDataRate(phid, data_rate);
        return true;
    }
}
Exemplo n.º 16
0
bool attach(CPhidgetMotorControlHandle &phid, int serial_number){

  //create the InterfaceKit object
	CPhidgetMotorControl_create(&phid);

	//Setup life-cycle handlers
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)phid, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)phid, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)phid, ErrorHandler, NULL);

  // Open
	CPhidget_open((CPhidgetHandle)phid, serial_number);

  return true;
}
Exemplo n.º 17
0
// Init
bool phidgetIMU::Init()
{
	// create driver object
	if( CPhidgetSpatial_create((CPhidgetSpatialHandle*)&mHandle) != 0 )
	{
		printf("phidgetIMU -- failed to create IMU device\n");
		return false;
	}

	//displayProperties();

	// set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)mHandle, imuAttach, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)mHandle, imuDetach, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)mHandle, imuError, NULL);

	// registers a callback that will run according to the set data rate that will return the spatial data changes
	CPhidgetSpatial_set_OnSpatialData_Handler((CPhidgetSpatialHandle)mHandle, imuData, this);


	// open the spatial object for device connections
	if( CPhidget_open((CPhidgetHandle)mHandle, -1) != 0 )
	{
		printf("failed to open IMU device\n");
		return false;
	}

	//displayProperties();

	// get the program to wait for a spatial device to be attached 
	/*printf("waiting for IMU to be attached...\n");
	const int result = CPhidget_waitForAttachment((CPhidgetHandle)mImu, 2000);

	if( result != 0 )
	{
		const char* err = NULL;
		CPhidget_getErrorDescription(result, &err);
		printf("failed to find attached IMU  (%s)\n", err);
		return false;
	}*/

	//Set the data rate for the spatial events
	CPhidgetSpatial_setDataRate((CPhidgetSpatialHandle)mHandle, /*16*/ 4);


	printf("phidgetIMU -- initialized IMU device\n");
	return true;
}
Exemplo n.º 18
0
CPhidgetAdvancedServoHandle InitializeServos(int n, int* channels, int grip_channel, double* AccelThrottle, double* VelLimThrottle, double grip_AccelThrottle, double grip_VelLimThrottle) {
	int result; 
	const char *err;
	double minAccel, maxAccel, minVel, maxVel;

	/* If servo is already defined, return. */
	if (servo != NULL) {
		return servo;
	}

	/* Create the advanced servo object */
	CPhidgetAdvancedServo_create(&servo); 

	/* Set the handlers to be run when the device is plugged in (opened) from software, unplugged (closed) from software, or generates an error. */
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)servo, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)servo, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)servo, ErrorHandler, NULL);

	/* Open the device for connections */
	CPhidget_open((CPhidgetHandle)servo, -1);

	LOG(logINFO) << "Waiting for servos to be attached..."; 
	if ((result = CPhidget_waitForAttachment((CPhidgetHandle)servo, 5000))) {
		CPhidget_getErrorDescription(result, &err);
		LOG(logERROR) << "Problem waiting for attachment: "<< err;
		return 0;
	}

	/* Set the acceleration and velocity limits of each joint angle actuator */
	for (int i = 0; i < n; i++) {
		CPhidgetAdvancedServo_getAccelerationMin(servo, channels[i], &minAccel);
		CPhidgetAdvancedServo_getAccelerationMax(servo, channels[i], &maxAccel);
		CPhidgetAdvancedServo_setAcceleration(servo, channels[i], AccelThrottle[i]*(maxAccel - minAccel) + minAccel );
		CPhidgetAdvancedServo_getVelocityMin(servo, channels[i], &minVel);
		CPhidgetAdvancedServo_getVelocityMax(servo, channels[i], &maxVel);
		CPhidgetAdvancedServo_setVelocityLimit(servo, channels[i], VelLimThrottle[i]*(maxVel - minVel) + minVel );
	}

	/* Set the acceleration and velocity limits of the end effector */
	CPhidgetAdvancedServo_getAccelerationMin(servo, grip_channel, &minAccel);
	CPhidgetAdvancedServo_getAccelerationMax(servo, grip_channel, &maxAccel);
	CPhidgetAdvancedServo_setAcceleration(servo, grip_channel, grip_AccelThrottle*(maxAccel - minAccel) + minAccel );
	CPhidgetAdvancedServo_getVelocityMin(servo, grip_channel, &minVel);
	CPhidgetAdvancedServo_getVelocityMax(servo, grip_channel, &maxVel);
	CPhidgetAdvancedServo_setVelocityLimit(servo, grip_channel, grip_VelLimThrottle*(maxVel - minVel) + minVel );

	return (CPhidgetAdvancedServoHandle)servo;
}
bool attach(
    CPhidgetInterfaceKitHandle &phid,
    int serial_number)
{
    CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, "/home/motters/Desktop/phidgets.log");

    //create the object
    CPhidgetInterfaceKit_create(&phid);

    //Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
    CPhidget_set_OnAttach_Handler((CPhidgetHandle)phid, AttachHandler, NULL);
    CPhidget_set_OnDetach_Handler((CPhidgetHandle)phid, DetachHandler, NULL);
    CPhidget_set_OnError_Handler((CPhidgetHandle)phid, ErrorHandler, NULL);

    //Registers a callback that will run if an input changes.
    //Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
    CPhidgetInterfaceKit_set_OnInputChange_Handler (phid, InputChangeHandler, NULL);

    //Registers a callback that will run if the sensor value changes by more than the OnSensorChange trig-ger.
    //Requires the handle for the IntefaceKit, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
    CPhidgetInterfaceKit_set_OnSensorChange_Handler (phid, SensorChangeHandler, NULL);

    //Registers a callback that will run if an output changes.
    //Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
    CPhidgetInterfaceKit_set_OnOutputChange_Handler (phid, OutputChangeHandler, NULL);

    //open the device for connections
    CPhidget_open((CPhidgetHandle)phid, serial_number);

    //get the program to wait for an interface kit device to be attached
    if (serial_number == -1) {
        ROS_INFO("Waiting for Interface Kit Phidget to be attached....");
    }
    else {
        ROS_INFO("Waiting for Interface Kit Phidget %d to be attached....", serial_number);
    }
    int result;
    if((result = CPhidget_waitForAttachment((CPhidgetHandle)phid, 10000)))
    {
        const char *err;
        CPhidget_getErrorDescription(result, &err);
	ROS_ERROR("Problem waiting for attachment: %s", err);
	return false;
    }
    else return true;
}
Exemplo n.º 20
0
qPhidgetRFID::qPhidgetRFID(QObject *parent) :
    QObject(parent)
{
    CPhidgetRFID_create(&rfidHandle);

    CPhidget_set_OnAttach_Handler((CPhidgetHandle)rfidHandle, attachHandler, NULL);
    CPhidget_set_OnDetach_Handler((CPhidgetHandle)rfidHandle, detachHandler, NULL);
//    CPhidget_set_OnError_Handler((CPhidgetHandle)gpsHandle, errorHandler, NULL);
    CPhidgetRFID_set_OnTag_Handler(rfidHandle, tagOnHandler, this);
    CPhidgetRFID_set_OnTagLost_Handler(rfidHandle, tagLostHandler, this);

    CPhidget_open((CPhidgetHandle)rfidHandle,-1);

    if(checkIfDeviceConnected())
        qDebug()<<"device connected";
    else
        qDebug()<<"no device found";
}
Exemplo n.º 21
0
bool attach(
    CPhidgetRFIDHandle &phid,
    int serial_number)
{
    int result;
    const char *err;

    //Declare an RFID handle
    CPhidgetRFIDHandle rfid = 0;

    //create the RFID object
    CPhidgetRFID_create(&rfid);

    //Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
    CPhidget_set_OnAttach_Handler((CPhidgetHandle)rfid, AttachHandler, NULL);
    CPhidget_set_OnDetach_Handler((CPhidgetHandle)rfid, DetachHandler, NULL);
    CPhidget_set_OnError_Handler((CPhidgetHandle)rfid, ErrorHandler, NULL);

    //Registers a callback that will run if an output changes.
    //Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
    CPhidgetRFID_set_OnOutputChange_Handler(rfid, OutputChangeHandler, NULL);

    //Registers a callback that will run when a Tag is read.
    //Requires the handle for the PhidgetRFID, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
    CPhidgetRFID_set_OnTag_Handler(rfid, TagHandler, NULL);

    //Registers a callback that will run when a Tag is lost (removed from antenna read range).
    //Requires the handle for the PhidgetRFID, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
    CPhidgetRFID_set_OnTagLost_Handler(rfid, TagLostHandler, NULL);

    //open the RFID for device connections
    CPhidget_open((CPhidgetHandle)rfid, -1);

    //get the program to wait for an RFID device to be attached
    ROS_INFO("Waiting for RFID sensor to be attached....");
    if ((result = CPhidget_waitForAttachment((CPhidgetHandle)rfid, 10000))) {
        CPhidget_getErrorDescription(result, &err);
        ROS_INFO("Problem waiting for RFID sensor attachment: %s\n", err);
        return false;
    }
    else return true;
}
Exemplo n.º 22
0
void RFIDreader::setup()
{
  #if ENABLE_RFID
	if(cfg().test){
		int result;
		const char *err;
		tagAvailable=false;
		CPhidgetRFID_create(&rfid);
		//Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
		CPhidget_set_OnAttach_Handler((CPhidgetHandle)rfid, AttachHandler, NULL);
		CPhidget_set_OnDetach_Handler((CPhidgetHandle)rfid, DetachHandler, NULL);
		CPhidget_set_OnError_Handler((CPhidgetHandle)rfid, ErrorHandler, NULL);
	  
		//Registers a callback that will run if an output changes.
		//Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
		CPhidgetRFID_set_OnOutputChange_Handler(rfid, OutputChangeHandler, NULL);
	  
		//Registers a callback that will run when a Tag is read.
		//Requires the handle for the PhidgetRFID, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
		CPhidgetRFID_set_OnTag_Handler(rfid, TagHandler, NULL);
	  
		//Registers a callback that will run when a Tag is lost (removed from antenna read range).
		//Requires the handle for the PhidgetRFID, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
		CPhidgetRFID_set_OnTagLost_Handler(rfid, TagLostHandler, NULL);
	
  
	  //open the RFID for device connections
		CPhidget_open((CPhidgetHandle)rfid, -1);
  
	  //get the program to wait for an RFID device to be attached
		printf("Waiting for RFID to be attached....");
		if((result = CPhidget_waitForAttachment((CPhidgetHandle)rfid, 2000)))
		{
			CPhidget_getErrorDescription(result, &err);
			printf("Problem waiting for attachment: %s\n", err);
		}
  
		CPhidgetRFID_setAntennaOn(rfid, 1);
	}
#endif
}
Exemplo n.º 23
0
void test()
{
	const char *err;	
	int result;
	CPhidgetFrequencyCounterHandle freq;
	//CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, NULL);

	CPhidgetFrequencyCounter_create(&freq);

	CPhidget_set_OnAttach_Handler((CPhidgetHandle)freq, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)freq, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)freq, ErrorHandler, NULL);

	CPhidgetFrequencyCounter_set_OnCount_Handler(freq, Count, NULL);

	CPhidget_open((CPhidgetHandle)freq, -1);

	//Wait for 10 seconds, otherwise exit
	if(result = CPhidget_waitForAttachment((CPhidgetHandle)freq, 10000))
	{

		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return;
	}

	display_generic_properties((CPhidgetHandle)freq);

	//Wait for enter
	getchar();

	printf("Closing...\n");

	CPhidget_close((CPhidgetHandle)freq);
	CPhidget_delete((CPhidgetHandle)freq);

	return;
}
void motor_callback(const std_msgs::String::ConstPtr& msg){
	ROS_INFO("Motor Move Request:");
	int result;
	const char *err;

	//Declare a motor control handle
	CPhidgetMotorControlHandle motoControl = 0;
	
	//create the motor control object
	CPhidgetMotorControl_create(&motoControl);

	CPhidget_set_OnAttach_Handler((CPhidgetHandle)motoControl, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)motoControl, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)motoControl, ErrorHandler, NULL);
	
	CPhidget_open((CPhidgetHandle)motoControl, -1);

	printf("Waiting for MotorControl to be attached....");
	if((result = CPhidget_waitForAttachment((CPhidgetHandle)motoControl, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return;
	}

	CPhidgetMotorControl_setAcceleration (motoControl, 0, 50.00);
	CPhidgetMotorControl_setVelocity (motoControl, 0, 100.00);
	
	//Wait for some time... 
	ros::Duration(1).sleep();
	
	CPhidgetMotorControl_setAcceleration (motoControl, 0,0);
	CPhidgetMotorControl_setVelocity (motoControl, 0, 0);

	printf("Closing...\n");
	CPhidget_close((CPhidgetHandle)motoControl);
	CPhidget_delete((CPhidgetHandle)motoControl);
}
Exemplo n.º 25
0
bool attach(
			CPhidgetLEDHandle &phid,
			int serial_number)
{
    int result;
    const char *err;

    // create the LED object
    CPhidgetLED_create(&phid);

    // Set the handlers to be run when the device is
	// plugged in or opened from software, unplugged or
	// closed from software, or generates an error.
    CPhidget_set_OnAttach_Handler((CPhidgetHandle)phid,
								  AttachHandler, NULL);
    CPhidget_set_OnDetach_Handler((CPhidgetHandle)phid,
								  DetachHandler, NULL);
    CPhidget_set_OnError_Handler((CPhidgetHandle)phid,
								 ErrorHandler, NULL);

    //open the LED for device connections
    CPhidget_open((CPhidgetHandle)phid, -1);

    //get the program to wait for an LED device to be attached
    printf("Waiting for LED to be attached....");
    if ((result =
		 CPhidget_waitForAttachment((CPhidgetHandle)phid,
									10000))) {
        CPhidget_getErrorDescription(result, &err);
        printf("Problem waiting for attachment: %s\n", err);
        return false;
    }
    else {
        return true;
    }
}
Exemplo n.º 26
0
int setup()
{
  init_debugging();
	int result, numSensors, i;
	const char *err;
  //handles *Handles;
	//Declare an InterfaceKit handle

	// Setup the IFKit
	CPhidgetInterfaceKit_create(&ifKit);
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)ifKit, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)ifKit, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)ifKit, ErrorHandler, NULL);
	CPhidgetInterfaceKit_set_OnInputChange_Handler (ifKit, IKInputChangeHandler, NULL);
	CPhidgetInterfaceKit_set_OnSensorChange_Handler (ifKit, IKSensorChangeHandler, NULL);
	CPhidgetInterfaceKit_set_OnOutputChange_Handler (ifKit, IKOutputChangeHandler, NULL);
	CPhidget_open((CPhidgetHandle)ifKit, -1);
  
	//get the program to wait for an interface kit device to be attached
	SetupLog("Waiting for interface kit to be attached....");
	if((result = CPhidget_waitForAttachment((CPhidgetHandle)ifKit, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return 0;
	}
	//Display the properties of the attached interface kit device
	IKDisplayProperties(ifKit);

  // Setup motoControl
  
	CPhidgetMotorControl_create(&motoControl);
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)motoControl, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)motoControl, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)motoControl, ErrorHandler, NULL);
	CPhidgetMotorControl_set_OnInputChange_Handler (motoControl, MCInputChangeHandler, NULL);
	CPhidgetMotorControl_set_OnVelocityChange_Handler (motoControl, MCVelocityChangeHandler, NULL);
	CPhidgetMotorControl_set_OnCurrentChange_Handler (motoControl, MCCurrentChangeHandler, NULL);
	CPhidget_open((CPhidgetHandle)motoControl, -1);
	SetupLog("Waiting for MotorControl to be attached....");
	if((result = CPhidget_waitForAttachment((CPhidgetHandle)motoControl, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return 0;
	}
	MCDisplayProperties(motoControl);
	CPhidgetMotorControl_setAcceleration (motoControl, 0, 50.00);
	CPhidgetMotorControl_setAcceleration (motoControl, 1, 50.00);

  // Setup AdvancedServo
	CPhidgetAdvancedServo_create(&servo);
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)servo, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)servo, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)servo, ErrorHandler, NULL);

	CPhidgetAdvancedServo_set_OnPositionChange_Handler(servo, ASPositionChangeHandler, NULL);
	CPhidget_open((CPhidgetHandle)servo, -1);
	SetupLog("Waiting for Phidget to be attached....");
	if((result = CPhidget_waitForAttachment((CPhidgetHandle)servo, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return 0;
	}

	//Display the properties of the attached device
	ASDisplayProperties(servo);
  CPhidgetAdvancedServo_setEngaged(servo, 0, 1);
	state.ServoPosition = 0;
	sensor.RightWhisker = 0;
	sensor.LeftWhisker = 0;
	sensor.FrontFacingIR = 0;
	sensor.TopIR = 0;
  state.AverageBaseLight = (float)10000;
  sensor.TopLeftLight = 0;
  sensor.TopRightLight = 0;
  state.flashWasOn = 0;
  state.wasOnBlackInLastIteration = 0;
  sensor.SpinSensor = 10.0;
  state.expectedMovement = None;
  state.expectedFor = 0;
  state.exitTrialCounter = 0;
  state.stuckCounter = 0;
  state.previousState = 2;
  gettimeofday(&state.lastFlashSighted, NULL);
  //#ifdef FREQUENCY
  //state.frequency = FREQUENCY;
  //#endif
	#ifndef NO_POWERLIB
	power_button_reset();
	
	while(power_button_get_value()==0)
	{
		sleep(1);
	}
	#endif
	
	
	return 0;
}
int interfacekit_simple()
{
	int result, numSensors, i;
	const char *err;

	//Declare an InterfaceKit handle
	CPhidgetInterfaceKitHandle ifKit = 0;

	//create the InterfaceKit object
	CPhidgetInterfaceKit_create(&ifKit);

	//Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)ifKit, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)ifKit, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)ifKit, ErrorHandler, NULL);

	//Registers a callback that will run if an input changes.
	//Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetInterfaceKit_set_OnInputChange_Handler (ifKit, InputChangeHandler, NULL);

	//Registers a callback that will run if the sensor value changes by more than the OnSensorChange trig-ger.
	//Requires the handle for the IntefaceKit, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetInterfaceKit_set_OnSensorChange_Handler (ifKit, SensorChangeHandler, NULL);

	//Registers a callback that will run if an output changes.
	//Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetInterfaceKit_set_OnOutputChange_Handler (ifKit, OutputChangeHandler, NULL);

	//open the interfacekit for device connections
	CPhidget_open((CPhidgetHandle)ifKit, -1);

	//get the program to wait for an interface kit device to be attached
	printf("Waiting for interface kit to be attached....");
	if((result = CPhidget_waitForAttachment((CPhidgetHandle)ifKit, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return 0;
	}

	//Display the properties of the attached interface kit device
	display_properties(ifKit);

	//read interface kit event data
	printf("Reading.....\n");

	//keep displaying interface kit data until user input is read
	printf("Press any key to go to next step\n");
	getchar();

	printf("Modifying sensor sensitivity triggers....\n");

	//get the number of sensors available
	CPhidgetInterfaceKit_getSensorCount(ifKit, &numSensors);

	//Change the sensitivity trigger of the sensors
	for(i = 0; i < numSensors; i++)
	{
		CPhidgetInterfaceKit_setSensorChangeTrigger(ifKit, i, 100);  //we'll just use 10 for fun
	}

	//read interface kit event data
	printf("Reading.....\n");

	//keep displaying interface kit data until user input is read
	printf("Press any key to go to next step\n");
	getchar();

	printf("Toggling Ratiometric....\n");

	CPhidgetInterfaceKit_setRatiometric(ifKit, 0);

	//read interface kit event data
	printf("Reading.....\n");

	//keep displaying interface kit data until user input is read
	printf("Press any key to end\n");
	getchar();

	//since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created
	printf("Closing...\n");
	CPhidget_close((CPhidgetHandle)ifKit);
	CPhidget_delete((CPhidgetHandle)ifKit);

	//all done, exit
	return 0;
}
int accelerometer_simple()
{
	int result, numAxes;
	const char *err;

	//Declare an accelerometer handle
	CPhidgetAccelerometerHandle accel = 0;

	//create the accelerometer object
	CPhidgetAccelerometer_create(&accel);

	//Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)accel, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)accel, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)accel, ErrorHandler, NULL);

	//Registers a callback that will run if the acceleration changes by more than the Acceleration trigger.
	//Requires the handle for the Accelerometer, the function that will be called, 
	//and an arbitrary pointer that will be supplied to the callback function (may be NULL)
	CPhidgetAccelerometer_set_OnAccelerationChange_Handler(accel, accel_AccelChangeHandler, NULL);

	//open the acclerometer for device connections
	CPhidget_open((CPhidgetHandle)accel, -1);

	//get the program to wait for an accelerometer device to be attached
	printf("Waiting for accelerometer to be attached.... \n");
	if((result = CPhidget_waitForAttachment((CPhidgetHandle)accel, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return 0;
	}

	//Display the properties of the attached accelerometer device
	display_properties((CPhidgetHandle)accel);

	//read accelerometer event data
	printf("Reading.....\n");

	//get the number of available axes on the attached accelerometer
	CPhidgetAccelerometer_getAxisCount(accel, &numAxes);

	//Most accelerometers have 2 axes so we'll pre-set their sensitivity to make the data more readable
	CPhidgetAccelerometer_setAccelerationChangeTrigger(accel, 0, 0.500);
	CPhidgetAccelerometer_setAccelerationChangeTrigger(accel, 1, 0.500);

	//If the accelerometer attached is a 3-axis, we'll set the sensitivity of the 3rd axis
	if(numAxes > 2)
	{
		CPhidgetAccelerometer_setAccelerationChangeTrigger(accel, 2, 0.500);
	}

	//wait until user input is read
	printf("Press any key to end\n");
	getchar();

	//since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created
	printf("Closing...\n");
	CPhidget_close((CPhidgetHandle)accel);
	CPhidget_delete((CPhidgetHandle)accel);

	//all done, exit
	return 0;
}
Exemplo n.º 29
0
int motorcontrol_simple()
{
	int result;
	const char *err;

	//Declare a motor control handle
	CPhidgetMotorControlHandle motoControl = 0;
	//CPhidgetMotorControlHandle motoControl2 = 1;

	//create the motor control object
	CPhidgetMotorControl_create(&motoControl);
	//CPhidgetMotorControl_create(&motoControl2);

	//Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)motoControl, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)motoControl, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)motoControl, ErrorHandler, NULL);
	/*	CPhidget_set_OnAttach_Handler((CPhidgetHandle)motoControl2, AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)motoControl2, DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)motoControl2, ErrorHandler, NULL);*/

	//Registers a callback that will run if an input changes.
	//Requires the handle for the Phidget, the function that will be called, and a arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetMotorControl_set_OnInputChange_Handler (motoControl, InputChangeHandler, NULL);
	//CPhidgetMotorControl_set_OnInputChange_Handler (motoControl2, InputChangeHandler, NULL);

	//Registers a callback that will run if a motor changes.
	//Requires the handle for the Phidget, the function that will be called, and a arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetMotorControl_set_OnVelocityChange_Handler (motoControl, VelocityChangeHandler, NULL);
	//CPhidgetMotorControl_set_OnVelocityChange_Handler (motoControl2, VelocityChangeHandler, NULL);

	//Registers a callback that will run if the current draw changes.
	//Requires the handle for the Phidget, the function that will be called, and a arbitrary pointer that will be supplied to the callback function (may be NULL).
	CPhidgetMotorControl_set_OnCurrentChange_Handler (motoControl, CurrentChangeHandler, NULL);
	//CPhidgetMotorControl_set_OnCurrentChange_Handler (motoControl2, CurrentChangeHandler, NULL);

	//open the motor control for device connections
	CPhidget_open((CPhidgetHandle)motoControl, -1);
	//CPhidget_open((CPhidgetHandle)motoControl2, -1);

	//get the program to wait for a motor control device to be attached
	printf("Waiting for MotorControl to be attached....");
	if((result = CPhidget_waitForAttachment((CPhidgetHandle)motoControl, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment: %s\n", err);
		return 0;
	}
	/*if((result = CPhidget_waitForAttachment((CPhidgetHandle)motoControl2, 10000)))
	{
		CPhidget_getErrorDescription(result, &err);
		printf("Problem waiting for attachment 2: %s\n", err);
		return 0;
		}*/

	//Display the properties of the attached motor control device
	display_properties(motoControl);
	//display_properties(motoControl2);

	//read motor control event data
	printf("Reading.....\n");

	//keep displaying motor control event data until user input is read
	printf("Press any key to continue\n");
	getchar();

	//Control the motor a bit.
	//Step 1: increase acceleration to 50, set target sped at 100
	/*CPhidgetMotorControl_setAcceleration (motoControl, 0, -50.00);
	CPhidgetMotorControl_setVelocity (motoControl, 0, -100.00);
	CPhidgetMotorControl_setAcceleration (motoControl, 1, 50.00);
	CPhidgetMotorControl_setVelocity (motoControl, 1, 100.00);

	printf("Press any key to continue\n");
	getchar();*/

	//Step 2: Set acceleration to 100, decrease target speed to 75
	CPhidgetMotorControl_setAcceleration (motoControl, 0, -100.00);
	CPhidgetMotorControl_setVelocity (motoControl, 0, -100.00);
	CPhidgetMotorControl_setAcceleration (motoControl, 1, 100.00);
	CPhidgetMotorControl_setVelocity (motoControl, 1, 70.00);

	printf("Press any key to continue\n");
	getchar();

	//Step 3: Stop the motor by decreasing speed to 0;
	CPhidgetMotorControl_setVelocity (motoControl, 0, 0.00);
	CPhidgetMotorControl_setAcceleration (motoControl, 0, 0.00);
	CPhidgetMotorControl_setVelocity (motoControl, 1, 0.00);
	CPhidgetMotorControl_setAcceleration (motoControl, 1, 0.00);

	printf("Press any key to end\n");
	getchar();

	//since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created
	printf("Closing...\n");
	CPhidget_close((CPhidgetHandle)motoControl);
	CPhidget_delete((CPhidgetHandle)motoControl);
	/*CPhidget_close((CPhidgetHandle)motoControl2);
	  CPhidget_delete((CPhidgetHandle)motoControl2);*/

	//all done, exit
	return 0;
}
Exemplo n.º 30
0
int test_interfacekit()
{
	int numInputs, numOutputs, numSensors;
	int err;
	CPhidgetInterfaceKitHandle IFK = 0;

	CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, NULL);
	
	CPhidgetInterfaceKit_create(&IFK);

	CPhidgetInterfaceKit_set_OnInputChange_Handler(IFK, IFK_InputChangeHandler, NULL);
	CPhidgetInterfaceKit_set_OnOutputChange_Handler(IFK, IFK_OutputChangeHandler, NULL);
	CPhidgetInterfaceKit_set_OnSensorChange_Handler(IFK, IFK_SensorChangeHandler, NULL);
	CPhidget_set_OnAttach_Handler((CPhidgetHandle)IFK, IFK_AttachHandler, NULL);
	CPhidget_set_OnDetach_Handler((CPhidgetHandle)IFK, IFK_DetachHandler, NULL);
	CPhidget_set_OnError_Handler((CPhidgetHandle)IFK, IFK_ErrorHandler, NULL);
	
	CPhidget_open((CPhidgetHandle)IFK, -1);

	//wait 5 seconds for attachment
	if((err = CPhidget_waitForAttachment((CPhidgetHandle)IFK, 0)) != EPHIDGET_OK )
	{
		const char *errStr;
		CPhidget_getErrorDescription(err, &errStr);
		printf("Error waiting for attachment: (%d): %s\n",err,errStr);
		goto exit;
	}
	
	display_generic_properties((CPhidgetHandle)IFK);
	CPhidgetInterfaceKit_getOutputCount((CPhidgetInterfaceKitHandle)IFK, &numOutputs);
	CPhidgetInterfaceKit_getInputCount((CPhidgetInterfaceKitHandle)IFK, &numInputs);
	CPhidgetInterfaceKit_getSensorCount((CPhidgetInterfaceKitHandle)IFK, &numSensors);
	
	CPhidgetInterfaceKit_setOutputState((CPhidgetInterfaceKitHandle)IFK, 0, 1);

	printf("Sensors:%d Inputs:%d Outputs:%d\n", numSensors, numInputs, numOutputs);
	
	//err = CPhidget_setDeviceLabel((CPhidgetHandle)IFK, "test");
	
	while(1)
	{
		sleep(1);
	}
	
	while(1)
	{
		CPhidgetInterfaceKit_setOutputState(IFK, 7, 1);
		CPhidgetInterfaceKit_setOutputState(IFK, 7, 0);
	}

	CPhidgetInterfaceKit_setOutputState(IFK, 0, 1);
	sleep(1);
	CPhidgetInterfaceKit_setOutputState(IFK, 0, 0);
	sleep(1);
	CPhidgetInterfaceKit_setOutputState(IFK, 0, 1);
	sleep(1);
	CPhidgetInterfaceKit_setOutputState(IFK, 0, 0);

	sleep(5);

exit:
	CPhidget_close((CPhidgetHandle)IFK);
	CPhidget_delete((CPhidgetHandle)IFK);

	return 0;
}