3 #define deg2rad(deg) ((deg*M_PI/180.0)) 7 struct termios oldt, newt;
11 tcgetattr(STDIN_FILENO, &oldt);
13 newt.c_lflag &= ~(ICANON | ECHO);
14 tcsetattr(STDIN_FILENO, TCSANOW, &newt);
15 oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
16 fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
20 tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
21 fcntl(STDIN_FILENO, F_SETFL, oldf);
33 printf(
"servo test program, current id = %d\n",
id);
34 printf(
" 1-9 : change id\n");
35 printf(
" r : setReset\n");
36 printf(
" o : setTorqueOn\n");
37 printf(
" f : setTorqueOff\n");
38 printf(
" b : setTorqueBreak\n");
39 printf(
" p : setPosition to 90\n");
40 printf(
" P : setPosition to -90\n");
41 printf(
" i : setPositions 90 to id 2 3 4 5 6 6 8\n");
42 printf(
" I : setPositions -90 to id 2 3 4 5 6 6 8\n");
43 printf(
" m : setMaxTorque to 100\n");
44 printf(
" M : setMaxTorque to 50\n");
45 printf(
" g : getPosition\n");
46 printf(
" G : getPositions\n");
47 printf(
" d : getDuration\n");
48 printf(
" s : getSpeed\n");
49 printf(
" t : getTorque\n");
50 printf(
" c : getTemperature\n");
51 printf(
" v : getVoltage\n");
52 printf(
" S : getState\n");
97 {
int ids[8] = {2,3,4,5,6,7,8,9};
98 double rads[8] = {90,90,90,90,90,90,90,90};
99 double secs[8] = { 3, 3, 3, 3, 3, 3, 3, 3};
103 {
int ids[8] = {2,3,4,5,6,7,8,9};
104 double rads[8] = {-90,-90,-90,-90,-90,-90,-90,-90};
105 double secs[8] = { 3, 3, 3, 3, 3, 3, 3, 3};
117 fprintf(stderr,
"angle = %f [deg]\n", angle);
120 {
int ids[8] = {2,3,4,5,6,7,8,9};
122 for(
int i = 0;
i < 8;
i++ ) {
126 fprintf(stderr,
"angles = %f %f %f %f %f %f %f %f [deg]\n", angles[0],angles[1],angles[2],angles[3],angles[4],angles[5],angles[6],angles[7]);}
131 fprintf(stderr,
"duration = %f [msec]\n", duration);
136 fprintf(stderr,
"speed = %f [deg/sec]\n", speed);
141 fprintf(stderr,
"torque = %f [mA]\n", torque);
146 fprintf(stderr,
"temperature = %f [C]\n", temperature);
151 fprintf(stderr,
"voltage = %f [V]\n", voltage);
154 unsigned char data[30];
156 fprintf(stderr,
"state =");
157 for(
int i = 0;
i < 30;
i++) {
158 fprintf(stderr,
" %02X", data[
i]);
159 if ( i % 10 == 9 ) fprintf(stderr,
" : ");
161 fprintf(stderr,
"\n");
int getSpeed(int id, double *duration)
int getVoltage(int id, double *voltage)
int getPosition(int id, double *angle)
int getDuration(int id, double *duration)
int getTemperature(int id, double *temperature)
int getState(int id, unsigned char *data)
int setMaxTorque(int id, short percentage)
int getTorque(int id, double *torque)
int setTorqueBreak(int id)
int setPosition(int id, double rad)
int setPositions(int len, int *id, double *rad)
int usleep(useconds_t usec)