Switch and Relocate Missions 'on the fly' - Testers wanted!

I coded a lua script for selecting a mission out of an infinite number of missions on SD-card and relocate (translate+rotate) that mission to the current location of my vehicle by pressing a button on transmitter.

Here a flight path of the latest test:

You have a start (Mission#0) in the middle,
then two loiter waypoints NW (Mission#1),
then a horizontal eight NE (Mission#2),
then a triangle SE (Mission#3),
then a rectangle SW (Mission#4)
and in the end a landing (again Mission#0)

…and all is done by a single push-button on transmitter.

Three of that missions are situated in Europe, but it’s no problem to relocate them to Australia.

So my personal mostly used case is the horizontal eight that I defined at my home-airfield: I just place it against the wind when I’m looking for thermals when soaring or when I’m at the slope.

But there are surely many other use cases.

  • E.g. if you lost a plane or copter over a wheat field and you have to start a search by a camera-copter - just use an automatically created meander mission and place it where you suppose to find it.
  • Or use just translation without rotation to scan the ground of a lake:

It would be great if you could test the script and drop a comment here.

The missions (with extension .txt to allow the upload):
SRM_Mission#0.waypoints.txt (603 Bytes)
SRM_Mission#1.waypoints.txt (508 Bytes)
SRM_Mission#2.waypoints.txt (684 Bytes)
SRM_Mission#3.waypoints.txt (419 Bytes)
SRM_Mission#4.waypoints.txt (509 Bytes)

The script:
SRM_SwitchRelocateMission.lua (22.2 KB)

Attention:

If you get an error at start of script that looks like “nil-pointer… dirlist()”, you have to update your ArduPilot firmware to ‘latest’, because that lua bindings are relatively new.

For the documentation see next post (the SM_SwitchMission.lua is not yet in the current code - the PR is still pending):

3 Likes

SRM_SwitchRelocateMission.lua - ArduPilot Lua script

OVERVIEW:

That script is derived from SM_SwitchMission.lua in

and the examples in ardupilot/libraries/AP_Scripting/examples at master · ArduPilot/ardupilot · GitHub

That script is useful to select an existing mission on SD-card via RC-channel, relocate (translate/rotate) it and self-switch to mode-AUTO

The selection of the mission can be done by multi-position-switch or pushbutton.

The relocation is started by long-press of a pushbutton

The kind of relocation can be selected by a 3-pos-switch or directly via parameter setting

The amount of missions is theoretically unlimited.

This script is intended to be used at least with yaapu-script in transmitter, because all info and warning messages of the script you can receive herein. If you can accept not receiving any feedback, the usecase with a multi-position-switch for selection is possible also without yaapu-script. GitHub - yaapu/FrskyTelemetryScript: A LUA telemetry script and widget for the Horus X10(S),X12 and Taranis X9D+,X9E,QX7 and X-Lite radios using ArduPilot frsky passthru protocol

CAUTION: Use this script AT YOUR OWN RISK

GENERAL INFORMATION

  • For not to lose accidentially a mission in FC at start of the script, the Mission in FC is saved to one of five files SRM_Backup#x.waypoints in cyclic manner.
    The last used Backup# you can find in SRM_Count.txt.

  • Only Waypoints (MAV_CMD_NAV_WAYPOINT/ID:16) and Spline-Waypoints (MAV_CMD_NAV_SPLINE_WAYPOINT/ID:82) will be relocated.

  • The diverse MAV_CMD_NAV_LOITER_xyz commands (e.g. MAV_CMD_NAV_LOITER_UNLIM) with optional location-information will not be relocated. If you want to relocate that commands, just put a Waypoint at the location and use the LOITER_xyz without location as next command.

  • Waypoints after DO_LAND_START (MAV_CMD_DO_LAND_START/ID:189) will never be relocated.

  • The Mission will be rotated by the heading of the vehicle at the moment the Start-Button was pressed (relative to North). I.e. if the vehicles heading is East, the rotation will be 90° clockwise. So you should plan your Missions “North-orinted”.

  • The altitude of the relocated Waypoints will be adapted only positive. I.e. if the vehicle at relocation is higher than the first Waypoint in mission, all Waypoint elevations will be increased accordingly. If it’s lower, no adaption will take place.

  • To prevent from accidentially relocation at start, there is an adjustable safety-radius arround Home within no relocation will happen.

SUMMARY OF PARAMETERS:

  • SRM_POSITIONS – the selection-method and/or amount of switch-positions
    •   1 = pushbutton for cyclic selection
    • >1  = amount of switch-positions
    •   0 = script paused
  • SRM_RC_SELECT – the RCx_Option (300…307) for selecting the mission or 0 to use start-button defined in SRM_RC_START
  • SRM_RC_START – the selected RCx_Option (300…307) for pushbutton to start the relocation
  • SRM_RELOCATION – the selected RCx_Option (300…307) of 3-pos-switch for definition of the kind of relocation or
    directly via parameter:
    • 0 = no relocation
    • 1 = translation only
    • 2 = translation+rotation
  • SRM_NO_RELOC_M – no relocation of Mission within a radius of XX m around Homepoint
    • should be adapted according to vehicle (kind, size, power, agility, …)
    • recommended: Plane=50m, Copter+Heli=10…20m, others=5m

HOW THE SCRIPT WORKS:

Initialization:

  • find or add script-specific parameter-table SRM_
  • find correct subdirectory for scripting (SITL or SD-card)
  • read necessary parameters, set corresponding values and find corresponding RCx_OPTION-channels
  • backup mission on FC to file SRM_Backup#x.waypoints
  • count available and check sufficient number of missions
  • load via multi-switch selected Mission# or Mission#0 if selection by pushbutton (unrelocated) to FC

Running:

  • check SRM_RC_SELECT and preselect mission accordingly
  • check start-RC-pushbutton (long-press) and if activated:
    • get current location
    • get kind of relocation
    • relocate the first Waypoint(s.c.Basepoint) of the preselected mission to the current location and the other Waypoins relatively.
    • if selected, the Waypoints will be rotated around the Basepoint by the amount of heading of the vehicle (difference to North) at the moment you pushed the button
    • translate altitude and load Waypoints to FC
    • if no problem, set mode-AUTO

Special Cases:

  • If the Parameter MIS_RESTART is set to 0 (Resume Mission), a further translation is earliest possible after a started Mission is reset or finished completely.

HOW TO USE:

Preparation:

  • activate scripting on your FC as described here: Lua Scripts — Dev documentation
  • adapt SCR_HEAP_SIZE to e.g. 102400 to have sufficient memory available for the script
  • create the subdirectory ‘missions’ in the directory where the sripts are stored
  • load the Missions to that subdir:
    • Mission#0.waypoints
    • Mission#1.waypoints
    • Mission#2.waypoints
    • a.s.o.
      Hint: No gap in the mission-numbers allowed
  • select the RC-input-pushbutton you want to use as SRM_RC_START (300…307) and set parameter RCx_OPTION accordingly
  • select the RC-input-3-pos-switch you want to use as SRM_RELOCATION (300…307) and set parameter RCx_OPTION accordingly
    or set SRM_RELOCATION directly to 0=no relocation / 1=translation only / 2=translation+rotation

Options you have to select before relocation

  • Mission# (via pushbutton or multi-switch)
  • Kind of relocation (via 3-pos-switch or parameter SRM_RELOCATION)

Relocation

  • start as usual
  • switch to a none-AUTO mode e.g. FBWB in ArduPlane and move to where you want to relocate the Mission
  • push the selected SRM_RC_START button
  • mode-AUTO is selected automatically

Hint for experienced users:

It would be straightforward to use other sources (e.g. a poti on an RC-input) to generate the amount of rotation, but from my side it’s not intended to overload that script more than necessary.

3 Likes

Incredible job! I will try this script in a few days .

1 Like

Nice work Willi, thanks for your persistence and for sharing the results with the rest of us.

After long nasty wintertime the weather yesterday gave me the chance to check the last version of SRM-script in a real flight.
Especially the cooperation with Soaring I’m not able to test at home - but all’s working fine :grinning:

The horizontal eight is defined far away at our RC-airfield:

The whole flight:

A Triangle Mission:

A Horizontal Eight Mission:

A Horizontal Eight Mission with Soaring in a little better place:

1 Like

Nobody interested in that functionallity?

If yes, it would be great if you could give a feedback here.
If you have ideas to or problems with that script - just post it.

In the meantime I enhanced the convenience of the script, but I ask myself if it’s a waste of time to publish it here and update the documentation.

2 Likes

It’s not a waste of time. It’s great for others to see just what is possible. Thanks for sharing this!

1 Like

It is an excellent idea and implementation!! Gongrats. I’ve seen your post since day one, but had to read it carefully to understand and afterwards try it on a VTOL.

Users makers or moders usually don’t comment a post if it just works (thus the popularity of “issue with…” Posts), which might be misinterpreted by the author as non intriguing or waste of time.

Keep up the great work, it was very very useful for my work - I need to fly in huge 8 pattern on demand - and I suppose for others.

I will write a feedback once I test it.

Thanks,
D

1 Like

Thanks for your motivating posts to @Allister & @Dimitris_Stefanakis.
Without feedback, it’s not easy for me to have an idea of general usability of such a script - at first I developed it for my purposes.
So it seems to me, placing a hidden bug in the script will help in the future :wink:

2 Likes

Very good job.
It would be better ArduPilot to support local frames ( MAV_FRAME_LOCAL_NED, MAV_FRAME_LOCAL_ENU) natively in AUTO mode though :slight_smile:

1 Like

I’ve that in my personal code since years - especially for my many MATEK-F405-Wing FCs without scripting-ability.
But the developers decided not to pull it into the code because the FCs with only 1MB are more or less obsolete. They recommended to realize such things in lua.

Sorry but I am on the devs’ side on that.
Implementing waypoints with local frames in AUTO mode does not mean relocating the waypoints. The waypoints will be stored and used in AUTO mode w.r.t. origin.

@Mustafa_Gokce I’m also at the developers side. It’s a strategic decision not to overload the code and all that’s possible to be implemented in a script only to implement in a script. And for sure, relative/local frames would it make much easier to relocate a mission - but it’s a different thing.

2 Likes

Hi @Quaxwilly!
I have a question not about this script, but in general. GPS can be connected on some transmitters (I connected it to the radiomaster tx16s). Is it possible to take the coordinates of the transmitter and record it as a separate mission. That is, by running the script, I returned my model to a new place where I moved with the equipment.

Hi @McKey, there I have no experience and guess that’s a mixture of OTX-Script and AP-Script and has a bit of “following” like a swarm.
But it’s much off-topic. So it would be better to start a new thread with a corresponding headline, because I’m sure there are many guys that have experience in such things.

Maybe that’s a threat of interest for you (besides it’s not really living): OpenTX LUA Script to send back GPS Data for follow me?

2 Likes

Hi @Quaxwilly , thanks for the clarification
I created a topic, I don’t know how effective it will be.

Nobody interested in testing that script?
Or too lazy to write some lines? :wink: