ArduPilot / SITL_Models

Models of aircraft for SITL
82 stars 116 forks source link

Add model for Hexapod Copter #96

Closed srmainwaring closed 1 year ago

srmainwaring commented 1 year ago

This PR is for an experimental frame combining a hexapod and hexacopter.

hexapod_copter_hover

The frame is fully articulated. Each of the 6 legs has 3 joints, however only 16 are actuated. The middle two 'hip' joints are fixed in this example. The motor ordering and orientation is the same as a standard hexa X frame, however in this case the FRAME_CLASS 17 (Dynamic Scripting Matrix) and the motor mixing is set in the Lua script.

The legs have two positions - folded when disarmed, and unfolded when armed.

If the scripting control of the legs is disabled they may be moved using gz topic commands:

# move the mid right femur joint down from its initial position of -0.6 rad to -0.4 rad 
gz topic -t "/femur_mr_joint/cmd_pos" -m gz.msgs.Double -p "data: -0.4"

Dependencies

The hexapod copter requires 32 servo support and has upstream dependencies on these PRs:

Usage

Gazebo and the plugins should be installed as per the ArduPilot Gazebo Plugin instructions.

Update the GZ_SIM_RESOURCE_PATH to include these models:

export GZ_SIM_RESOURCE_PATH=$GZ_SIM_RESOURCE_PATH:\
$HOME/SITL_Models/Gazebo/models:\
$HOME/SITL_Models/Gazebo/worlds

Run Gazebo

gz sim -v4 -r hexapod_copter_runway.sdf

Run ArduPilot SITL

Copy the script $HOME/SITL_Models/Gazebo/scripts/hexapod_copter.lua to the SITL scripts directory, then start SITL:

sim_vehicle.py -D -v ArduCopter -f hexa --model JSON --add-param-file=$HOME/SITL_Models/Gazebo/config/hexapod_copter.param --console
davidbuzz commented 1 year ago

i love the pr... great start.. it was my hope that lua would b able to move the leg actuators as normal servos[like the motors].. is that possible?

srmainwaring commented 1 year ago

@davidbuzz added a quadruped copter version which is configured for scripting. The scripts folder has an example script quadruped_copter.lua and there are params in config/quadruped_copter.param which extend the standard quad params.

Run Gazebo

gz sim -v4 -r quadruped_copter_runway.sdf

Run SITL

First quadruped_copter.lua to the ardupilot scripts directory. Then run SITL:

sim_vehicle.py -D -v ArduCopter -f quad --model JSON --console --add-param-file=<path_to_quadruped_copter.param>

The script is only partially working. The legs set to the disarmed position, but the motors don't spin and the vehicle wont arm because it's expecting motor mappings - need to figure the correct FRAME_CLASS etc. for scripting.

Update

Fixed in https://github.com/ArduPilot/SITL_Models/pull/96/commits/e15128808d0caf5c456c5930a9fe2be00e71decd

The copter is folded when disarmed. When armed the legs extend to flying position and the motors spin up. Will run in all modes as a standard quad. Some notes:

davidbuzz commented 1 year ago

Wow.

srmainwaring commented 1 year ago

There is a working version of the hexapod_copter in https://github.com/ArduPilot/SITL_Models/pull/96/commits/e51a5810d1094c75acbb44fc0a6192b45e1be16a.

It follows the same approach as the quadruped_copter with:

Dependencies (Updated)

There are two changes needed to support 32 servos in SITL_JSON and the ArduPilot Gazebo plugin. They are in these PRs:

Usage

Run Gazebo

gz sim -v4 -r hexapod_copter_runway.sdf

Run SITL

First copy hexapod_copter.lua to the ardupilot scripts directory. Then run SITL:

sim_vehicle.py -D -v ArduCopter -f hexa --model JSON --console --add-param-file=<path_to_hexapod_copter.param>
davidbuzz commented 1 year ago

notes below from my attempt to run this.. I think I have it worked out now... but these were the transitional issue i hit along the way..

mkdir ./scripts
cp ./SITL_Models/Gazebo/scripts/hexapod_copter.lua ./scripts

