Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/sensor_trigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,28 @@
<< gpio_chip_ << "line number " << gpio_line_ << ".");
}

// Set CPU affinity
// Create thread
trigger_time_publisher_ = create_publisher<builtin_interfaces::msg::Time>("trigger_time", 1000);
trigger_thread_ = std::make_unique<std::thread>(&SensorTrigger::run, this);

// Set CPU affinity for trigger_thread_
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(cpu_, &cpuset);
if (pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset)) {
RCLCPP_WARN_STREAM(get_logger(), "Failed to set CPU affinity: " << strerror(errno) << ".");
if (pthread_setaffinity_np(trigger_thread_->native_handle(), sizeof(cpu_set_t), &cpuset)) {
RCLCPP_WARN_STREAM(get_logger(), "Failed to set thread CPU affinity: " << strerror(errno) << ".");
}
if (pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset)) {
RCLCPP_WARN_STREAM(get_logger(), "Failed to check CPU affinity: " << strerror(errno) << ".");
if (pthread_getaffinity_np(trigger_thread_->native_handle(), sizeof(cpu_set_t), &cpuset)) {

Check warning on line 79 in src/sensor_trigger.cpp

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (getaffinity)
RCLCPP_WARN_STREAM(get_logger(), "Failed to check thread CPU affinity: " << strerror(errno) << ".");
}

// Create thread
trigger_time_publisher_ = create_publisher<builtin_interfaces::msg::Time>("trigger_time", 1000);
trigger_thread_ = std::make_unique<std::thread>(&SensorTrigger::run, this);

// Set thread priority
sched_param sch;
int policy;
pthread_getschedparam(trigger_thread_->native_handle(), &policy, &sch);
sch.sched_priority = 30;
sch.sched_priority = 80;
if (pthread_setschedparam(trigger_thread_->native_handle(), SCHED_FIFO, &sch)) {
RCLCPP_WARN_STREAM(
get_logger(), "Failed to set schedule parameters: " << strerror(errno) << ".");
RCLCPP_WARN_STREAM(get_logger(), "Failed to set schedule parameters: " << strerror(errno) << ".");
}
}

Expand Down Expand Up @@ -130,7 +129,7 @@
while (now_nsec > target_nsec) {
target_nsec = target_nsec + interval_nsec;
}
// FIX: what about very small phases and fast framerates giving a negative number?

Check warning on line 132 in src/sensor_trigger.cpp

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (framerates)
wait_nsec = target_nsec - now_nsec - 1e7;
} else {
target_nsec = start_nsec;
Expand Down
Loading