1.TX2 gpio图
2.sysfs gpio值如GPIO26,值为gpio388
cd /sys/class/gpio/
echo 388 > export #使能端口
cd gpio388
cat direction #方向
cat value #输出值
?
3.通过c++实现
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc,char** argv)
{
ifstream dirStream("/sys/devices/c2f0000.gpio/gpiochip1/gpio/gpio338/value");
if(!dirStream)
{
cout<<"unable open"<<endl;
}
else
{
cout<<"open"<<endl;
}
int value_;
dirStream>>value_;
cout<<value_<<endl;
return 0;
}
4.ros执行
#include "ros/ros.h"
#include "std_msgs/Int8.h"
#include "sstream"
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc,char** argv)
{
ros::init(argc,argv,"gpio_ss");
ros::NodeHandle n;
ros::Publisher pub=n.advertise<std_msgs::Int8>("gpio_ss",100);
ros::Rate loop_rate(1);
std_msgs::Int8 msg;
int ss=0;
while(ros::ok())
{
ifstream dirStream("/sys/devices/c2f0000.gpio/gpiochip1/gpio/gpio338/value");
if(!dirStream)
{
cout<<"unable open"<<endl;
}
else
{
cout<<"open"<<endl;
}
dirStream>>ss;
msg.data=ss;
cout<<ss<<endl;
pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
|