ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
-1

I am a beginner to ROS. I am trying to write a code for PCAN using SocketCAN_interface headers. But i couldnt find the files. Plzz help me to loacte SocketCAN_interface library [closed]

asked 2016-02-18 07:52:26 -0600

Nivin gravatar image

updated 2017-04-03 21:46:25 -0600

ahendrix gravatar image

.

#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
#include "socketcan_interface/socketcan.h"
#include "socketcan_interface/threading.h"
#include "socketcan_interface/string.h"

void handleFrames(const can::Frame &f){
    // handle all frames
    LOG(can::tostring(f, true)); // lowercase: true
}
void handleFrame123(const can::Frame &f){
    // handle specific frame
    LOG("123? " << can::tostring(f, true)); // lowercase: true
}

int main(int argc, char **argv)
{
    can::ThreadedSocketCANInterface driver;
    if(!driver.init("can0", false)) return 1; // read own messages: false

    can::CommInterface::FrameListener::Ptr all_frames = driver.createMsgListener(handleFrames);
    can::CommInterface::FrameListener::Ptr one_frame = driver.createMsgListener(can::MsgHeader(0xFF32), handleFrame123); // handle only frames with CAN-ID 0x123

    ros::init(argc, argv, "data_raw");
    ros::NodeHandle n;
    ros::Publisher canbus_pub = n.advertise<std_msgs::String>("canbus", 1000);

    while (ros::ok())
    {
      std_msgs::String msg;
      std::stringstream ss;

      ss << all_frames;
      msg.data = ss.str();
      canbus_pub.publish(msg);

      //ROS_INFO("%s", msg.data.c_str());

      //ROS_INFO("%s", std::cout<<"all_frames is of type: "<<typeid(all_frames).name()<<std::endl);

      ros::spinOnce();
    }

  driver.shutdown();
  return 0;
}

This is the code i reffered

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2017-04-20 14:38:21.059349

Comments

This kind of issue is often an issue with build rules; particularly if you're using a library that's not installed by default. Please edit your question to include your build rules (CMakeLists.txt) and the exact error message.

ahendrix gravatar image ahendrix  ( 2017-04-03 21:48:51 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-04-03 18:42:32 -0600

rmck gravatar image

updated 2017-04-03 18:45:52 -0600

I'm not sure if you still need help with this but normally you would have to install the socketcan_interface package on your computer. You can do this by typing:

sudo apt-get install ros-[your_distribution]-socketcan-interface

So in my case, I would type:

sudo apt-get install ros-indigo-socketcan-interface

Then you should be able to use the code above.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-02-18 07:52:26 -0600

Seen: 644 times

Last updated: Apr 03 '17