# Simulating Manual Control using Mavros

**URL:** <https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745>\
**Category:** Blue Robotics Software\
**Tags:** sitl, simulate\
**Created:** [November 16, 2017, 6:27am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745 "2017-11-16T06:27:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![MavNav](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MavNav](https://discuss.bluerobotics.com/u/MavNav)\
**Post date:** [November 16, 2017, 6:27am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/1 "2017-11-16T06:27:26Z")

</div>

Hello,  
Let me start off by saying im a rookie at this pixhawk and mavros stuff. I am using Ardusub V3.5.1.  
My ultimate goal here is to make the pixhawk move my motors in any of the axes, X, Y and Z. Im running Ubuntu Mate on an ARMv7 chip. (ODroid XU3)  
Note that i am not using any localisation techniques. I simply want to command a movement in a certain direction.  
I have tried publishing to “/mavros/setpoint\_velocity/cmd\_vel” with no results. Of course, i armed it beforehand with “rosrun mavros mavsafety arm”

Here is the code i got online to publish cmd\_vel:

#include \<ros/ros.h\>  
#include \<std\_msgs/String.h\>  
#include \<stdio.h\>  
#include “geometry\_msgs/TwistStamped.h”  
#include “geometry\_msgs/Vector3Stamped.h”  
int M = 0;  
int L = 0;

int main(int argc, char \*\*argv)  
{  
geometry\_msgs::TwistStamped msg;  
ros::init(argc, argv, “move\_pix”);  
ros::NodeHandle nh;

ros::Publisher velocity\_message = nh.advertise\<geometry\_msgs::TwistStamped\>(“/mavros/setpoint\_velocity/cmd\_vel”,100);  
ros::Rate loop\_rate(10);

while(ros::ok()){  
msg.header.stamp = ros::Time::now();  
msg.header.seq=1;

```
   msg.twist.linear.x = 1;
   msg.twist.linear.y = 1;
   msg.twist.linear.z = 1;
   msg.twist.angular.x = 0;
   msg.twist.angular.y = 0;
   msg.twist.angular.z = 0;

   velocity_message.publish(msg);
   ros::spinOnce();
   loop_rate.sleep();
   M++;
   L++;

```

}  
return 0;  
}

Can someone advise on how i should go about achieving my goal? Thanks a bunch 🙂

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [November 16, 2017, 11:00am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/2 "2017-11-16T11:00:51Z")

</div>

Hi @MavNav,

I’ll itemize each step to make sure that everything is correct 🙂  
Probably will work with the real ROV, but I’ll write a simple guide to you to test with [SITL](http://ardupilot.org/dev/docs/sitl-simulator-software-in-the-loop.html).

- Start SITL
  - `cd ardupilot/ArduSub`
  - `sim_vehicle.py -j4`

- Connect mavros with SITL
  - `roslaunch mavros apm.launch fcu_url:=udp://0.0.0.0:14550@`

- Arm the ROV and put it on guided mode.
  - `rosrun mavros mavsafety arm`
  - `rosrun mavros mavsys mode -c GUIDED`
    - It’ll appear `Mode changed.`

Now, we should have everything prepared to send linear and angular messages.  
To make sure that everything is correct, we can subscribe in odom to see the drone position.

- `rostopic echo /mavros/local_position/odom/pose`

```auto
pose: 
  position: 
    x: -15.353191375732417
    y: -2.969302654266354
    z: -39.34264373779297
  orientation: 
    x: 0.0005757744895501046
    y: 0.0023029090765363785
    z: -0.4099183091346866
    w: -0.9121191506210589

```

Now, we can send a linear and angular reference with rospub.

- `rostopic pub -r 10 /mavros/setpoint_velocity/cmd_vel geometry_msgs/TwistStamped "{header: auto, twist: {linear: {x: 10.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}}"`

And with this, you’ll [see the x go up](https://asciinema.org/a/TsR2jxvxLy4JYlcSpwdXjLsEk).

---

<div class="post-metadata">

**Author:** ![MavNav](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MavNav](https://discuss.bluerobotics.com/u/MavNav)\
**Post date:** [November 16, 2017, 2:09pm UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/3 "2017-11-16T14:09:48Z")

</div>

Hey! Thanks for replying.  
I do have a real ROV on hand to test with. If so where do i start off? Also another thing, I’m using an Odroid XU3 as my companion computer connected to the Pixhawk using USB so i’d presume no need for the URL IP thingy?

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [November 16, 2017, 2:19pm UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/4 "2017-11-16T14:19:28Z")

</div>

Are you using the /dev/ttyACM0 right ? that’s the default communication device of mavros, no need to set the ip address.  
You should: Start mavros normally, arm the vehicle and set guided mode, like in [Arm the ROV and put it on guided mode.](http://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/2)

I recommend to test your code with SITL first, just to make sure that your part is running without problems.

Odroid XU3 is a powerful computer, any special reason for using it ?

---

<div class="post-metadata">

**Author:** ![MavNav](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MavNav](https://discuss.bluerobotics.com/u/MavNav)\
**Post date:** [November 17, 2017, 2:59am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/5 "2017-11-17T02:59:54Z")

</div>

Yes im using /dev/tty/ACM0. I start mavros using “roslaunch bluerov apm.launch” and it succesfully connects. However, when i try to change the mode to guided, it times out with “TImed Out!”.

I’ll try to work on SITL in the following days just as a proof of concept.

No real reason for the Odroid except i just happen to have one on hand and i eventually plan to make my AUV fully autonomous with smach.

---

<div class="post-metadata">

**Author:** ![MavNav](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MavNav](https://discuss.bluerobotics.com/u/MavNav)\
**Post date:** [November 23, 2017, 5:24am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/6 "2017-11-23T05:24:39Z")

</div>

UPDATE 23/11/17: I’ve managed to get it working in SITL and it does move. I can’t get it to change modes when i just connect to the pixhawk directly. Could you help?

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [November 23, 2017, 11:55am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/7 "2017-11-23T11:55:15Z")

</div>

@MavNav take a look in `/diagnostics` for problems or check the [mavproxy](http://ardupilot.github.io/MAVProxy/html/index.html) console, probably something is restricting the mode.

---

<div class="post-metadata">

**Author:** ![MavNav](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MavNav](https://discuss.bluerobotics.com/u/MavNav)\
**Post date:** [December 2, 2017, 11:44am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/8 "2017-12-02T11:44:22Z")

</div>

Hey sorry it took awhile. These are my results when i echo the /diagnostics topic:

## header: seq: 104 stamp: secs: 1512215007 nsecs: 470157004 frame\_id: ‘’ status:

```
level: 0
name: mavros: FCU connection
message: connected
hardware_id: /dev/pixhawk:115200
values: 
  - 
    key: Received packets:
    value: 36094
  - 
    key: Dropped packets:
    value: 0
  - 
    key: Buffer overruns:
    value: 0
  - 
    key: Parse errors:
    value: 0
  - 
    key: Rx sequence number:
    value: 25
  - 
    key: Tx sequence number:
    value: 157
  - 
    key: Rx total bytes:
    value: 1022089
  - 
    key: Tx total bytes:
    value: 2983
  - 
    key: Rx speed:
    value: 11458.000000
  - 
    key: Tx speed:
    value: 17.000000

```

- 
## level: 0 name: mavros: Heartbeat message: Normal hardware\_id: /dev/pixhawk:115200 values:

```
key: Heartbeats since startup
value: 133

```

  - key: Frequency (Hz)  
value: 1.037217
  - key: Vehicle type  
value: Submarine
  - key: Autopilot type  
value: ArduPilotMega / ArduCopter
  - key: Mode  
value: MANUAL
  - key: System status  
value: Critical

- 
## level: 0 name: mavros: System message: Normal hardware\_id: /dev/pixhawk:115200 values:

```
key: Sensor present
value: 0x0020FC07

```

  - key: Sensor enabled  
value: 0x00209C07
  - key: Sensor helth  
value: 0x0020FC07
  - key: 3D gyro  
value: Ok
  - key: 3D accelerometer  
value: Ok
  - key: 3D magnetometer  
value: Ok
  - key: 3D angular rate control  
value: Ok
  - key: attitude stabilization  
value: Ok
  - key: yaw position  
value: Ok
  - key: motor outputs / control  
value: Ok
  - key: AHRS subsystem health  
value: Ok
  - key: CPU Load (%)  
value: 32.6
  - key: Drop rate (%)  
value: 0.0
  - key: Errors comm  
value: 0
  - key: Errors count #1  
value: 0
  - key: Errors count #2  
value: 0
  - key: Errors count #3  
value: 0
  - key: Errors count #4  
value: 0

- 
## level: 1 name: mavros: Battery message: Low voltage hardware\_id: /dev/pixhawk:115200 values:

```
key: Voltage
value: 0.00

```

  - key: Current  
value: -0.0
  - key: Remaining  
value: -1.0

I have observed that the system status is “Critical”. Does it have any effect on the mode change command timing out?

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [December 2, 2017, 1:01pm UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/9 "2017-12-02T13:01:12Z")

</div>

Hi @MavNav, critical appears when one of the failsafes are enable: battery, ekf and others.  
First, you’ll need to disable then to arm, after that try to send some rc commands via `/mavros/rc/override`.

---

<div class="post-metadata">

**Author:** ![MavNav](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MavNav](https://discuss.bluerobotics.com/u/MavNav)\
**Post date:** [December 2, 2017, 1:24pm UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/10 "2017-12-02T13:24:01Z")

</div>

Ah alright. How do i disable them? And i was sending messages to setpoint\_velocity/cmd\_vel. So do i just change the topic name to mavros/rc/override?

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [December 2, 2017, 1:39pm UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/11 "2017-12-02T13:39:23Z")

</div>

You can disable then with QGC.

 ![Screenshot from 2017-12-02 11-24-16](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/1/1f6cfc9214725cf7cecaecf91b278d21a66ac8e6.png)  
(This parameters are only for test ! Do not use in a real case.)

Try first to control the rc output using the manual mode to test what you are doing.

---

<div class="post-metadata">

**Author:** ![MavNav](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MavNav](https://discuss.bluerobotics.com/u/MavNav)\
**Post date:** [December 2, 2017, 5:49pm UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/12 "2017-12-02T17:49:31Z")

</div>

I’ve disabled arming checks as seen here:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/7/7688c85de178ce507e7f3f657dcb6f2ac4b71d19.png)

I get this on the terminal running mavros when i run the mode change command:  
“[WARN] [1512236670.910592758]: CMD: Unexpected command 11, result 4”

Mode change to Guided still times out. I’m usng QGC on Windows to change parameters because i can’t get QGC to work in Linux.

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [December 4, 2017, 11:17am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/13 "2017-12-04T11:17:31Z")

</div>

Hi @MavNav,  
I have sent you a private message, probably this will be the fastest way to understand and solve your problem.

---

<div class="post-metadata">

**Author:** ![frozeneye](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/frozeneye/32/2927_2.png) [@frozeneye](https://discuss.bluerobotics.com/u/frozeneye)\
**Post date:** [August 22, 2018, 5:48am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/14 "2018-08-22T05:48:22Z")

</div>

Hi @patrickelectric  
I have encounter the same problem. would you like to sent me the fastest way to understand and solve the problem?🤣🤣🤣

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [December 4, 2017, 11:12am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/15 "2017-12-04T11:12:16Z")

</div>

Hi,

Are you running a new version of ArduSub ?  
Are you able to send RC values in _rc/override_ in MANUAL mode ?

My best regards,

---

<div class="post-metadata">

**Author:** ![MavNav](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MavNav](https://discuss.bluerobotics.com/u/MavNav)\
**Post date:** [December 5, 2017, 9:30am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/16 "2017-12-05T09:30:29Z")

</div>

Yes i am running the new version of Ardusub, 3.5.2.

I don’t know what to send to Rc/Override so perhaps you could advise?

On a side note, I thought i have to use guided mode to send cmd\_vel?

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [December 5, 2017, 10:32am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/17 "2017-12-05T10:32:32Z")

</div>

Ok, To send rc commands, try to use `rostopic pub -r 1 /mavros/rc/override mavros_msgs/OverrideRCIn '[1300, 1300, 1300, 1300, 0, 0, 0, 0]'`

Yes, you’ll need to change the mode before sending cmd\_vel, try first to do basic communication, like sending rc commands and etc. Just to make sure that everything will work.

---

<div class="post-metadata">

**Author:** ![MavNav](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MavNav](https://discuss.bluerobotics.com/u/MavNav)\
**Post date:** [December 6, 2017, 7:19am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/18 "2017-12-06T07:19:59Z")

</div>

Good news! I have managed to get it to run as per your steps, in Manual mode, publishing the rc override code.

How do i progress from here, to get to guided mode cmd vel?

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [December 6, 2017, 11:02am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/19 "2017-12-06T11:02:15Z")

</div>

Good !

Now, try first to set the guided and then arm the vehicle,  
maybe this can trick mavros to set the vehicle.

---

<div class="post-metadata">

**Author:** ![MavNav](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@MavNav](https://discuss.bluerobotics.com/u/MavNav)\
**Post date:** [December 7, 2017, 3:29am UTC](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745/20 "2017-12-07T03:29:06Z")

</div>

Minor Problem: I cannot control the speed of Main Out 2 on the pixhawk using that command, it just runs at full speed. I got it to output correctly with speed control with only 1 ESC plugged in. But when i plug 2 in it runs it on Max output.

Bigger Issue: Guided mode still times out when i try to initialise it both when running, and not.  
Mavros Terminal: [WARN] [1512617445.197459316]: CMD: Unexpected command 11, result 4

Command Terminal: ~$ rosrun mavros mavsys mode -c GUIDED  
Timed out!

[Next page](https://discuss.bluerobotics.com/t/simulating-manual-control-using-mavros/1745.md?page=2)
