How to get rover to move via mavros ? Which topics to publish to ? What mode?

Hello,

There are mainly three options of making rover to move. First, you can control motors and servos connected to rc outputs directly. Have a look at our examples.

Second, you can manipulate waypoints and send it to APM or send another commands using mavcmd and mavwp.

For manipulating mission use mavwp with the following arguments:

{show,load,pull,dump,clear,setcur,goto}
show - Show waypoints
load - load waypoints from file
pull - pull waypoints from FCU
dump - dump waypoints to file
clear - clear waypoints on device
setcur - set current waypoints on device

To send commands use:
rosrun mavros mavcmd {argument}, where argument can be on of these:

{long,int,sethome,takeoff,land,takeoffcur,landcur,trigger_control}

long - Send any command (COMMAND_LONG)
int - Send any command (COMMAND_INT)
sethome - Request change home position
takeoff - Request takeoff
land - Request land
takeoffcur - Request takeoff from current GPS coordinates
landcur - Request land on current GPS coordinates
trigger_control - Control onboard camera trigerring system (PX4)

Alternatively, you can write and build your own ros publisher that will send Waypoint msgs to the topic mavros/mission/waypoints

Look at our tutorial to get familiar with the creating of your own packages, publishers and subscribers in ros. Then we’ll write our own publisher in C++.

  1. In the ‘src’ directory of your package create file named send_waypoint.cpp
  2. Past there the following code:

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "mavros_msgs/Waypoint.h"
#include <sstream>

int main(int argc, char **argv){
    ros::init(argc, argv, "talker");
    ros::NodeHandle n;
    ros::Publisher chatter_pub = n.advertise<mavros_msgs::Waypoint>("/mavros/mission/waypoints", 1000);
    ros::Rate loop_rate(10);
    int count = 0;
    while (ros::ok()){
        mavros_msgs::Waypoint waypoint;
        chatter_pub.publish(waypoint);
        ros::spinOnce();
        loop_rate.sleep();
        ++count;
    }
    return 0;
}
  1. Add the following lines to the CMakeLists.txt:
    add_executable(send_wp src/send_waypoint.cpp)
    target_link_libraries(send_wp ${catlin_LIBRARIES})

  2. Build everything with catkin_make

In your build directory you’ll see send_wp executable file. Run it and check with
rostopic echo mavros/mission/waypoints
if any waypoints are appeared. You can initialize waypoint object with your own data to get it published.

Hope it’ll help you :slight_smile:

1 Like