helpers.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // Copyright 2022 FZI Forschungszentrum Informatik
5 // Created on behalf of Universal Robots A/S
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // -- END LICENSE BLOCK ------------------------------------------------
19 
20 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 
30 #include <ur_client_library/log.h>
31 
32 #include <cstring>
33 #include <fstream>
34 #include <iostream>
35 
36 namespace urcl
37 {
38 bool setFiFoScheduling(pthread_t& thread, const int priority)
39 {
40  struct sched_param params;
41  params.sched_priority = priority;
42  int ret = pthread_setschedparam(thread, SCHED_FIFO, &params);
43  if (ret != 0)
44  {
45  switch (ret)
46  {
47  case EPERM:
48  {
49  URCL_LOG_ERROR("Your system/user seems not to be setup for FIFO scheduling. We recommend using a lowlatency "
50  "kernel with FIFO scheduling. See "
51  "https://github.com/UniversalRobots/Universal_Robots_ROS_Driver/blob/master/ur_robot_driver/"
52  "doc/real_time.md for details.");
53  break;
54  }
55  default:
56 
57  {
58  URCL_LOG_ERROR("Unsuccessful in setting thread to FIFO scheduling with priority %i. %s", priority,
59  strerror(ret));
60  }
61  }
62  }
63  // Now verify the change in thread priority
64  int policy = 0;
65  ret = pthread_getschedparam(thread, &policy, &params);
66  if (ret != 0)
67  {
68  URCL_LOG_ERROR("Couldn't retrieve scheduling parameters");
69  return false;
70  }
71 
72  // Check the correct policy was applied
73  if (policy != SCHED_FIFO)
74  {
75  URCL_LOG_ERROR("Scheduling is NOT SCHED_FIFO!");
76  return false;
77  }
78  else
79  {
80  URCL_LOG_INFO("SCHED_FIFO OK, priority %i", params.sched_priority);
81  if (params.sched_priority != priority)
82  {
83  URCL_LOG_ERROR("Thread priority is %i instead of the expected %i", params.sched_priority, priority);
84  return false;
85  }
86  }
87  return true;
88 }
89 } // namespace urcl
#define URCL_LOG_ERROR(...)
Definition: log.h:26
bool setFiFoScheduling(pthread_t &thread, const int priority)
Definition: helpers.cpp:38
#define URCL_LOG_INFO(...)
Definition: log.h:25


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Tue Jul 4 2023 02:09:47