Seeking help with reverse throttle in Ardurover

Hello everyone,

I was wondering if anyone here could help me understand how the MAV_CMD “DO_SET_REVERSE” works with Ardurover?

I am currently making a script ( by modifying the follow me code) that sends a rover to a guided wp, then tells it to return to another wp in reverse. It seems like I would be able to utilize the aforementioned command to tell my rover to go in reverse. However, my rover still seems to keep going forward even after using the command. My rover does support reverse in manual mode, and I am allowing the rover to reach a complete stop before telling it to go in reverse. I’ll copy the two lines of code I am using below:

“port.doCommand(MAV.sysid, MAV.compid, MAVLink.MAV_CMD.DO_SET_REVERSE, 1, 0, 0, 0, 0, 0, 0);

port.setGuidedModeWP(MAV.sysid, MAV.compid, ReturnWP, false)”

,where port and MAV are the currently selected comport and MAV, respectively. The rover does reach the waypoint, but only by going forward. Due to some potential obstacles in my application, I’d prefer the rover to reverse back out of the location.

After reading some previous posts, it seems that the support for reverse with Ardurover has improved over the past year, so if anyone has any recommendations, I’d very much appreciate it. I’m currently using Rover 3.3 and can upload a log if anyone thinks it might be helpful.

1 Like

Grayson,

Rover supports to the do-set-reverse as a mission command (i.e. used within Auto mode) but not within Guided which accepts more real-time commands using the COMMAND_LONG or COMMAND_INT mavlink message (which is what you’re using). It’s very possible to add so I’ve created an issue including some advice on what changes should be made.

I can’t immediately promise when I will get to this but there are other developers that could possibly take on the challenge (and I would help them with advice).

I see. Thank you for the informative response!

I think in the meantime, I will just try to program in a J-turn using RCoverride. I’m mainly just trying to avoid going any further forward in order to turn around.

Grayson,

RC-overrides will probably work but not in Guided mode. It might be better to try and use the SET_ATTITUDE_TARGET and SET_POSITION_TARGET_GLOBAL_INT messages which Guided mode can accept and using these will provide higher level controls.

I looked into the SET_ATTITUDE command earlier, but I wasn’t sure how I would be able to properly tell the rover to max turn since it only sends the turn rate (yaw rate).

Is that something I will just need to tune? I’m just concerned if I give it a yaw rate of 2 rad/s, that it will keep trying to torque my steering past it’s physical capabilities (~45 degrees each way). Ideally, I would just like to say reverse slowly at a yaw of 45 degrees to the right until a certain heading has been achieved.

Grayson,

The SERVOx_MIN/MAX parameters are obeyed so as long as those are set, it won’t physically stress the servos I think.

The ATC_MAX_RATE and TURN_MAX_G parameters allow setting limits on how fast the vehicle will rotate so even if a command is received through SET_ATTITUDE_TARGET with a high turn rate, the vehicle should just do the best it can.

The SET_ATTITUDE_TARGET also supports a target heading but you’ll have to provide the target as a quaternion. It’s possible to convert between euler and quaternions though. ArduPilot’s code to do this is in the AP_Math/quaternion class.

The tricky thing about the SET_ATTITUDE_TARGET message is getting the type_mask field correct.

Another message you could use is a COMMAND_LONG with a MAV_CMD_NAV_SET_YAW_SPEED in it. This allows setting a change in heading. (i.e. change target heading to be 10degrees clockwise).

Thanks again for your help with all this. I’ll go and test what I have written up tomorrow, but it looks promising. I am only ignoring the roll and pitch rate in the type_mask field since they have no real impact for my rover.

It does appear that I could potentially have my script generate a flight plan to execute in Auto mode now that I think of it. That way, the rover could reverse all the way back to the second WP instead of having to do a J-Turn.Would you recommend I follow the command structured detailed in the website below in order to generate and execute a mission in Auto mode? Or would you recommend a higher level function in MP that might simplify the process?

https://mavlink.io/en/protocol/mission.html

Grayson,

I’ve never seen that website actually… It looks like it could be correct at least in terms of the mavlink messages required to upload a message… so it might work.

Good news! I was able to get the J-Turn working with the set_attitude command. Thank you again for your help.

Out of curiosity, I am still trying to get reverse mode in Auto working. It seems that my ESC requires a pump brake before it can go in reverse. For this reason, it seems that I cannot simply just tell the rover to start going in reverse with DO_SET_REVERSE without some preliminary step. I still haven’t figured out an order of Auto commands that allow my rover to reverse.

Would you happen to know if anyone has already figured this out? I would presume it is a common problem with most ESC’s. I tried using many combinations of DO_SET_SERVO and CONDITION_DELAY in order to “pump to brake” to no avail.

My rover does go in reverse if I pump the brakes in Manual mode before sending it on its Auto path which proves that it could work given the right preliminary step(s).

1 Like

I wasn’t able to get reverse to work using purely Auto mode commands, but I did get it to work by having my script attempt the reverse Auto path for one second (to “pump the brake”), then hold for one second, then try the Auto path again (successfully).

Hi Grayson,

the need to delay at zero throttle is normally a configurable setting within the ESC. I’ve found (and fixed) the issue on a couple of my vehicles. There’s a short note on the wiki here about it but there are many different varieties of ESCs with different methods of changing the config. Sometimes it’s done with an ESC programmer, sometimes there’s a jump on the ESC… I suspect there are other ways to configure the ESCs as well.

@gmorph and I discussed adding some handling of this ESC configuration but at least from my personal point of view, the result would never be as good as just re-configuring the ESC or replacing the ESC with another that does handle the reversing smoothly.