Ambiguous behavior in 'GUIDED' mode

Hai All,

I am using a Pixhawk 4 which runs the ArduRover firmware (ArduRover V4.2.3) for my Autonomous Surface Vehicle (ASV) which has a two thruster configuration. When I am switching the flight mode from ‘MANUAL’ to ‘GUIDED’ the motors starts running at a high gain continously until I disarm the vehicle. I have cleared all the waypoints from my flightcontrller before switching to the ‘GUIDED’ mode but still the issue continues. Has anyone faced similar issues or know the reason why it is happening?

Ultimately I want to control my robot by publishing velocity to ‘/mavros/setpoint_velocity/cmd_vel’ MAVROS topic.

Please help.

what about steering mode? are you sure the outputs are setup correctly?

1 Like

Maybe a log file would be helpful.
Anyway, as far as I know Guided requires continuous Mavlink commands, if not it goes to a default mode that might be the reason for high motor gain.

1 Like

@dotanb7 I will share the log file. Can we change the default movement to something we want. In simulation when i am not publishing any velocity commands it shows the message ‘No commands recieved for 3 seconds’ and stops.

Hai @jeanbat

Do you mean ‘MANUAL’ mode? Yes everything is working as per the RC commands.

Switching to Guided manually is not needed if you want to use Mission Planner’s map to send a ‘go to here’ command.
If you want to use Guided with “advanced” control you can setup your tests with MavProxy, it’ll generate the messages you want pretty easily. A companion computer is not needed for that initial setup.

1 Like

Hai @dotanb7

I am using MAVROS to send velocity commands to the flight controller so a company computer is required to run ROS. Does the default mode you talked about asssociated with the home position/launch point? It stops when I am not giving any commands for 1-2 minuntes and then starts running at a particular gain.

I’m not sure about the default “mode” in ArduRover, it’s not mentioned in the documentation, and I am mostly familiar with Copters.
You can try to figure things by reading the code itself.

Try sharing the commands you are sending to the Rover from MAVROS.
Also, again, log file might help.
Generally - the more (relevant) information you share it’ll be easier to help you.

1 Like

@dotanb7 I am publishing velocity commands to the following MAVROS topic /mavros/setpoint_velocity/cmd_vel, msgtype: geometry_msgs/TwistStamped in GUIDED mode. When I am not publishing any velocity commands for some time (20-30sec) after arming the vehicle the motors starts rotating on its own at a particular speed. One assumption is that it is trying ro return to its home position / launch point when no commands are recived but still not sure whether this will happen in GUIDED mode. All the waypoints are cleared before switching to GUIDED mode.

All these experiments are perfromed from the bench.

Log file from the following experiment: 2023-10-23 20-08-18.bin - Google Drive

Have a look at this code snippet from ardupilot/Rover/mode_guided.cpp

// stop vehicle if target not updated within 3 seconds
            if (have_attitude_target && (millis() - _des_att_time_ms) > 3000) {
                gcs().send_text(MAV_SEVERITY_WARNING, "target not received last 3secs, stopping");
                have_attitude_target = false;
            }
            if (have_attitude_target) {
                // run steering and throttle controllers
                [...]
            } else {
                // we have reached the destination so stay here
                if (rover.is_boat()) {
                    if (!start_loiter()) {
                        stop_vehicle();
                    }
                } else {
                    stop_vehicle();
                }
            }
            break;

If a timeout occurs vehicle will enter loiter mode or stop, depending on vehicle type.
This timeout should be 3 seconds and not 30…

Make sure your vehicle is able to stop or loiter properly (although it switches to Manual rather than loiter…)
Have a look at bool Mode::stop_vehicle() in ardupilot/Rover/mode.cpp

1 Like

@dotanb7 Thanks for this huge piece of information.
I will check exactly how much time it takes before the ambiguous behavior occurs, definitely not 3 seconds more than that.

bool Mode::stop_vehicle()
{
    // call throttle controller and convert output to -100 to +100 range
    bool stopped = false;
    float throttle_out;

    // if vehicle is balance bot, calculate throttle required for balancing
    if (rover.is_balancebot()) {
        throttle_out = 100.0f * attitude_control.get_throttle_out_speed(0, g2.motors.limit.throttle_lower, g2.motors.limit.throttle_upper, g.speed_cruise, g.throttle_cruise * 0.01f, rover.G_Dt);
        rover.balancebot_pitch_control(throttle_out);
    } else {
        throttle_out = 100.0f * attitude_control.get_throttle_out_stop(g2.motors.limit.throttle_lower, g2.motors.limit.throttle_upper, g.speed_cruise, g.throttle_cruise * 0.01f, rover.G_Dt, stopped);
    }

    // relax sails if present
    g2.motors.set_mainsail(100.0f);
    g2.motors.set_wingsail(0.0f);

    // send to motor
    g2.motors.set_throttle(throttle_out);

    // do not turn while slowing down
    float steering_out = 0.0;
    if (!stopped) {
        steering_out = attitude_control.get_steering_out_rate(0.0, g2.motors.limit.steer_left, g2.motors.limit.steer_right, rover.G_Dt);
    }
    g2.motors.set_steering(steering_out * 4500.0);

    // return true once stopped
    return stopped;
}

I had a look at stop_vehicle(). From the code I can see that the vehicle never stops if no commands are passed but keeps on sending some throttle and steering commands right? Please correct me if i am wrong .

stop_vehicle() is called repeatedly and I haven’t gone through the sub functions to tell if it actually stops the vehicle, but it’s possible that it’s not, but it does send some commands. You can dive into the attitude_control.get_throttle_out_stop() function and figure it out.

Anyways, the issue might be related to your MAVROS app, you can try sending commands via MissionPlanner or MavProxy to see if the vehicle behaves differently.

1 Like

Does that ASV work in auto mode and other modes where pilot input isn’t directly mapped to outputs?

1 Like

@dotanb7 Sure, I will also try that. The part I don’t understand is that when I am not sending any velocity commands the motors starts rotating only after 30 seconds while in the guided mode code it say it will switch after 3 seconds (confirmed with a stopwatch)

Hai @LupusTheCanine ,

It works perfectly in ‘AUTO’ mode where I can send the waypoints through MAVROS and the ASV executes the mission points correctly. Also I have used the ‘ACRO’ mode for tuning my PID controllers. These are the two modes I have used extensively other than ‘MANUAL’ nad ‘GUIDED’ modes.