Ask Your Question
0

Can I use WiringPi on ROS indigo ?

asked 2015-11-16 23:22:25 -0500

Kazuki Kadonaka gravatar image

updated 2015-12-04 03:37:38 -0500

tfoote gravatar image

Please teach me how to use by ROS indigo.

I can use WiringPi. I can use this program.

#include < iostream >
#include < wiringPi.h >
#include < conio.h >

int main()
{
  if (wiringPiSetupGpio() == \-1) {
    std::cout << "cannot setup gpio." << std::endl;
    return 1;
  }

  pinMode(18, PWM_OUTPUT);
  pinMode(19, PWM_OUTPUT);
  pwmSetMode(PWM_MODE_MS);
  pwmSetClock(266);
  pwmSetRange(1024);
  pwmWrite(18,110);
  pwmWrite(19,105);

  while (1) {
    pwmWrite(18,110);
    if (kbhit() && getch() == 'w'){
      while(1){
      pwmWrite(18,117); //前進
      if(kbhit() && getch() == 'x') break;
       }
    }
    if (kbhit() && getch() == 's'){
      while(1){
      pwmWrite(18,100);//後退
      if(kbhit() && getch() == 'x') break;
       }
    }
    if (kbhit() && getch() == 'd'){
      pwmWrite(19,90);//右旋回
    }
    if (kbhit() && getch() == 'a'){
      pwmWrite(19,120);//左旋回
    }
    if (kbhit() && getch() == 'e'){
      pwmWrite(19,105); //直進
     }
    if (kbhit() && getch() == 'q'){ //停止
    pwmWrite(18,110);
    pwmWrite(19,105);
    break;
    }
  }
  pwmWrite(18,110);
  pwmWrite(19,105);
  return 0;
}

and I want to control. It is recieved joystick data to control GPIO.

edit retag flag offensive close merge delete

Comments

Hi, have you been able to get it working together?

wilsonz91 gravatar image wilsonz91  ( 2015-12-04 03:17:59 -0500 )edit

Thanks your comment.Now studying.

Kazuki Kadonaka gravatar image Kazuki Kadonaka  ( 2015-12-07 23:49:21 -0500 )edit

3 Answers

Sort by » oldest newest most voted
3

answered 2015-12-08 01:56:43 -0500

wilsonz91 gravatar image

I have manage to get wiringPi and ROS working together. First step, you need to include in the CMakeList.txt where to find the lirary, for me it was:

FIND_LIBRARY(WIRINGPI_LIBRARY wiringPi /home/odroid/wiringPi)

The first parameter WIRINGPI_LIBRARY is just a name you give it which you will then use to refer within CMakeList. Second parameter is the library name and third parameter is the location on your system.

To use it, It depends on whether you're working using Python or C++.

1) For C++, include the library in your code and it would be something like this:

#include “wiringPi.h”       //include the library

………

wiringPiSetup();            //library setup function
pinMode(11,OUTPUT);         //set pin GPX2.1 as output. Based on wiringPi
//GPIO library map 

………

digitalWrite(11,data);      //write data(binary) to pin

And then in your CMakeList.txt, add the following:

add_executable(slave src/slave.cpp)
target_link_libraries(slave ${CATKIN_LIBRARIES} ${WIRINGPI_LIBRARY}
add_dependencies(slave beginner_tutorials_generate_messages_cpp wiringPi)

2) For python, I THINK its simply including the library in your code (not tested)

edit flag offensive delete link more

Comments

Thanks,please check.

Kazuki Kadonaka gravatar image Kazuki Kadonaka  ( 2015-12-10 02:59:31 -0500 )edit

This was very helpful; but be sure to use the direct path to your wiringPi folder you cloned in the FIND_LIBRARY command in order for full functionality to actually work.

luc gravatar image luc  ( 2016-03-20 15:59:05 -0500 )edit

Hi, I followed your instruction and setup the wiringPi in my ROS node, but I encountered the issue that "wiringPiSetup: Must be root. (Did you forget sudo?)" I know that this is related to the root permission, how do you overcome this? Thanks in advance.

DKWatson gravatar image DKWatson  ( 2016-06-16 00:27:54 -0500 )edit

It's been a while since I used it but I'm guessing that happens when you try to run your code? If that's the case, then you have to execute your code as SU i.e. in the terminal have SU rights, source the ROS bash file then run your code. Let me know if it works.

wilsonz91 gravatar image wilsonz91  ( 2016-06-16 05:19:23 -0500 )edit

Yeah, when I did it, I had to do su root, enter my password, then it worked.

luc gravatar image luc  ( 2016-06-16 12:21:37 -0500 )edit

If you need any reference for using wiring_pi with ROS, you can check out my project here: https://github.com/lucbettaieb/origam...

luc gravatar image luc  ( 2016-06-16 12:23:28 -0500 )edit

Finally get it down! @wilsonz91, @luc, Thanks so much for replying me the comment. They really help. Thank you @luc for sharing your project code to me, thanks you a Tons!

DKWatson gravatar image DKWatson  ( 2016-06-16 14:52:41 -0500 )edit

BTW, to whom may concern, su root doesn't work for me. But sudo -i will just did the same job.

DKWatson gravatar image DKWatson  ( 2016-06-16 15:16:48 -0500 )edit
0

answered 2015-12-10 03:00:46 -0500

Kazuki Kadonaka gravatar image

updated 2015-12-10 03:45:57 -0500

gvdhoorn gravatar image

Please check

#include <ros/ros.h>
#include <sensor_msgs/Joy.h>
#include <geometry_msgs/Twist.h>
#include <wiringPi.h> 


class JoyTwist
{
public:
  JoyTwist()
  {
    ros::NodeHandle node;
    joy_sub_ = node.subscribe("joy", 1, &JoyTwist::joyCallback, this);
  }

  void joyCallback(const sensor_msgs::Joy &joy_msg)
  {
    wiringPiSetup(); 
    pinMode(18,OUTPUT); 
    pinMode(19,OUTPUT);
    if (joy_msg.buttons[0] == 1)
    {
      digitalWrite(18, 110 + joy_msg.axes[1] * 10);
      digitalWrite(19, 105 + joy_msg.axes[0] * 15);         
    }
  }
private:
  ros::Subscriber joy_sub_;
};

int main(int argc, char **argv) {
  ros::init(argc, argv, "joy_twist");
  JoyTwist joy_twist;
  ros::spin();
}
edit flag offensive delete link more
-1

answered 2015-12-05 04:19:26 -0500

Look at the tutorials at http://wiki.ros.org/ROS/Tutorials

They show you how to set up a workspace to create ROS compatible code, and then publish or subscribe to messages in ROS. You would need to incorporate the code for subscribing into your code for wiringPi, assuming you want to control the pins based on messages received from a ROS topic

edit flag offensive delete link more

Comments

Thanks your comment.Now studying.

Kazuki Kadonaka gravatar image Kazuki Kadonaka  ( 2015-12-07 23:49:43 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-11-16 23:22:25 -0500

Seen: 3,842 times

Last updated: Dec 10 '15