-
Notifications
You must be signed in to change notification settings - Fork 38
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. std::shared_ptrJSBSim::FGInitialCondition initial_condition = _fdmexec->GetIC(); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -53,7 +53,7 @@ JSBSimBridge::JSBSimBridge(JSBSim::FGFDMExec *fdmexec, ConfigurationParser &cfg) | |||||
|
||||||
// Configure Mavlink HIL interface | ||||||
_mavlink_interface = std::make_unique<MavlinkInterface>(); | ||||||
SetMavlinkInterfaceConfigs(_mavlink_interface, config); | ||||||
SetMavlinkInterfaceConfigs(_mavlink_interface, _cfg); | ||||||
|
||||||
_mavlink_interface->Load(); | ||||||
|
||||||
|
@@ -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) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
TiXmlHandle config = *cfg.XmlHandle(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
TiXmlElement *mavlink_configs = config.FirstChild("mavlink_interface").Element(); | ||||||
|
||||||
if (!mavlink_configs) return true; // Nothing to set | ||||||
|
||||||
int tcp_port = kDefaultSITLTcpPort; | ||||||
GetConfigElement<int>(config, "mavlink_interface", "tcp_port", tcp_port); | ||||||
int udp_port = kDefaultGCSPort; | ||||||
GetConfigElement<int>(config, "mavlink_interface", "udp_port", udp_port); | ||||||
bool enable_lockstep = true; | ||||||
GetConfigElement(config, "mavlink_interface", "enable_lockstep", enable_lockstep); | ||||||
|
||||||
interface->SetMavlinkTcpPort(tcp_port); | ||||||
interface->SetUseTcp(true); | ||||||
if (cfg.getSerialEnabled()) { | ||||||
// Configure for HITL when serial is enabled | ||||||
interface->SetSerialEnabled(cfg.getSerialEnabled()); | ||||||
interface->SetDevice(cfg.getDevice()); | ||||||
interface->SetBaudrate(cfg.getBaudrate()); | ||||||
interface->SetHILStateLevel(true); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interface->SetHILStateLevel(false); this fixes GPS Lock issue |
||||||
interface->SetHILMode(true); | ||||||
interface->SetGcsAddr("INADDR_ANY"); | ||||||
interface->SetGcsUdpPort(udp_port); | ||||||
|
||||||
} else { | ||||||
// Configure for SITL as default | ||||||
interface->SetMavlinkTcpPort(tcp_port); | ||||||
interface->SetUseTcp(true); | ||||||
} | ||||||
|
||||||
interface->SetEnableLockstep(enable_lockstep); | ||||||
|
||||||
return true; | ||||||
|
@@ -199,7 +216,12 @@ void JSBSimBridge::Run() { | |||||
} | ||||||
|
||||||
// Receive and handle actuator controls | ||||||
_mavlink_interface->pollForMAVLinkMessages(); | ||||||
bool hil_mode_ = true; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. always true (?) |
||||||
if (hil_mode_) { | ||||||
_mavlink_interface->pollFromGcsAndSdk(); | ||||||
} else { | ||||||
_mavlink_interface->pollForMAVLinkMessages(); | ||||||
} | ||||||
Eigen::VectorXd actuator_controls = _mavlink_interface->GetActuatorControls(); | ||||||
|
||||||
if (actuator_controls.size() >= 16) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.