from gazebo plugin prior to updating it:

[Err] [ArduPilotPlugin.cc:1487] [hexapod_copter] control[19] channel [19] is greater than the number of servo channels [16], control not applied

and then on a later attempt..

[Wrn] [ArduPilotPlugin.cc:1386] Incorrect protocol magic 29569 should be 18458 [Wrn] [ArduPilotPlugin.cc:1386] Incorrect protocol magic 29569 should be 18458 [Wrn] [ArduPilotPlugin.cc:1386] Incorrect protocol magic 29569 should be 18458 [Wrn] [ArduPilotPlugin.cc:1386] Incorrect protocol magic 29569 should be 18458

and then after a rebase and clean build of the gazebo plugin, it stopped throwing those errors, and then the arducopter console started giving me this:

No JSON sensor message received, resending servos No JSON sensor message received, resending servos No JSON sensor message received, resending servos No JSON sensor message received, resending servos No JSON sensor message received, resending servos

so i tried a 'rm -rf ./build/sitl/' before running sim_vehicle again, but no difference.

commands i'm running:

... a bunch of export commands to setup the gazebo env, this seems ok as the model appears to load in gz

cd ~/gazebo
mkdir ./scripts
cp ./SITL_Models/Gazebo/scripts/hexapod_copter.lua ./scripts

cd ~/gazebo/ardupilot_gazebo
rm -rf build
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
make

cd ~/gazebo/
gz sim -v4 -r hexapod_copter_runway.sdf 

[ this starts up gz fine and shows me the model ]

cd ~/gazebo
sim_vehicle.py -D -v ArduCopter -f hexa --model JSON --console --add-param-file=$HOME/gazebo/SITL_Models/Gazebo/config/hexapod_copter.param

[ this compiles the pr, runs sitl, starts mavproxy, and the sitl instance has JSON errors, and mavproxy doesn't detect a link.


~/gazebo/ardupilot_gazebo$ git status
On branch srmainwaring/garden/pr-servo-32-enable
Your branch is up to date with 'srmainwaring/srmainwaring/garden/pr-servo-32-enable'.
nothing to commit, working tree clean

~/gazebo/SITL_Models$ git status
On branch srmainwaring/hexapod-copter
Your branch is up to date with 'srmainwaring/srmainwaring/hexapod-copter'.
nothing to commit, working tree clean

~/ardupilot$ git status
On branch pr-sitl-servo-32-enable
Your branch is up to date with 'srmainwaring/pr-sitl-servo-32-enable'.
nothing to commit, working tree clean

looking thru the console output of 'gz sim -v4 -r hexapod_copter_runway.sdf' i get:

[Err] [SystemLoader.cc:118] Failed to load system plugin: (Reason: Could not find shared library)
- Requested plugin name: [ArduPilotPlugin]
- Requested library name: [ArduPilotPlugin]
- Library search paths:
  - /home/buzz/.gz/sim/plugins/
  - /usr/lib/x86_64-linux-gnu/gz-sim-7/plugins/
  - /home/buzz/.ignition/gazebo/plugins/
  - /home/buzz/gazebo/ardupilot_gazebo/build/
  - /

... which i guess means i need to re-run 'make' in the build folder...

...
[100%] Linking CXX shared library libParachutePlugin.so
[100%] Built target ParachutePlugin

ok, that seem to have loaded the plugin etc now... moving on..

davidbuzz commented 1 year ago

should the 20-ish commits be squashed down, before its merged..? - not a big deal either way, in my opinion, but the quadruped copter could be its own commit[ or dropped, now that the hexa variant fully works, up-to-you? ]

srmainwaring commented 1 year ago

Thanks for the review @davidbuzz.

should the 20-ish commits be squashed down, before its merged..? - not a big deal either way, in my opinion, but the quadruped copter could be its own commit[ or dropped, now that the hexa variant fully works, up-to-you? ]

Yes, I'll drop the quad version as it was mainly to get up and running b4 the 32 servo changes were added. Will squash the remainder down to a single commit.

I'll take this as confirmation that the changes to the plugin are working as well and get that merged which should make the set up a bit easier.