Phidget SBC3 Digital Inputs and Encoder QME-01
Posted: Wed Mar 15, 2017 8:37 am
Good day, Phidget Community.
Last week I was trying to connect this particular model of encoder:
http://www.robotshop.com/en/lynxmotion- ... ifications
Alongside the Phidgets SBC3.
I managed to get some sort of output by using an example I found online, the output is as follows:
However, the problem is that the Digital input print is not on pair when the DC motor starts picking up speed.
I can only get the previously written output when I move the wheel by hand and quite slowly, but as soon as I start rotating it slightly faster, I stop getting any kind of output.
Now my question is, what could be the cause of this issue?
I took the example online as-is, and reduced it to only print the Digital inputs, and I am still getting the same problem.
Here's the main code I am using (reduced):
(NOTE: the kservo.hpp is a library used for the movement of the DC motor, is completely separate and I only use it to enable/disable motor motion)
Any kind of help would be greatly appreciated!
Last week I was trying to connect this particular model of encoder:
http://www.robotshop.com/en/lynxmotion- ... ifications
Alongside the Phidgets SBC3.
I managed to get some sort of output by using an example I found online, the output is as follows:
Code: Select all
Digital Input: 0 > State: 1
Digital Input: 1 > State: 0
Digital Input: 2 > State: 0
Digital Input: 3 > State: 0
Digital Input: 4 > State: 0
Digital Input: 5 > State: 0
Digital Input: 6 > State: 0
Digital Input: 7 > State: 0
Digital Input: 0 > State: 0
Digital Input: 0 > State: 1
Digital Input: 0 > State: 0
Digital Input: 0 > State: 1
(and so on)
I can only get the previously written output when I move the wheel by hand and quite slowly, but as soon as I start rotating it slightly faster, I stop getting any kind of output.
Now my question is, what could be the cause of this issue?
I took the example online as-is, and reduced it to only print the Digital inputs, and I am still getting the same problem.
Here's the main code I am using (reduced):
(NOTE: the kservo.hpp is a library used for the movement of the DC motor, is completely separate and I only use it to enable/disable motor motion)
Code: Select all
//
// sbcexample.c
//
// This simple example creates an InterfaceKit handle, hooks the event
// handlers and opens it.
// It reads the status of the inputs and outputs then waits for an InterfaceKit
// to be attached and waits for events to be fired.
// Digital output 0 will trigger on when any sensor value is greater than 500.
//
// Modified by Kat Dornian on 2014-03-26.
//
// Copyright 2014 Phidgets Inc.
// This work is licensed under the Creative Commons Attribution 2.5 Canada License.
// To view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/ca/
// To compile:
// g++ -o test encoder.c -lphidget21 -ldl -lpthread -lm
#include <stdio.h>
#include <unistd.h>
#include <phidget21.h>
#include "kservo.hpp"
#define phi0 0
//Callback that will run if an input changes.
//Index - Index of the input that generated the event, State - boolean (0 or 1) representing the input state (on or off)
int CCONV InputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int State)
{
fprintf(stdout, "Digital Input: %d > State: %d\n", Index, State);
fflush(stdout);
return 0;
}
int interfacekit_simple()
{
int result;
const char *err;
//Declare an InterfaceKit handle
CPhidgetInterfaceKitHandle ifKit = 0;
//create the InterfaceKit object
CPhidgetInterfaceKit_create(&ifKit);
//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;
}
//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);
//keep displaying interface kit until program is ended
while(1) {
usleep(1000);
}
CPhidget_close((CPhidgetHandle)ifKit);
CPhidget_delete((CPhidgetHandle)ifKit);
//all done, exit
return 0;
}
int main(int argc, char* argv[])
{
interfacekit_simple();
// int enc = CPhidgetRFID_getOutputState(IFK, 0);
//printf("%d \n",&enc);
return 0;
}