Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Hardware-In-The-Loop simulation for JSBSim #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Jaeyoung-Lim
Copy link
Contributor

@Jaeyoung-Lim Jaeyoung-Lim commented Oct 22, 2020

Describe problem solved by this pull request
Currently the px4-jsbsim-bridge can only be used to run Software-In-The-Loop(SITL) simulations. While this is useful for evaluating the software changes in firmware, it may not reveal issues that may appear only deployed on hardware. PX4 also supports Hardware-In-The-Loop(HITL) simulation. However, this was not exposed to the jsbsim-bridge

Describe your solution
This commit adds configuration options for running HITL simulation with the PX4 JSBSim bridge.

The device path / baudrate can be passed with the command line when running the binary directly with flag -d and -b.
e.g.

HEADLESS=1 ./jsbsim_bridge rascal -d /dev/ttyACM0 -s ~/src/Firmware/Tools/jsbsim_bridge/scene/LSZH.xml

or to set the baudrate

HEADLESS=1 ./jsbsim_bridge rascal -d /dev/ttyACM0 -b 921600 -s ~/src/Firmware/Tools/jsbsim_bridge/scene/LSZH.xml

The bridge is configured to be run with a HITL when the device path -d is provided. The baudrate is configured to be 921600 by default, but can be also configured through a -b flag.

Test data / coverage
WIP

Additional context

