55 std::string pubName = (
myID ==
rightGlove) ?
"rightGloveData" :
"leftGloveData";
61 if (!gloveDev->init(serialPort.c_str())) {
62 printf(
"Could not start GloveDevice... gloveDev->init(%s) failed. Bailing out\n", serialPort.c_str());
71 printf(
"Loading calibration file \"%s\"\n", srcFileName);
76 if ((f = fopen(srcFileName,
"r")) == NULL) {
77 printf(
"ERROR loading calibration file - open file error!\n");
80 printf(
"Trying to load calibration file \"%s\"\n", tmp.c_str());
81 if ((f = fopen(tmp.c_str(),
"r")) == NULL) {
82 printf(
"Could not open file.\n");
86 printf(
"Successfully opened file.\n");
92 printf(
"Stopping server thread.\n");
103 double tmpraw1, tmprad1, tmpraw2, tmprad2;
106 if (!fscanf(f,
"%lf:%lf %lf:%lf\n", &tmprad1, &tmpraw1, &tmprad2, &tmpraw2)) {
107 printf(
"load calibration file - error: read from file !\n");
114 printf(
"ERROR in calibration data!\nJoint %s does not achieve minimum resolution.\n",
JOINT_NAME[i]);
115 printf(
"Joint resolution: %d Minimum resolution: %d\n\n", (
int) fabs(tmpraw2 - tmpraw1),
118 if (fabs(tmpraw2 - tmpraw1) < 2) {
120 printf(
"Bailing out...");
133 printf(
"load calibration file successful !\n");
136 printf(
"Starting server thread again.\n");
157 #define PAUSE_SET 10000 158 #define PAUSE_WRITE 10000 162 return vAcc[0][index];
164 std::vector<unsigned int> data;
165 for (
unsigned int i = 0; i <
MAX_SETS; i++)
166 data.push_back((
unsigned int) vAcc[i][index]);
167 std::sort(data.begin(), data.end());
169 if (MAX_SETS % 2 == 0)
170 return (
unsigned char) ((data[MAX_SETS / 2 - 1] + data[MAX_SETS / 2]) / 2);
172 return (
unsigned char) data[(MAX_SETS - 1) / 2];
182 asr_msgs::AsrGlove gloveData;
183 asr_msgs::AsrGlove gloveData_radian;
190 for (
unsigned int i = 0; i <
MAX_SETS; i++) {
197 printf(
"%3d ", vAcc[i][j]);
201 if (i + 1 < MAX_SETS)
214 printf(
"%3d ", v[j]);
222 printf(
"Could not permute values. Bailing out.\n");
228 printf(
"%s", ctime(&now));
232 for (
unsigned int i = 0; i < n; i++)
233 printf(
"%3d ", (
int) v_perm[i]);
237 double *temp =
new double[n];
238 for (
unsigned int i = 0 ; i < n ; i++) temp[i] = (
double) v_perm[i];
240 printf(
"Couldn't write Notification to NotificationManager. Error!\n");
245 printf(
"Couldn't write Notification to NotificationManager. Error!\n");
256 if (
sizeof(valIn) >
sizeof(valOut)) {
257 printf(
"ERROR in permuteValues(). Array sizes do not fit for permutation!\n");
287 double * radianArray =
new double[size];
288 for (
unsigned int i = 0 ; i < size; i++){
295 for (
unsigned int i = 0; i < size; i++) {
296 gloveData.data[i] = data[i];
299 std::stringstream output;
300 output <<
"Glove Data Message published: " <<
myID <<
" ";
301 for (
unsigned int i = 0; i < size; i++) {
302 output << gloveData.data[i] <<
" ";
304 ROS_INFO(
"%s", output.str().c_str());
311 #if gloveServer_impl_test 312 int main(
int argc,
char **argv)
unsigned int GLOVERAW_MAP2_GLOVEINVENTOR[22]
double getRadian(int index, unsigned char val)
boost::thread * boostWorkerThread
Thread for delivering tracker data to nCenter.
double * getRadianArray(unsigned char *data, unsigned int size)
void publish(const boost::shared_ptr< M > &message) const
std::vector< double > FulcRaw2
const int RADSIGN[22]
Sign of angle. Notation in inventor model order, use after permutation!!!
const int MIN_JOINT_RESOLUTION
bool loadCalibFile(const char *srcFileName)
std::vector< double > FulcRad2
bool permuteValues(unsigned char *valIn, unsigned char *valOut)
permute sensor values according to GLOVERAW_MAP2_GLOVEINVENTOR mapping
unsigned char getMedian(unsigned char(&vAcc)[MAX_SETS][MAX_SENSORS], unsigned int index)
ros::Publisher gloveDataPub_radian
bool init(std::string serialPort)
void workerThread()
this method is called by static method s_workerthread
std::vector< double > FulcRaw1
bool cmdGetSensorValues(vector_t values, uchar_t *n, statusQuery_t *query, gloveStatusByte_t *gloveStatusByte)
ros::Publisher gloveDataPub
bool threadRunning
flag switching on/off thread
int main(int argc, char **argv)
gloveServer_impl(gloveID id, std::string name)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
const unsigned int GLOVERAW_MAP2_GLOVEINVENTOR_DEFAULT[22]
#define DEFAULT_CALIBRATION_PATH
ROSCPP_DECL void spinOnce()
const char * JOINT_NAME[]
for debug output
bool sendNotificationDataToRos(double *data, unsigned int size, asr_msgs::AsrGlove gloveData, ros::Publisher publisher)
Send sensor data to Notification Center.
std::vector< double > FulcRad1