Hi I am currently writing a ros2 wrapper for masterboard_sdk(link text). It initialises a constructor using an ethernet port access. Thus If This sdk was used in standalone c++ code, user have to run the executable with sudo permission. However since I am using ROS2 minimal publisher class . I cant run the node in sudo as the env variable changes , I get error stating that its not able access certain libraries related to ROS. How can I solve this issue ?
[INFO] [launch]: All log files can be found below /root/.ros/log/2021-02-12-17-20-57-003084-NHHYDl-00392-29555 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [imu_reader-1]: process started with pid [29558] [imu_reader-1] /home/shyamsrinivasan/ros2_tut/install/IMU_DEMO/lib/IMU_DEMO/imu_reader: error while loading shared libraries: liblibstatistics_collector.so: cannot open shared object file: No such file or directory [ERROR] [imu_reader-1]: process has died [pid 29558, exit code 127, cmd ‘sudo /home/shyamsrinivasan/ros2_tut/install/IMU_DEMO/lib/IMU_DEMO/imu_reader --ros-args’].
Below is my code
```
#include <chrono>
#include <functional>
#include <memory>
#include <string>
#include "master_board_sdk/master_board_interface.h"
#include "master_board_sdk/defines.h"
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "sensor_msgs/msg/imu.hpp"
#include <math.h>
#include <stdio.h>
#include <sys/stat.h>
#include <assert.h>
#include <unistd.h>
#define N_SLAVES_CONTROLED 6
using namespace std::chrono_literals;
#include <typeinfo>
/* This example creates a subclass of Node and uses std::bind() to register a
* member function as a callback from the timer. */
class MinimalPublisher : public rclcpp::Node
{
public:
MinimalPublisher()
: Node("minimal_publisher"), count_(0)
{ //std::string interface_name = "enp3s0";
//std::string &if_name = interface_name ;
MasterBoardInterface robot_if("enp3s0");
robot_if.Init();
for (int i = 0; i < N_SLAVES_CONTROLED; i++)
{
robot_if.motor_drivers[i].motor1->SetCurrentReference(0);
robot_if.motor_drivers[i].motor2->SetCurrentReference(0);
robot_if.motor_drivers[i].motor1->Enable();
robot_if.motor_drivers[i].motor2->Enable();
robot_if.motor_drivers[i].EnablePositionRolloverError();
robot_if.motor_drivers[i].SetTimeout(5);
robot_if.motor_drivers[i].Enable();
}
publisher_ = this->create_publisher<sensor_msgs::msg::Imu>("/imu", 10);
timer_ = this->create_wall_timer(
1ms, std::bind(&MinimalPublisher::timer_callback, this));
}
private:
void timer_callback()
{
auto message = sensor_msgs::msg::Imu();
//message.data = "Hello, world! " + std::to_string(count_++);
//RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", message.data.c_str());
publisher_->publish(message);
}
rclcpp::TimerBase::SharedPtr timer_;
rclcpp::Publisher<sensor_msgs::msg::Imu>::SharedPtr publisher_;
size_t count_;
};
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<MinimalPublisher>());
rclcpp::shutdown();
return 0;
}
```