C++ 没有用于调用 `LogBlock<CrazyflieROS::logMotor>` 的匹配函数
C++ no matching function for call to `LogBlock<CrazyflieROS::logMotor>`
我正在尝试修改 already existing package of ROS,在 crazyflie_driver 文件夹中添加和删除一些内容。我正在使用 catkin_make
进行编译,并且我有 ROS Kinetic 16.04。
我实际修改 crazyflie_server C++ 脚本的部分是:
私人的:
结构 logImu {
浮动acc_x;
浮动acc_y;
浮动acc_z;
浮动gyro_x;
浮动gyro_y;
浮动gyro_z;
} 属性((打包));
private:
struct logMotor {
int m1;
int m2;
int m3;
int m4;
} __attribute__((packed));
void onImuData(uint32_t time_in_ms, logImu* data) {
if (m_enable_logging_imu) {
sensor_msgs::Imu msg;
if (m_use_ros_time) {
msg.header.stamp = ros::Time::now();
} else {
msg.header.stamp = ros::Time(time_in_ms / 1000.0);
}
msg.header.frame_id = m_tf_prefix + "/base_link";
msg.orientation_covariance[0] = -1;
//new
msg.orientation.x = cos(data->gyro_z/2)*cos(data->gyro_y/2)*cos(data->gyro_x/2) + sin(data->gyro_z/2)*sin(data->gyro_y/2)*sin(data->gyro_x/2);
msg.orientation.y = sin(data->gyro_z/2)*cos(data->gyro_y/2)*cos(data->gyro_x/2) - cos(data->gyro_z/2)*sin(data->gyro_y/2)*sin(data->gyro_x/2);
msg.orientation.z = cos(data->gyro_z/2)*sin(data->gyro_y/2)*cos(data->gyro_x/2) + sin(data->gyro_z/2)*cos(data->gyro_y/2)*sin(data->gyro_x/2);
msg.orientation.w = cos(data->gyro_z/2)*cos(data->gyro_y/2)*sin(data->gyro_x/2) - sin(data->gyro_z/2)*sin(data->gyro_y/2)*cos(data->gyro_x/2);
//endnew
// measured in deg/s; need to convert to rad/s
msg.angular_velocity.x = degToRad(data->gyro_x);
msg.angular_velocity.y = degToRad(data->gyro_y);
msg.angular_velocity.z = degToRad(data->gyro_z);
// measured in mG; need to convert to m/s^2
msg.linear_acceleration.x = data->acc_x * 9.81;
msg.linear_acceleration.y = data->acc_y * 9.81;
msg.linear_acceleration.z = data->acc_z * 9.81;
m_pubImu.publish(msg);
}
}
void onMotorData(logMotor* data) {
std_msgs::Int32MultiArray array;
array.data.clear();
array.data.push_back(data->m1);
array.data.push_back(data->m2);
array.data.push_back(data->m3);
array.data.push_back(data->m4);
m_pubMotors.publish(array);
}
std::function<void(uint32_t, logImu*)> cb = std::bind(&CrazyflieROS::onImuData, this, std::placeholders::_1,std::placeholders::_2);
logBlockImu.reset(new LogBlock<logImu>(
&m_cf,{
{"acc", "x"},
{"acc", "y"},
{"acc", "z"},
{"gyro", "x"},
{"gyro", "y"},
{"gyro", "z"},
}, cb));
logBlockImu->start(1); // 10ms
std::function<void(logMotor*)> cbmotor = std::bind(&CrazyflieROS::**onMotorData**, this, std::placeholders::_1);
logBlockMotor.reset(new LogBlock<logMotor>(
&m_cf,{
{"motor", "m1"},
{"motor", "m2"},
{"motor", "m3"},
{"motor", "m4"},
}, cbmotor));
logBlockMotor->start(1); // 10ms
}
我的问题是,当我尝试使用这部分代码进行编译时:
>logBlockMotor.reset(new LogBlock<logMotor>(
&m_cf,{
{"motor", "m1"},
{"motor", "m2"},
{"motor", "m3"},
{"motor", "m4"},
}, cbmotor));
它给了我一个不匹配的函数来调用 LogBlock<CrazyflieROS::logMotor>
/home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_driver/src/crazyflie_server.cpp: In member function ‘void CrazyflieROS::run()’:
/home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_driver/src/crazyflie_server.cpp:530:9: error: no matching function for call to ‘LogBlock<CrazyflieROS::logMotor>::LogBlock(Crazyflie*, <brace-enclosed initializer list>, std::function<void(unsigned int, CrazyflieROS::logImu*)>&)’
}, cb));
^
In file included from /home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_driver/src/crazyflie_server.cpp:50:0:
/home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_cpp/include/crazyflie_cpp/Crazyflie.h:462:3: note: candidate: LogBlock<T>::LogBlock(Crazyflie*, std::__cxx11::list<std::pair<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > >, std::function<void(unsigned int, T*)>&) [with T = CrazyflieROS::logMotor]
LogBlock(
^
/home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_cpp/include/crazyflie_cpp/Crazyflie.h:462:3: note: no known conversion for argument 3 from ‘std::function<void(unsigned int, CrazyflieROS::logImu*)>’ to ‘std::function<void(unsigned int, CrazyflieROS::logMotor*)>&’
/home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_cpp/include/crazyflie_cpp/Crazyflie.h:459:7: note: candidate: LogBlock<CrazyflieROS::logMotor>::LogBlock(const LogBlock<CrazyflieROS::logMotor>&)
class LogBlock
^
/home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_cpp/include/crazyflie_cpp/Crazyflie.h:459:7: note: candidate expects 1 argument, 3 provided
crazyflie_ros/crazyflie_driver/CMakeFiles/crazyflie_server.dir/build.make:62: recipe for target 'crazyflie_ros/crazyflie_driver/CMakeFiles/crazyflie_server.dir/src/crazyflie_server.cpp.o' failed
make[2]: *** [crazyflie_ros/crazyflie_driver/CMakeFiles/crazyflie_server.dir/src/crazyflie_server.cpp.o] Error 1
CMakeFiles/Makefile2:2995: recipe for target 'crazyflie_ros/crazyflie_driver/CMakeFiles/crazyflie_server.dir/all' failed
make[1]: *** [crazyflie_ros/crazyflie_driver/CMakeFiles/crazyflie_server.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j1 -l1" failed
这是 LogBlock.h 文件的一部分:
namespace crazyflie_driver
{
template <class ContainerAllocator>
struct LogBlock_
{
typedef LogBlock_<ContainerAllocator> Type;
LogBlock_()
: topic_name()
, frequency(0)
, variables() {
}
LogBlock_(const ContainerAllocator& _alloc)
: topic_name(_alloc)
, frequency(0)
, variables(_alloc) {
(void)_alloc;
}
typedef std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > _topic_name_type;
_topic_name_type topic_name;
typedef int16_t _frequency_type;
_frequency_type frequency;
typedef std::vector<std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > , typename ContainerAllocator::template rebind<std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > >::other > _variables_type;
_variables_type variables;
typedef boost::shared_ptr< ::crazyflie_driver::LogBlock_<ContainerAllocator> > Ptr;
typedef boost::shared_ptr< ::crazyflie_driver::LogBlock_<ContainerAllocator> const> ConstPtr;
}; // struct LogBlock_
我不明白我做错了什么,还因为如果我在代码中留下 onImuData 的东西,它会完美编译。一旦我添加了那部分代码,就会出现编译器错误。
谁能帮帮我?我也尝试查看 CMake.txt 文件,但它似乎包含目录并且没有任何错误:
cmake_minimum_required(VERSION 2.8.3)
project(crazyflie_driver)
find_package(catkin REQUIRED COMPONENTS
message_generation
std_msgs
tf
crazyflie_cpp
)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_service_files(
FILES
AddCrazyflie.srv
GoTo.srv
Land.srv
RemoveCrazyflie.srv
SetGroupMask.srv
StartTrajectory.srv
Stop.srv
Takeoff.srv
UpdateParams.srv
UploadTrajectory.srv
sendPacket.srv
)
add_message_files(
FILES
LogBlock.msg
GenericLogData.msg
FullState.msg
TrajectoryPolynomialPiece.msg
crtpPacket.msg
Hover.msg
Position.msg
)
## Generate added messages and services with any dependencies listed here
generate_messages(
DEPENDENCIES
std_msgs
geometry_msgs
)
catkin_package(
CATKIN_DEPENDS
message_runtime
std_msgs
tf
crazyflie_cpp
)
###########
## Build ##
###########
include_directories(
${catkin_INCLUDE_DIRS}
)
## Declare a cpp executable
add_executable(crazyflie_server
src/crazyflie_server.cpp
)
add_dependencies(crazyflie_server
crazyflie_driver_generate_messages_cpp
)
## Specify libraries to link a library or executable target against
target_link_libraries(crazyflie_server
${catkin_LIBRARIES}
)
## Declare a cpp executable
add_executable(crazyflie_add
src/crazyflie_add.cpp
)
add_dependencies(crazyflie_add
crazyflie_driver_generate_messages_cpp
)
target_link_libraries(crazyflie_add
${catkin_LIBRARIES}
)
提前致谢!
您正在创建
std::function<void(logMotor*)> cbmotor = ...
然后将其传递给期望
的构造函数
std::function<void(uint32_t, T*)>&
(其中 T
大概是 logMotor
)。这两种类型不兼容。这是我在你的来源中读到的内容。
另一方面,错误消息说
no known conversion for argument 3 from
‘std::function<void(unsigned int, CrazyflieROS::logImu*)>’
to
‘std::function<void(unsigned int, CrazyflieROS::logMotor*)>&’
这意味着您正在创建面向 logImu
的回调并试图将其传递给面向 logMotor
的参数。您显示的错误消息可能来自与您作为来源发布的文件不同的文件。
无论如何你都需要传递正确类型的回调。
有点不相关的说明:
LogBlock(
Crazyflie* cf,
std::list<std::pair<std::string, std::string> > variables,
std::function<void(uint32_t, T*)>& callback)
是您尝试使用的包中的错误。拥有非常量引用 std::function
参数然后立即将其复制到成员变量是没有意义的。这不必要地将构造函数限制为仅与非常量左值参数一起使用。例如,你可以做
std::function<void(uint32_t, logImu*)> cb = std::bind(...);
new LogBlock<logImu>(..., ..., cb)
但是你不能直接做
new LogBlock<logImu>(..., ..., std::bind (...))
构造函数应该有一个 const 引用参数,并且可以选择有一个带有右值引用参数的重载。
该函数还按值接受 std::list
,这也没有意义。
我正在尝试修改 already existing package of ROS,在 crazyflie_driver 文件夹中添加和删除一些内容。我正在使用 catkin_make
进行编译,并且我有 ROS Kinetic 16.04。
我实际修改 crazyflie_server C++ 脚本的部分是:
私人的:
结构 logImu {
浮动acc_x;
浮动acc_y;
浮动acc_z;
浮动gyro_x;
浮动gyro_y;
浮动gyro_z;
} 属性((打包));
private:
struct logMotor {
int m1;
int m2;
int m3;
int m4;
} __attribute__((packed));
void onImuData(uint32_t time_in_ms, logImu* data) {
if (m_enable_logging_imu) {
sensor_msgs::Imu msg;
if (m_use_ros_time) {
msg.header.stamp = ros::Time::now();
} else {
msg.header.stamp = ros::Time(time_in_ms / 1000.0);
}
msg.header.frame_id = m_tf_prefix + "/base_link";
msg.orientation_covariance[0] = -1;
//new
msg.orientation.x = cos(data->gyro_z/2)*cos(data->gyro_y/2)*cos(data->gyro_x/2) + sin(data->gyro_z/2)*sin(data->gyro_y/2)*sin(data->gyro_x/2);
msg.orientation.y = sin(data->gyro_z/2)*cos(data->gyro_y/2)*cos(data->gyro_x/2) - cos(data->gyro_z/2)*sin(data->gyro_y/2)*sin(data->gyro_x/2);
msg.orientation.z = cos(data->gyro_z/2)*sin(data->gyro_y/2)*cos(data->gyro_x/2) + sin(data->gyro_z/2)*cos(data->gyro_y/2)*sin(data->gyro_x/2);
msg.orientation.w = cos(data->gyro_z/2)*cos(data->gyro_y/2)*sin(data->gyro_x/2) - sin(data->gyro_z/2)*sin(data->gyro_y/2)*cos(data->gyro_x/2);
//endnew
// measured in deg/s; need to convert to rad/s
msg.angular_velocity.x = degToRad(data->gyro_x);
msg.angular_velocity.y = degToRad(data->gyro_y);
msg.angular_velocity.z = degToRad(data->gyro_z);
// measured in mG; need to convert to m/s^2
msg.linear_acceleration.x = data->acc_x * 9.81;
msg.linear_acceleration.y = data->acc_y * 9.81;
msg.linear_acceleration.z = data->acc_z * 9.81;
m_pubImu.publish(msg);
}
}
void onMotorData(logMotor* data) {
std_msgs::Int32MultiArray array;
array.data.clear();
array.data.push_back(data->m1);
array.data.push_back(data->m2);
array.data.push_back(data->m3);
array.data.push_back(data->m4);
m_pubMotors.publish(array);
}
std::function<void(uint32_t, logImu*)> cb = std::bind(&CrazyflieROS::onImuData, this, std::placeholders::_1,std::placeholders::_2);
logBlockImu.reset(new LogBlock<logImu>(
&m_cf,{
{"acc", "x"},
{"acc", "y"},
{"acc", "z"},
{"gyro", "x"},
{"gyro", "y"},
{"gyro", "z"},
}, cb));
logBlockImu->start(1); // 10ms
std::function<void(logMotor*)> cbmotor = std::bind(&CrazyflieROS::**onMotorData**, this, std::placeholders::_1);
logBlockMotor.reset(new LogBlock<logMotor>(
&m_cf,{
{"motor", "m1"},
{"motor", "m2"},
{"motor", "m3"},
{"motor", "m4"},
}, cbmotor));
logBlockMotor->start(1); // 10ms
}
我的问题是,当我尝试使用这部分代码进行编译时:
>logBlockMotor.reset(new LogBlock<logMotor>(
&m_cf,{
{"motor", "m1"},
{"motor", "m2"},
{"motor", "m3"},
{"motor", "m4"},
}, cbmotor));
它给了我一个不匹配的函数来调用 LogBlock<CrazyflieROS::logMotor>
/home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_driver/src/crazyflie_server.cpp: In member function ‘void CrazyflieROS::run()’:
/home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_driver/src/crazyflie_server.cpp:530:9: error: no matching function for call to ‘LogBlock<CrazyflieROS::logMotor>::LogBlock(Crazyflie*, <brace-enclosed initializer list>, std::function<void(unsigned int, CrazyflieROS::logImu*)>&)’
}, cb));
^
In file included from /home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_driver/src/crazyflie_server.cpp:50:0:
/home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_cpp/include/crazyflie_cpp/Crazyflie.h:462:3: note: candidate: LogBlock<T>::LogBlock(Crazyflie*, std::__cxx11::list<std::pair<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > >, std::function<void(unsigned int, T*)>&) [with T = CrazyflieROS::logMotor]
LogBlock(
^
/home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_cpp/include/crazyflie_cpp/Crazyflie.h:462:3: note: no known conversion for argument 3 from ‘std::function<void(unsigned int, CrazyflieROS::logImu*)>’ to ‘std::function<void(unsigned int, CrazyflieROS::logMotor*)>&’
/home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_cpp/include/crazyflie_cpp/Crazyflie.h:459:7: note: candidate: LogBlock<CrazyflieROS::logMotor>::LogBlock(const LogBlock<CrazyflieROS::logMotor>&)
class LogBlock
^
/home/bitcraze/catkin_ws/src/crazyflie_ros/crazyflie_cpp/include/crazyflie_cpp/Crazyflie.h:459:7: note: candidate expects 1 argument, 3 provided
crazyflie_ros/crazyflie_driver/CMakeFiles/crazyflie_server.dir/build.make:62: recipe for target 'crazyflie_ros/crazyflie_driver/CMakeFiles/crazyflie_server.dir/src/crazyflie_server.cpp.o' failed
make[2]: *** [crazyflie_ros/crazyflie_driver/CMakeFiles/crazyflie_server.dir/src/crazyflie_server.cpp.o] Error 1
CMakeFiles/Makefile2:2995: recipe for target 'crazyflie_ros/crazyflie_driver/CMakeFiles/crazyflie_server.dir/all' failed
make[1]: *** [crazyflie_ros/crazyflie_driver/CMakeFiles/crazyflie_server.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j1 -l1" failed
这是 LogBlock.h 文件的一部分:
namespace crazyflie_driver
{
template <class ContainerAllocator>
struct LogBlock_
{
typedef LogBlock_<ContainerAllocator> Type;
LogBlock_()
: topic_name()
, frequency(0)
, variables() {
}
LogBlock_(const ContainerAllocator& _alloc)
: topic_name(_alloc)
, frequency(0)
, variables(_alloc) {
(void)_alloc;
}
typedef std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > _topic_name_type;
_topic_name_type topic_name;
typedef int16_t _frequency_type;
_frequency_type frequency;
typedef std::vector<std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > , typename ContainerAllocator::template rebind<std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > >::other > _variables_type;
_variables_type variables;
typedef boost::shared_ptr< ::crazyflie_driver::LogBlock_<ContainerAllocator> > Ptr;
typedef boost::shared_ptr< ::crazyflie_driver::LogBlock_<ContainerAllocator> const> ConstPtr;
}; // struct LogBlock_
我不明白我做错了什么,还因为如果我在代码中留下 onImuData 的东西,它会完美编译。一旦我添加了那部分代码,就会出现编译器错误。
谁能帮帮我?我也尝试查看 CMake.txt 文件,但它似乎包含目录并且没有任何错误:
cmake_minimum_required(VERSION 2.8.3)
project(crazyflie_driver)
find_package(catkin REQUIRED COMPONENTS
message_generation
std_msgs
tf
crazyflie_cpp
)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_service_files(
FILES
AddCrazyflie.srv
GoTo.srv
Land.srv
RemoveCrazyflie.srv
SetGroupMask.srv
StartTrajectory.srv
Stop.srv
Takeoff.srv
UpdateParams.srv
UploadTrajectory.srv
sendPacket.srv
)
add_message_files(
FILES
LogBlock.msg
GenericLogData.msg
FullState.msg
TrajectoryPolynomialPiece.msg
crtpPacket.msg
Hover.msg
Position.msg
)
## Generate added messages and services with any dependencies listed here
generate_messages(
DEPENDENCIES
std_msgs
geometry_msgs
)
catkin_package(
CATKIN_DEPENDS
message_runtime
std_msgs
tf
crazyflie_cpp
)
###########
## Build ##
###########
include_directories(
${catkin_INCLUDE_DIRS}
)
## Declare a cpp executable
add_executable(crazyflie_server
src/crazyflie_server.cpp
)
add_dependencies(crazyflie_server
crazyflie_driver_generate_messages_cpp
)
## Specify libraries to link a library or executable target against
target_link_libraries(crazyflie_server
${catkin_LIBRARIES}
)
## Declare a cpp executable
add_executable(crazyflie_add
src/crazyflie_add.cpp
)
add_dependencies(crazyflie_add
crazyflie_driver_generate_messages_cpp
)
target_link_libraries(crazyflie_add
${catkin_LIBRARIES}
)
提前致谢!
您正在创建
std::function<void(logMotor*)> cbmotor = ...
然后将其传递给期望
的构造函数std::function<void(uint32_t, T*)>&
(其中 T
大概是 logMotor
)。这两种类型不兼容。这是我在你的来源中读到的内容。
另一方面,错误消息说
no known conversion for argument 3 from
‘std::function<void(unsigned int, CrazyflieROS::logImu*)>’
to‘std::function<void(unsigned int, CrazyflieROS::logMotor*)>&’
这意味着您正在创建面向 logImu
的回调并试图将其传递给面向 logMotor
的参数。您显示的错误消息可能来自与您作为来源发布的文件不同的文件。
无论如何你都需要传递正确类型的回调。
有点不相关的说明:
LogBlock(
Crazyflie* cf,
std::list<std::pair<std::string, std::string> > variables,
std::function<void(uint32_t, T*)>& callback)
是您尝试使用的包中的错误。拥有非常量引用 std::function
参数然后立即将其复制到成员变量是没有意义的。这不必要地将构造函数限制为仅与非常量左值参数一起使用。例如,你可以做
std::function<void(uint32_t, logImu*)> cb = std::bind(...);
new LogBlock<logImu>(..., ..., cb)
但是你不能直接做
new LogBlock<logImu>(..., ..., std::bind (...))
构造函数应该有一个 const 引用参数,并且可以选择有一个带有右值引用参数的重载。
该函数还按值接受 std::list
,这也没有意义。