树莓派ROS环境下编写功能包报错

minecraftyusei 发布于 06/02 21:08
阅读 41
收藏 0

想要写一个在树莓派下运行的功能包,c++代码如下:

#include <ros/ros.h>
#include "tf/transform_datatypes.h"
#include <geometry_msgs/Vector3.h>
#include <geometry_msgs/Twist.h>
#include <geometry_msgs/PoseWithCovarianceStamped.h>
#include "geometry_msgs/Quaternion.h"
#include "tf/LinearMath/Matrix3x3.h"
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <fstream>
#include <sys/socket.h>
using namespace std;
#define bufsize 100

float xr=0,yr=0;
float tfvectorx=0.2;
float tfvectory=0;
double roll;
double pitch;
double yaw;
int servsock;
int strlenzy;
struct sockaddr_in servaddr;

struct sendstruct
{
float x;
float y;
float angle;
float vr;
float omegar;
};

sendstruct sendmsgzy;

void velcallback(const geometry_msgs::Twist &msg)
{
    sendmsgzy.vr=msg.linear.x;
    sendmsgzy.omegar=msg.angular.z;
}

void amclcallback(const geometry_msgs::PoseWithCovarianceStamped &msg)
{
    sendmsgzy.x=msg.pose.pose.position.x+tfvectorx;
    sendmsgzy.y=msg.pose.pose.position.y+tfvectory;

    tf::Quaternion quat;
    tf::quaternionMsgToTF(msg.pose.pose.orientation, quat);
    tf::Matrix3x3(quat).getRPY(roll, pitch, yaw);
    sendmsgzy.angle=yaw;
}

int main(int argc, char **argv)
{

  ros::init(argc, argv, "leader");
  ros::NodeHandle nh;

  ros::Subscriber amcl1sub=nh.subscribe("/amcl_pose",1,amclcallback);
  ros::Subscriber velsub=nh.subscribe("/cmd_vel",1,velcallback);

  ros::Rate loop_rate(10);
  while(ros::ok())
  {
  ros::spinOnce();

  servsock=socket(AF_INET,SOCK_STREAM,0);
  if(servsock==-1)
  {
    return(-1);
  }

  memset(&servaddr,0,sizeof(servaddr));
  servaddr.sin_family=AF_INET;
  servaddr.sin_addr.s_addr=inet_addr("100.64.245.46");
  servaddr.sin_port=htons(8080);

  if(connect(servsock,(struct sockaddr*)&servaddr,sizeof(servaddr))==-1)
  {
    return(-1);
  }

  strlenzy=write(servsock,(char *)&sendmsgzy,sizeof(sendstruct));
  if(strlenzy==-1)
  {
    close(servsock);
    return(-1);
  }
  loop_rate.sleep();
  }

return 0;
}


电脑虚拟机ubuntu16.04环境rosmake通过,然而在树莓派上报错,报错代码如下:

       distance(_InputIterator __first, _InputIterator __last)
       ^
  /usr/include/c++/5/bits/stl_iterator_base_funcs.h:114:5: note:   template argument deduction/substitution failed:
  /usr/include/c++/5/bits/stl_iterator_base_funcs.h: In substitution of ‘template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) [with _InputIterator = char*]’:
  /usr/include/c++/5/bits/basic_string.tcc:219:57:   required from ‘void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_InIterator, _InIterator, std::forward_iterator_tag) [with _FwdIterator = char*; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
  /usr/include/c++/5/bits/basic_string.h:195:23:   required from ‘void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct_aux(_InIterator, _InIterator, std::__false_type) [with _InIterator = char*; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
  /usr/include/c++/5/bits/basic_string.h:214:20:   required from ‘void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_InIterator, _InIterator) [with _InIterator = char*; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
  /usr/include/c++/5/bits/basic_string.h:400:21:   required from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
  /usr/include/boost/core/demangle.hpp:89:16:   required from here
  /usr/include/c++/5/bits/stl_iterator_base_funcs.h:114:5: error: no type named ‘difference_type’ in ‘struct std::iterator_traits<char*>’
  In file included from /usr/include/c++/5/bits/basic_string.h:40:0,
                   from /usr/include/c++/5/string:52,
                   from /opt/ros/kinetic/include/tf/transform_datatypes.h:35,
                   from /home/rikirobot/dev/rosbook/testleader/src/main.cpp:2:
  /usr/include/c++/5/ext/alloc_traits.h: In instantiation of ‘struct __gnu_cxx::__alloc_traits<std::allocator<boost::io::detail::format_item<char, std::char_traits<char>, std::allocator<char> > > >’:
  /usr/include/c++/5/bits/stl_vector.h:75:28:   required from ‘struct std::_Vector_base<boost::io::detail::format_item<char, std::char_traits<char>, std::allocator<char> >, std::allocator<boost::io::detail::format_item<char, std::char_traits<char>, std::allocator<char> > > >’
  /usr/include/c++/5/bits/stl_vector.h:214:11:   required from ‘class std::vector<boost::io::detail::format_item<char, std::char_traits<char>, std::allocator<char> >, std::allocator<boost::io::detail::format_item<char, std::char_traits<char>, std::allocator<char> > > >’
  /usr/include/boost/format/format_class.hpp:152:37:   required from ‘class boost::basic_format<char>’
  /usr/include/boost/math/policies/error_handling.hpp:133:35:   required from ‘void boost::math::policies::detail::raise_error(const char*, const char*, const T&) [with E = boost::math::rounding_error; T = double]’
  /usr/include/boost/math/policies/error_handling.hpp:478:47:   required from ‘TargetType boost::math::policies::detail::raise_rounding_error(const char*, const char*, const T&, const TargetType&, const boost::math::policies::rounding_error<(boost::math::policies::error_policy_type)0u>&) [with T = double; TargetType = double]’
  /usr/include/boost/math/policies/error_handling.hpp:644:39:   required from ‘TargetType boost::math::policies::raise_rounding_error(const char*, const char*, const T&, const TargetType&, const Policy&) [with T = double; TargetType = double; Policy = boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy>]’
  /usr/include/boost/math/special_functions/round.hpp:28:44:   required from ‘typename boost::math::tools::promote_args<T>::type boost::math::detail::round(const T&, const Policy&, mpl_::false_) [with T = double; Policy = boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy>; typename boost::math::tools::promote_args<T>::type = double; mpl_::false_ = mpl_::bool_<false>]’
  /usr/include/boost/math/special_functions/round.hpp:65:24:   required from ‘typename boost::math::tools::promote_args<T>::type boost::math::round(const T&, const Policy&) [with T = double; Policy = boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy>; typename boost::math::tools::promote_args<T>::type = double]’
  /usr/include/boost/math/special_functions/round.hpp:70:16:   required from ‘typename boost::math::tools::promote_args<T>::type boost::math::round(const T&) [with T = double; typename boost::math::tools::promote_args<T>::type = double]’
  /opt/ros/kinetic/include/ros/time.h:160:42:   required from ‘T& ros::TimeBase<T, D>::fromSec(double) [with T = ros::Time; D = ros::Duration]’
  /opt/ros/kinetic/include/ros/time.h:192:31:   required from here
  /usr/include/c++/5/ext/alloc_traits.h:178:53: error: no type named ‘difference_type’ in ‘class std::allocator<boost::io::detail::format_item<char, std::char_traits<char>, std::allocator<char> > >’
       typedef typename _Alloc::difference_type        difference_type;
                                                       ^
  CMakeFiles/main.dir/build.make:87: recipe for target 'CMakeFiles/main.dir/src/main.cpp.o' failed
  make[3]: *** [CMakeFiles/main.dir/src/main.cpp.o] Error 1
  make[3]: Leaving directory '/home/rikirobot/dev/rosbook/testleader/build'
  CMakeFiles/Makefile2:613: recipe for target 'CMakeFiles/main.dir/all' failed
  make[2]: *** [CMakeFiles/main.dir/all] Error 2
  make[2]: Leaving directory '/home/rikirobot/dev/rosbook/testleader/build'
  Makefile:127: recipe for target 'all' failed
  make[1]: *** [all] Error 2
  make[1]: Leaving directory '/home/rikirobot/dev/rosbook/testleader/build'
  /opt/ros/kinetic/share/mk/cmake.mk:7: recipe for target 'all' failed
完全超出知识水平,看不懂了。特此请教各位我这是写错了什么内容?它报的distance我好像完全没提到它啊?

 

加载中
返回顶部
顶部