Hi everyone,
My custom xplane bridge is talking, but I’m having difficulties getting control allocation for an airframe to work in my build. The information in the issues I’ve found on the forums and github is out of date, still expecting “make px4_sitl none_iris”, which allows an airframe to be specified with “none” simulator.
opened 07:33AM - 30 Nov 21 UTC
closed 07:53AM - 10 Dec 21 UTC
question
Hi,
I need to link one homemade simulator in Python with PX4 SITL (later HITL… ).
My simulator contains full drone and world models. My plan is to receive commands from PX4 and to return the drone state (position, attitude, acceleration, everything needed).
I tried to follow the [dedicated documentation](https://docs.px4.io/master/en/simulation/#simulator-mavlink-api) but despite of my efforts it doesn't work. So I suspect the documentation to be incomplete.
What I need is a lockstep SITL. The documentation says:
**[Simulator MAVLink API](https://docs.px4.io/master/en/simulation/#simulator-mavlink-api)**
PX4 inputs are: **HIL_SENSOR**, **HIL_GPS**, etc... mavlink messages
PX4 outputs are: **HIL_ACTUATOR_CONTROLS** message
**[SITL Simulation Environment](https://docs.px4.io/master/en/simulation/#sitl-simulation-environment)**
PX4 SITL and the simulator communicate through a TCP connection on port 4560
**[Starting/Building SITL Simulation](https://docs.px4.io/master/en/simulation/#starting-building-sitl-simulation)**
To start PX4 with a custom simulator:
```make px4_sitl none_iris```
**[Lockstep Simulation](https://docs.px4.io/master/en/simulation/#lockstep-simulation)**
A lockstep simulation runs as follow:
1. The simulator must send a **HIL_SENSOR** message.
2. The PX4 returns a **HIL_ACTUATOR_CONTROLS** message.
I followed all of this information but can't have it work. What I do:
**1. I launch a SITL standalone PX4:**
```make px4_sitl none_iris```
**2. I wait until it says it waits for the simulator to connect:**
```INFO [simulator] Waiting for simulator to accept connection on TCP port 4560```
**3. In Python, I connect to the TCP port with pymavlink:**
```
from pymavlink import mavutil
vehicle = mavutil.mavlink_connection('tcpin:localhost:4560')
vehicle.wait_heartbeat()
print("Heartbeat from system (system %u component %u)" % (vehicle.target_system, vehicle.target_component))
```
**4. PX4 says the simulator is connected:**
```INFO [simulator] Simulator connected on TCP port 4560.```
**5. I sent a HIL_SENSOR message**
```
# HIL_SENSOR
vehicle.mav.hil_sensor_send(
time_usec = 1636636640 , # Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude of the number. [us] (type:uint64_t)
xacc = 0 , # X acceleration [m/s/s] (type:float)
yacc = 0 , # Y acceleration [m/s/s] (type:float)
zacc = 0 , # Z acceleration [m/s/s] (type:float)
xgyro = 0 , # Angular speed around X axis in body frame [rad/s] (type:float)
ygyro = 0 , # Angular speed around Y axis in body frame [rad/s] (type:float)
zgyro = 0 , # Angular speed around Z axis in body frame [rad/s] (type:float)
xmag = 0 , # X Magnetic field [gauss] (type:float)
ymag = 0 , # Y Magnetic field [gauss] (type:float)
zmag = 0 , # Z Magnetic field [gauss] (type:float)
abs_pressure = 1 , # Absolute pressure [hPa] (type:float)
diff_pressure = 0 , # Differential pressure (airspeed) [hPa] (type:float)
pressure_alt = 0 , # Altitude calculated from pressure (type:float)
temperature = 15 , # Temperature [degC] (type:float)
fields_updated = 31 , # Bitmap for fields that have updated since last message, bit 0 = xacc, bit 12: temperature, bit 31: full reset of attitude/position/velocities/etc was performed in sim. (type:uint32_t)
id = 0 , # Sensor ID (zero indexed). Used for multiple sensor inputs (type:uint8_t)
)
```
**6. I wait for an answer from PX4**
```
print("Waiting a message...")
msg = vehicle.recv_match(blocking=True)
print(msg)
```
But nothing happens. In addition, no UDP connection is not initiated by PX4 to monitor it.
Is there something missing in the documentation regarding the use of custom simulators?
This doesn’t work anymore; how do I get it to load an airframe, but let it link to a simulator using a simple mavlink bridge? I think this may be the last thing I need to get this running. I’m still new to the PX4 build architecture, so help would be appreciated while I try to continue figuring this out myself.
I ended up somewhat solving this myself. It appears all I have to do is set the PX4_SIM_MODEL environment variable externally and it will pick up my airframe configs. Now I just have to figure out why it’s barfing on bad accel 0 and gyro 0 and all the imu data being sent to ID 0 is being remapped to 3…
We’re almost flying in xplane again.
i have similar issue - after a “fresh” sitl build - the airframe is “none” - i need to reset and select vtol airframe again does anybody has an advice?