Creating a Hold/Circle Mode

Good afternoon, I currently have completed my skid-steering based rover and everything works as advertised. My problem, or issue that I would like help solving is listed below as well as all of the components that I am using currently.

I want to be able to add in a sensor that talks to the cube orange. I would like to attach it to one of the GPIO pins and allow my sensor to output a “high” signal when a specific thing happens on the device. I can achieve this through adding in an arduino if necessary. However, the thing that I would like help on is I want my rover to pause it’s current mission, travel in a circle based on the time that the “high” signal was received, then continue onto the previous (original) mission that it had began on. Is this possible? If so, how do I implement this feature onto my robot. Thank you in advance.

I am using the following equipment:
F9P GPS System
4 Independent 24V motors
Cube Orange Autopilot System
RFD900+ Telemetry System
Mission Planner GCS

You will need to use a Lua script. This thread my offer some suggestions:

Thank you for your help on that topic. When I read through the thread, it should help me be able to get my sensor values to the cube orange itself, but how would I go about getting the rover to then pause the current mission, travel in a circle, then resume the mission afterwards? Thank you in advance and I look forward to seeing if we can solve this issue.

Hello,

There was a similar disussion here:

I guess that @Yuri_Rage could comment/help

1 Like

Lua and guided mode, see here:

2 Likes

Thank you for this information. As I read through it briefly, it appears as if this will work for what I need it for. Thank you again for all of your help and I will try to implement this in the next couple of days and see if this works for what I need it for. Thank you again.

2 Likes

I do have one more question on this topic. Now that I understand how to get the rover to do this action whenever I flip a switch on the remote control, is there any way that I can get the rover to do this automatically whenever I receive a signal?

For example, I have a machine that periodically will give me a “high” reading, while the default reading is always low. Whenever this machine sends the “high” signal, I would like the rover to trigger the circle feature that you have mentioned above.

I thought about implementing a portion of code that allows the lua script to read the state of a GPIO pin, or somehow signaling the cube in a different manner that the lua script can then monitor, and whenever the signal is switched to the high state, then the script would run and allow the rover to travel in the circle pattern like you have done above.

Thank you in advance and I look forward to seeing what you can help with on this topic.

“Button” in this context is really just GPIO polling:

1 Like

That should help me out a lot. Thank you again Yuri!

Before I get into this too much, this is my first time attempting to write/combine a Lua Script. This is what I have come up with so far attempting to combine both the acrobatics portion that you suggested along with the button pressing script as well. I have two questions

1: Does this scripting look like it will work? Or do you see any flaws right off the bat?
2: How do I go about activating this code once it is working? Would I just attach a signal wire to the GPIO pin I need activated?
2b: If number 2 is true, which GPIO pin would this be?

Thank you in advance and thank you for all of your help thus far.

Lua Scripting Trial 1.txt (1.6 KB)

No, this won’t work. First, the filename can contain no spaces and must end in .lua.

Second, it’s a functional disaster. The logic makes little sense, though I see what you’re aiming to accomplish. There’s never a command to exit GUIDED mode (if it ever gets entered), and the do_circle() function is placed extremely strangely.

There’s never an entry to the update() function, nor is it rescheduled, so the script will never execute a thing, regardless of the attempted logic.

I’m afraid I can’t just write this one for you, though most of the work is already done via the examples. Please reference the following links to answer your questions and improve your script.

ArduPilot Lua Scripting Basics - YouTube
ArduPilot Lua Demos (streamed live, 16 Apr 2022) - YouTube
Lua Scripts — Copter documentation (ardupilot.org)
Buttons — Copter documentation (ardupilot.org)

I will try to go through these demos and tutorials and see if I can improve the script. Thank you for your feedback and I will try to get a second draft to you sometime this afternoon or on Monday. Thank you again for all of your help

@Yuri_Rage I have made some updates to the original file that I have showed you. I believe that I followed the examples more closely. If you could go through this new file (excluding the file name issue that you mentioned earlier) and point me in the right direction, that would be greatly appreciated. Like I stated before, I have made many changes to the logic and tried to follow all of your suggestions from before. Thank you in advance and I hope to hear back from you soon. Thank you so much.

Trial2.txt (1.9 KB)

This isn’t really much better. The syntax errors are worse, including some newly introduced spelling errors, and the logic is unfollowable.

Use my example from the aerobatics thread almost verbatim.

Where I check for a switch to LOITER mode, you should instead poll button state.

I’m sorry that I can’t devote more time to your script right now other than offering harsh criticism. You really ought to watch those videos at least once if not several times.

Thank you for your advice. I will try to fix these errors and see if I can come up with a solution. Your harsh criticism is greatly appreciated as I am brand new to the Lua Scripting aspect.

Is it important that the vehicle drive in rather arbitrary circles while the input is held high? Could it just go to hold mode instead?

I would like the vehicle to drive in a circle by itself (preferably 10’) once it gets that high input signal, then return to its “auto” mode path afterwards. Hold mode would be acceptable to an extent, but the ultimate goal would be to get it to do a circle when it receives that high input signal

All of that is possible, including your desired radius (through some simple trigonometry). Start with my last suggestion and go from there.

Thank you. I will watch those videos and re-read some of those articles and try to get you revised section of coding afterwards. Thank you again.

@Yuri_Rage I have taken out the upper section of Trial2. I believe that this follows your suggested script pretty well, however I am not sure if this is the correct version of polling for that button like you had suggested. How does this look to you?

Trial3.txt (1.4 KB)