This is only bug and feature tracker, please use it
to report bugs or request features.
Issue details
I have a couple of questions regarding the proper way to connect to my pixhawk (running on APM) correctly and also how to arm and send commands through an offboard computer. I am also unable to arm the pixhawk through mavros.
First, I am only able to occasionally connect with the pixhawk with mavros and get actual data on topics. My procedure for connecting is as follows:
Connect battery to drone and usb serial to my laptop (just temporary for testing)
run roscore in one tab
run mavros: roslaunch mavros apm.launch
After the above steps, I feel that I should be able to connect, but the various topics I can use (ex: /mavros/battery) do not output anything. When I see this, I try random things like using the RC to try to connect and arm the drone or starting up QGC, which successfully connects with the drone. After several of these random attempts and head-banging, I can connect.
Second, I am unable to arm the drone. I try running the following: rosrun mavros mavsafety arm, but this produces the error: Request failed. Check mavros logs. Of course then, I try to check the logs by first running roslaunch-logs, which gives me the path to a file that lists various log files. I vim into these, but do not see anything meaningful. I then run rqt_console to see real-time error messages, which is pretty helpful, but doesn't help me with arming the drone. Where can I check the mavros logs?
Also, when I am trying to arm the drone through a .cpp file rather than through terminal, I am following the offboard example. Here is my code below. Before taking a look, my understanding is that I publish desired values (ex: global positions) that I want the drone to move to. I also should publish some arm command to the arming topic, mavros/cmd/arming.
Please, any assistance is greatly appreciated. Please let me know if my post was bad as this is my first github issue post. This project is to have an Iris 3DR drone fly to some goal location and detect crop anomalies to send to mobile ground robots for further inspection :) Thank you!
#include <ros/ros.h>
#include <geometry_msgs/PoseStamped.h>
#include <geometry_msgs/TwistStamped.h>
#include <geometry_msgs/Vector3.h>
#include <mavros_msgs/CommandBool.h>
#include <mavros_msgs/SetMode.h>
#include <mavros_msgs/State.h>
#include <mavros_msgs/Thrust.h>
#include <sstream>
mavros_msgs::State current_state;
void state_cb(const mavros_msgs::State::ConstPtr& msg){
current_state = *msg;
}
int main(int argc, char **argv)
{
char *target_mode = "GUIDED";
ros::init(argc, argv, "offb_node");
ros::NodeHandle nh;
ros::Subscriber state_sub = nh.subscribe<mavros_msgs::State>
("mavros/state", 10, state_cb);
ros::Publisher local_pos_pub = nh.advertise<geometry_msgs::PoseStamped>
("mavros/setpoint_position/local", 10);
ros::ServiceClient arming_client = nh.serviceClient<mavros_msgs::CommandBool>
("mavros/cmd/arming");
ros::ServiceClient set_mode_client = nh.serviceClient<mavros_msgs::SetMode>
("mavros/set_mode");
ros::Publisher pub_att = nh.advertise<geometry_msgs::PoseStamped>("/mavros/setpoint_attitude/attitude", 100);
ros::Publisher pub_vel = nh.advertise<geometry_msgs::TwistStamped>("/mavros/setpoint_attitude/cmd_vel", 100);
ros::Publisher pub_thr = nh.advertise<mavros_msgs::Thrust>("/mavros/setpoint_attitude/thrust", 100);
//the setpoint publishing rate MUST be faster than 2Hz
ros::Rate rate(20.0);
// wait for FCU connection
while(ros::ok() && !current_state.connected){
ros::spinOnce();
rate.sleep();
// std::stringstream ss;
// ss << "[Not Connected]" << ", armed: " << armed << mode;
ROS_INFO("Not Connected!");
}
// Set goals
geometry_msgs::PoseStamped cmd_pose;
cmd_pose.header.frame_id = 1;
cmd_pose.pose.position.x = 0;
cmd_pose.pose.position.y = 0;
cmd_pose.pose.position.z = 2;
geometry_msgs::TwistStamped cmd_vel;
cmd_vel.header.frame_id = 1;
cmd_vel.twist.linear.x = 0.0;
cmd_vel.twist.linear.y = 0.0;
cmd_vel.twist.linear.z = 1.0;
mavros_msgs::Thrust cmd_thr;
cmd_thr.header.frame_id = 1;
// send a few setpoints before starting to make sure drone
// has an initial pose when offboard mode starts
ROS_INFO("Setting initial setpoints");
for(int i = 0; ros::ok() && i < 100; i++){
cmd_pose.header.stamp = ros::Time::now();
cmd_pose.header.seq = i;
local_pos_pub.publish(cmd_pose);
pub_att.publish(cmd_pose);
pub_vel.publish(cmd_vel);
pub_thr.publish(cmd_thr);
ros::spinOnce();
rate.sleep();
}
// now start offboard mode now that some initial pose has been set
mavros_msgs::SetMode offb_set_mode;
offb_set_mode.request.custom_mode = target_mode;
mavros_msgs::CommandBool arm_cmd;
arm_cmd.request.value = true;
ros::Time last_request = ros::Time::now();
// switch to offboard mode, and after 5 seconds arm the quad to allow
// it to fly
ROS_INFO("Starting Loop");
while(!ros::ok()){
ROS_INFO("Not OK!");
}
while(ros::ok()){
/*
if( current_state.mode == target_mode &&
(ros::Time::now() - last_request > ros::Duration(5.0))){
if( set_mode_client.call(offb_set_mode) &&
offb_set_mode.response.mode_sent){
if (current_state.mode != target_mode) ROS_INFO("WRONG MODE");
ROS_INFO("Offboard enabled");
}
last_request = ros::Time::now();
} else {
*/
if((ros::Time::now() - last_request > ros::Duration(5.0))){
if( arming_client.call(arm_cmd) &&
arm_cmd.response.success){
ROS_INFO("Vehicle armed");
}
last_request = ros::Time::now();
}
local_pos_pub.publish(cmd_pose);
ros::spinOnce();
rate.sleep();
}
return 0;
}
MAVROS version and platform
Mavros: 0.28.0
ROS: Kinetic
Ubuntu: 16.04
Autopilot type and version
[ ArduPilotMega ] ArduPilot
Version: not too sure at the moment, don't want to close down mavros connection to check QGC
Node logs
how do I get this? is this the /mavlink/from topic?
This is only bug and feature tracker, please use it to report bugs or request features.
Issue details
I have a couple of questions regarding the proper way to connect to my pixhawk (running on APM) correctly and also how to arm and send commands through an offboard computer. I am also unable to arm the pixhawk through mavros.
First, I am only able to occasionally connect with the pixhawk with mavros and get actual data on topics. My procedure for connecting is as follows:
roscore
in one tabroslaunch mavros apm.launch
After the above steps, I feel that I should be able to connect, but the various topics I can use (ex:
/mavros/battery
) do not output anything. When I see this, I try random things like using the RC to try to connect and arm the drone or starting up QGC, which successfully connects with the drone. After several of these random attempts and head-banging, I can connect.Second, I am unable to arm the drone. I try running the following:
rosrun mavros mavsafety arm
, but this produces the error:Request failed. Check mavros logs
. Of course then, I try to check the logs by first runningroslaunch-logs
, which gives me the path to a file that lists various log files. I vim into these, but do not see anything meaningful. I then runrqt_console
to see real-time error messages, which is pretty helpful, but doesn't help me with arming the drone. Where can I check the mavros logs?Also, when I am trying to arm the drone through a .cpp file rather than through terminal, I am following the offboard example. Here is my code below. Before taking a look, my understanding is that I publish desired values (ex: global positions) that I want the drone to move to. I also should publish some arm command to the arming topic,
mavros/cmd/arming
.Please, any assistance is greatly appreciated. Please let me know if my post was bad as this is my first github issue post. This project is to have an Iris 3DR drone fly to some goal location and detect crop anomalies to send to mobile ground robots for further inspection :) Thank you!
MAVROS version and platform
Mavros: 0.28.0 ROS: Kinetic Ubuntu: 16.04
Autopilot type and version
[ ArduPilotMega ] ArduPilot
Version: not too sure at the moment, don't want to close down mavros connection to check QGC
Node logs
Diagnostics
Check ID