27 #include <sys/types.h> 28 #include <sys/socket.h> 29 #include <netinet/in.h> 31 #include <arpa/inet.h> 58 : counter_(0), period_(period)
60 socket_ = socket(AF_INET, SOCK_DGRAM, 0);
61 addr_.sin_family = AF_INET;
62 addr_.sin_port = htons(10000);
63 addr_.sin_addr.s_addr = inet_addr (
"127.0.0.1");
65 bind(socket_, (
struct sockaddr *)&
addr_,
sizeof(
addr_));
84 FD_SET (socket_, &fds);
87 time.tv_usec = timeout * 1000;
89 int r = select (socket_ + 1, &fds, NULL, NULL, &time);
92 ROS_ERROR (
"select error: %s", strerror(errno));
95 if (r > 0 && FD_ISSET (socket_, &fds))
97 struct sockaddr_in recv_addr;
100 int size = recvfrom (socket_,
101 &recv_buff_,
sizeof (recv_buff_),
102 0, (
struct sockaddr *)&recv_addr, &len);
103 ROS_INFO(
"recv from: %s, size=%d", inet_ntoa(recv_addr.sin_addr), size);
125 size = sendto (socket_,
126 (
char *) &send_buff_,
sizeof (send_buff_),
127 0, (
struct sockaddr *) &recv_addr,
sizeof (recv_addr));
128 if (size !=
sizeof (send_buff_))
130 ROS_WARN (
"Failed to send packet.");
144 ROS_INFO(
"mxt.dat.jnt: % 4.3f % 4.3f % 4.3f % 4.3f % 4.3f % 4.3f % 4.3f % 4.3f",
161 stat.
add (
"Counter", counter_);
165 if (diff > period_ * 1.2)
167 stat.
summary(diagnostic_msgs::DiagnosticStatus::WARN,
168 "Periodic time exceeds 120%");
172 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
173 "Periodic time is normal");
175 stat.
add (
"Period", diff);
181 double time_dif = (g_time_now -
g_time_old).toSec();
182 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"Periodic time is normal");
183 stat.
add (
"Period", time_dif);
189 int main (
int argc,
char **argv)
192 ros::init (argc, argv,
"melfa_loopback");
196 ros::param::param<bool>(
"~realtime", realtime,
false);
198 ros::param::param<double>(
"~period", period, 0.0071);
211 struct sched_param param;
212 memset(¶m, 0,
sizeof(param));
213 int policy = SCHED_FIFO;
214 param.sched_priority = sched_get_priority_max(policy);
216 ROS_WARN(
"Setting up Realtime scheduler");
217 if (sched_setscheduler(0, policy, ¶m) < 0) {
218 ROS_ERROR(
"sched_setscheduler: %s", strerror(errno));
219 ROS_ERROR(
"Please check you are using PREEMPT_RT kernel and set /etc/security/limits.conf");
222 if (mlockall(MCL_CURRENT|MCL_FUTURE) < 0)
224 ROS_ERROR(
"mlockall: %s", strerror(errno));
void summary(unsigned char lvl, const std::string s)
void setHardwareID(const std::string &hwid)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
IMETHOD Vector diff(const Vector &p_w_a, const Vector &p_w_b, double dt=1)
void add(const std::string &name, TaskFunction f)
double period_
Periodic time [s].
void diagnose(diagnostic_updater::DiagnosticStatusWrapper &stat)
void loop_diagnostic(diagnostic_updater::DiagnosticStatusWrapper &stat)
union enet_rtcmd_str::rtdata dat
LoopbackNode(double period)
int main(int argc, char **argv)
Main function.
int counter_
Packet counter.
void print_mxt_packet(MXTCMD &mxt)
bool update(double timeout=0.06)
ROSCPP_DECL void shutdown()
void add(const std::string &key, const T &val)