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

Trouble with using roscpp and mavros api to integrate pixhawk with Jetson

asked 2015-02-10 16:14:02 -0600

the_reddevil gravatar image

Hi,

I'm trying to Integrate pixhawk with Nvidia Jetson TK1. I was able to use ROS/Mavros and communicate with pixhawk by ros commands. Now I'm trying to use roscpp and mavros C++ api to communicate with pixhawk by C++ development on Jetson. I was able to run hello world program by following this tutorial http://jbohren.com/articles/roscpp-he...

Now, I'm trying to use it and mavros api to send arming commands to pixhawk. I modified it this way and compiled the program.

// Include the ROS C++ APIs

#include <ros/ros.h>
#include <mavros/mavros.h>
#include <mavros/CommandBool.h>
#include <mavros/mavros_plugin.h>
#include <pluginlib/class_list_macros.h>
#include <iostream>
using namespace mavros;
using namespace mavplugin;

// Standard C++ entry point
int main(int argc, char** argv) {
  // Announce this program to the ROS master as a "node" called "hello_world_node"
  ros::init(argc, argv, "mavros");
  // Start the node resource managers (communication, time, etc)
  ros::start();
  // Broadcast a simple log message
  ROS_INFO_STREAM("Hello, world!");
  //Create Request and Response structures for Arming service
  CommandBool::Request arm_req;//=new CommandBool::Request<std::Allocator<void>>();
  arm_req.value=1;
  CommandBool::Response arm_res;//=new CommandBool::Response();
  //Send arming command to master node
  bool result=mavplugin::CommandPlugin::arming_cb(&arm_req, &arm_res);
  // Process ROS callbacks until receiving a SIGINT (ctrl-c)
  ros::spin();
  // Stop the node's resources
  ros::shutdown();
  // Exit tranquilly
  return 0;
}

I got the following error message after compiling this:

sample.cpp: In function ‘int main(int, char**)’:
sample.cpp:28:26: error: ‘mavplugin::CommandPlugin’ has not been declared
   bool result=mavplugin::CommandPlugin::arming_cb(&arm_req, &arm_res);

Can anyone please suggest me how to proceed? Thanks.

edit retag flag offensive close merge delete

Comments

Can you tell how to use ROS/Mavros and communicate with pixhawk by ros commands? Email:iwangcong@outlook.com Thx!

cong gravatar image cong  ( 2018-01-04 06:43:17 -0600 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2015-02-11 09:26:13 -0600

vooon gravatar image

You used wrong namespace.

mavplugin is for plugins only, do not include it in your nodes. Also you don't need pluginlib.

Second: ros::init(), "mavros" taken by mavros_node!

Third: you should use ros services! Calling plugin class methods completely wrong.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-02-10 16:14:02 -0600

Seen: 774 times

Last updated: Feb 11 '15