Skip to content

Commit 27706fc

Browse files
authored
Merge pull request #3544 from satiowadahc/cw-translate
2 parents c56ee33 + 4457560 commit 27706fc

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
component joint_axis_mapper """Translate from Joint to Axis""";
2+
3+
license "GPL";
4+
5+
pin in bit temp "Fault in";
6+
7+
function _;
8+
option singleton yes;
9+
option rtapi_app no;
10+
11+
;;
12+
13+
static char *coord = "XYZABCUVWXYZABCUVW";
14+
RTAPI_MP_STRING(coord, "Existing Axes");
15+
16+
int number_joints = 9;
17+
static int axis_counts[9];
18+
19+
typedef struct{
20+
hal_bit_t *fault_in[16];
21+
hal_bit_t *fault_out[16];
22+
} faults_in_t;
23+
24+
static faults_in_t *faults_in;
25+
char fault_letter[16];
26+
27+
28+
29+
int rtapi_app_main(void) {
30+
int r = 0;
31+
comp_id = hal_init("joint_axis_mapper");
32+
char buf[HAL_NAME_LEN + 1];
33+
34+
if(comp_id < 0) return comp_id;
35+
36+
number_joints = strlen(coord);
37+
faults_in = hal_malloc(sizeof(faults_in_t));
38+
39+
rtapi_print_msg(RTAPI_MSG_INFO, "Joint Axis Mapper - Initializing with coords %s\n", coord);
40+
41+
int this_count = 0;
42+
for(int i =0; i < strlen(coord); i++){
43+
if(coord[i] != ' ' && coord[i] != ';' && coord[i] != '{' && coord[i] != '}' && coord[i] != ',' &&
44+
coord[i] != '\n' && coord[i] != '\r' && coord[i] != '\t' && coord[i] != '\"' && coord[i] != '\'') {
45+
coord[this_count++] = coord[i];
46+
number_joints--;
47+
}
48+
}
49+
coord[this_count] = '\0';
50+
51+
this_count = 0;
52+
number_joints = strlen(coord);
53+
54+
for(int i = 0; i < strlen(coord); i++) {
55+
fault_letter[i] = coord[i];
56+
this_count = 0;
57+
if(coord[i] == 'X' || coord[i] == 'x'){ axis_counts[0]++; this_count = axis_counts[0]; }
58+
if(coord[i] == 'Y' || coord[i] == 'y'){ axis_counts[1]++; this_count = axis_counts[1]; }
59+
if(coord[i] == 'Z' || coord[i] == 'z'){ axis_counts[2]++; this_count = axis_counts[2]; }
60+
if(coord[i] == 'A' || coord[i] == 'a'){ axis_counts[3]++; this_count = axis_counts[3]; }
61+
if(coord[i] == 'B' || coord[i] == 'b'){ axis_counts[4]++; this_count = axis_counts[4]; }
62+
if(coord[i] == 'C' || coord[i] == 'c'){ axis_counts[5]++; this_count = axis_counts[5]; }
63+
if(coord[i] == 'U' || coord[i] == 'u'){ axis_counts[6]++; this_count = axis_counts[6]; }
64+
if(coord[i] == 'V' || coord[i] == 'v'){ axis_counts[7]++; this_count = axis_counts[7]; }
65+
if(coord[i] == 'W' || coord[i] == 'w'){ axis_counts[8]++; this_count = axis_counts[8]; }
66+
67+
if(this_count == 1){
68+
hal_pin_bit_newf(HAL_IN, &(faults_in->fault_in[i]), comp_id, "jam.%c-fault", coord[i]);
69+
hal_pin_bit_newf(HAL_OUT, &(faults_in->fault_out[i]), comp_id, "jam.%c-fault-latched", coord[i]);
70+
}
71+
else if(this_count > 1){
72+
hal_pin_bit_newf(HAL_IN, &(faults_in->fault_in[i]), comp_id, "jam.%c%d-fault", coord[i], this_count);
73+
hal_pin_bit_newf(HAL_OUT, &(faults_in->fault_out[i]), comp_id, "jam.%c%d-fault-latched", coord[i], this_count);
74+
}
75+
else {
76+
rtapi_print_msg(RTAPI_MSG_ERR, "Joint Axis Mapper - %c axis not found in coord string\n", coord[i]);
77+
}
78+
}
79+
80+
hal_export_funct("joint_axis_mapper", (void(*))_, 0, 1, 0, comp_id);
81+
hal_ready(comp_id);
82+
return 0;
83+
}
84+
85+
void rtapi_app_exit(void) {
86+
hal_exit(comp_id);
87+
}
88+
89+
90+
FUNCTION(_) {
91+
for(int i = 0; i < number_joints; i++) {
92+
if(*faults_in->fault_in[i] && ! *faults_in->fault_out[i]){
93+
rtapi_print_msg(RTAPI_MSG_ERR, "%c Axis fault detected\n", fault_letter[i]);
94+
}
95+
*(faults_in->fault_out[i]) = *(faults_in->fault_in[i]);
96+
}
97+
}

0 commit comments

Comments
 (0)