test_xarm_cgpio_states.cpp
Go to the documentation of this file.
1 /* Copyright 2021 UFACTORY Inc. All Rights Reserved.
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Author: Jason <jason@ufactory.cc>
6  Vinman <vinman@ufactory.cc>
7  ============================================================================*/
8 #include "ros/ros.h"
9 #include <xarm_msgs/CIOState.h>
10 
11 void chatterCallback(xarm_msgs::CIOState cio_msg)
12 {
13  // printf("[CGPIO] functional_input_difitals: [");
14  // for (int i = 0; i < 16; ++i) {
15  // printf("%d,", (cio_msg.input_digitals[0] >> i) & 0x0001);
16  // }
17  // printf("]\n");
18  // printf("[CGPIO] functional_output_difitals: [");
19  // for (int i = 0; i < 16; ++i) {
20  // printf("%d,", (cio_msg.output_digitals[0] >> i) & 0x0001);
21  // }
22  // printf("]\n");
23 
24  printf("[INPUT]\n");
25  printf(" [CI] ");
26  for (int i = 0; i < 8; ++i) { printf("CI%d=%d, ", i, (cio_msg.input_digitals[1] >> i) & 0x0001); }
27  printf("\n");
28  // printf(" [DI] ");
29  // for (int i = 8; i < 16; ++i) { printf("DI%d=%d, ", i-8, (cio_msg.input_digitals[1] >> i) & 0x0001); }
30  // printf("\n");
31  printf(" [AI] AI0=%f, AI1=%f\n", cio_msg.input_analogs[0], cio_msg.input_analogs[1]);
32 
33  printf("[OUTPUT]\n");
34  printf(" [CO] ");
35  for (int i = 0; i < 8; ++i) { printf("CO%d=%d, ", i, (cio_msg.output_digitals[1] >> i) & 0x0001); }
36  printf("\n");
37  // printf(" [DO] ");
38  // for (int i = 8; i < 16; ++i) { printf("DO%d=%d, ", i-8, (cio_msg.output_digitals[1] >> i) & 0x0001); }
39  // printf("\n");
40  printf(" [AO] AO0=%f, AO1=%f\n", cio_msg.output_analogs[0], cio_msg.output_analogs[1]);
41 
42 
43  printf("[CONF]\n");
44  printf(" [CI] ");
45  for (int i = 0; i < 8; ++i) { printf("CI%d=%d, ", i, cio_msg.input_conf[i]); }
46  printf("\n");
47  // printf(" [DI] ");
48  // for (int i = 8; i < 16; ++i) { printf("DI%d=%d, ", i-8, cio_msg.input_conf[i]); }
49  // printf("\n");
50  printf(" [CO] ");
51  for (int i = 0; i < 8; ++i) { printf("CO%d=%d, ", i, cio_msg.output_conf[i]); }
52  printf("\n");
53  // printf(" [DO] ");
54  // for (int i = 8; i < 16; ++i) { printf("DO%d=%d, ", i-8, cio_msg.output_conf[i]); }
55  // printf("\n");
56 
57  printf("======================================\n");
58 }
59 
60 int main(int argc, char **argv)
61 {
62  ros::init(argc, argv, "xarm_cgpio_states");
64  ros::Subscriber sub = n.subscribe("/xarm/xarm_cgpio_states", 1000, chatterCallback);
65  ros::spin();
66 
67  return 0;
68 }
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
ROSCPP_DECL void spin()
void chatterCallback(xarm_msgs::CIOState cio_msg)


xarm_api
Author(s):
autogenerated on Sat May 8 2021 02:51:23