@Jaeyoung-Lim Jaeyoung-Lim changed the title Add device /baudrate for configuration options Enable Hardware-In-The-Loop simulation for JSBSim Oct 22, 2020
@Jaeyoung-Lim Jaeyoung-Lim force-pushed the pr-hil-support branch 2 times, most recently from 97bb7de to 411ee67 Compare October 24, 2020 16:30
@Jaeyoung-Lim Jaeyoung-Lim marked this pull request as ready for review October 27, 2020 21:31
This was referenced Oct 27, 2020
@@ -63,6 +60,9 @@ class ConfigurationParser {
std::string getInitScriptPath() { return _init_script_path; }
std::string getModelName() { return _model_name; }
int getRealtimeFactor() { return _realtime_factor; }
bool getSerialEnabled() { return _serial_enabled; }
int getBaudrate() { return _baudrate; }
std::string getDevice() { return _device; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string getDevice() { return _device; }
const std::string& getDevice() const { return _device; }

src/configuration_parser.cpp Outdated Show resolved Hide resolved
@@ -149,18 +149,35 @@ bool JSBSimBridge::SetFdmConfigs(ConfigurationParser &cfg) {
}
}

bool JSBSimBridge::SetMavlinkInterfaceConfigs(std::unique_ptr<MavlinkInterface> &interface, TiXmlHandle &config) {
bool JSBSimBridge::SetMavlinkInterfaceConfigs(std::unique_ptr<MavlinkInterface> &interface, ConfigurationParser &cfg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool JSBSimBridge::SetMavlinkInterfaceConfigs(std::unique_ptr<MavlinkInterface> &interface, ConfigurationParser &cfg) {
bool JSBSimBridge::SetMavlinkInterfaceConfigs(std::unique_ptr<MavlinkInterface> &interface, const ConfigurationParser &cfg) {

@@ -149,18 +149,35 @@ bool JSBSimBridge::SetFdmConfigs(ConfigurationParser &cfg) {
}
}

bool JSBSimBridge::SetMavlinkInterfaceConfigs(std::unique_ptr<MavlinkInterface> &interface, TiXmlHandle &config) {
bool JSBSimBridge::SetMavlinkInterfaceConfigs(std::unique_ptr<MavlinkInterface> &interface, ConfigurationParser &cfg) {
TiXmlHandle config = *cfg.XmlHandle();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TiXmlHandle config = *cfg.XmlHandle();
const TiXmlHandle& config = *cfg.XmlHandle();

@@ -199,7 +216,12 @@ void JSBSimBridge::Run() {
}

// Receive and handle actuator controls
_mavlink_interface->pollForMAVLinkMessages();
bool hil_mode_ = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always true (?)

@Jaeyoung-Lim Jaeyoung-Lim force-pushed the pr-hil-support branch 3 times, most recently from d12eef0 to 774fa81 Compare November 2, 2020 16:51
This commit adds configuration options for running HITL simulation with the PX4 JSBSim bridge

The device path / baudrate can be passed with the command line flag -d and -b. The bridge is configured to be run by HITL when the -d is provided. the baudrate is configured to be 921600 by default 


Enable HITL on mavlink interface

This PR enables HITL on the mavlink interface
Handle gcs udp port in config file
Co-authored-by: Beat Küng <beat-kueng@gmx.net>
@fahadmaqbool16
Copy link

@Jaeyoung-Lim . Hi I am interested in running HITL with JSBSim bridge, Can you please guide me with the steps to follow for this. any help will be highly appreciated.

@Jaeyoung-Lim
Copy link
Contributor Author

@fahadmaqbool16 The pull request already explains how to test this PR, what additional information do you need?

@fahadmaqbool16
Copy link

@Jaeyoung-Lim thanks for your reply, when I run

HEADLESS=1 ./jsbsim_bridge rascal -d /dev/ttyACM0 -s ~/src/Firmware/Tools/jsbsim_bridge/scene/LSZH.xml

 in Tools directory I get 

bash: ./Tools/jsbsim_bridge/: Is a directory

Nothing happens.

@Jaeyoung-Lim
Copy link
Contributor Author

@fahadmaqbool16 If you read the PR description, your command does not match what I have described

Also your log says that what you tried to execute is a directory, therefore it is expected that nothing happens

@fahadmaqbool16
Copy link

No, actually I was changing the directory to Tools to see if the command works, but it didn't. To clarify, I am

running this command HEADLESS=1 ./jsbsim_bridge rascal -d /dev/ttyACM0 -s ~/src/Firmware/Tools/jsbsim_bridge/scene/LSZH.xml

in the Tools directory, I get the error

ofp@ubuntu:~/PX4-Autopilot/Tools$ HEADLESS=1 ./jsbsim_bridge rascal -d /dev/ttyACM0 -s ~/src/Firmware/Tools/jsbsim_bridge/scene/LSZH.xml

bash: ./jsbsim_bridge: Is a directory

if this command is not correct, can you please tell the correct command,

@fahadmaqbool16
Copy link

Hi, My bad, I was running the command in the Tools directory, now I am able to make the jsbsim bridge work by running that command (HEADLESS=1 ./jsbsim_bridge rascal -d /dev/ttyACM0 -s ~/src/Firmware/Tools/jsbsim_bridge/scene/LSZH.xml) from within the build directory (/PX4-Autopilot/build/px4_sitl_default/build_jsbsim_bridge). My pixhawk is detected on the serial port as shown in the image below.

image

QGC is also able to connect with pixhawk but i am unable to arm the vehicle as the vehicle launch position is not showing in QGC.

image

running dmesg in the MAVLINK console shows the follwing output.

image

PS: I replaced the px4_jsbsim_bridge files from this repo. (https://github.com/Auterion/px4-jsbsim-bridge/tree/f88764b091a8f5bc5f98893f07c63b56682a1420)

@Jaeyoung-Lim
Copy link
Contributor Author

PS: I replaced the px4_jsbsim_bridge files from this repo. (https://github.com/Auterion/px4-jsbsim-bridge/tree/f88764b091a8f5bc5f98893f07c63b56682a1420)

@fahadmaqbool16 You can't do that it only works with this specific branch

interface->SetSerialEnabled(cfg.getSerialEnabled());
interface->SetDevice(cfg.getDevice());
interface->SetBaudrate(cfg.getBaudrate());
interface->SetHILStateLevel(true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interface->SetHILStateLevel(false); this fixes GPS Lock issue

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::shared_ptrJSBSim::FGInitialCondition initial_condition = _fdmexec->GetIC();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENABLING HIL MODE IN JSBSIM BRIDGE
6 participants