Skip to content

Commit

Permalink
Fix bugs in offboard mode.
Browse files Browse the repository at this point in the history
Fix persistence of new settings.
  • Loading branch information
lovettchris committed Mar 17, 2017
1 parent fda5e77 commit d0ee449
Show file tree
Hide file tree
Showing 8 changed files with 596 additions and 380 deletions.
85 changes: 45 additions & 40 deletions AirLib/include/vehicles/configs/PX4ConfigCreator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "controllers/Settings.hpp"
#include "BlacksheepQuadX.hpp"
#include "PX4QuadX.hpp"
#include "SimJoyStick/SimJoyStick.h"
#include "SimJoyStick/SimJoyStick.h"

namespace msr { namespace airlib {

Expand All @@ -20,15 +20,15 @@ class PX4ConfigCreator {

std::unique_ptr<MultiRotorParams> config;

if (connection_info.model == "Blacksheep") {
config.reset(new BlacksheepQuadX(connection_info));
}
else {
config.reset((new Px4QuadX(connection_info)));
if (connection_info.model == "Blacksheep") {
config.reset(new BlacksheepQuadX(connection_info));
}
else {
config.reset((new Px4QuadX(connection_info)));
}

//In SITL mode enable joystick support
SimJoyStick::setEnabled(!connection_info.use_serial);
SimJoyStick::setEnabled(!connection_info.use_serial);

return config;
}
Expand All @@ -42,8 +42,8 @@ class PX4ConfigCreator {

//read settings and override defaults
Settings& settings = Settings::singleton();
Settings child;
if (settings.isLoadSuccess()) {
Settings child;
settings.getChild(connection_info.vehicle_name, child);

// allow json overrides on a per-vehicle basis.
Expand Down Expand Up @@ -75,40 +75,45 @@ class PX4ConfigCreator {
connection_info.baud_rate = child.getInt("SerialBaudRate", connection_info.baud_rate);
connection_info.model = child.getString("Model", connection_info.model);
}
//do not write to users settings unless file didn't exist!
else if (settings.hasFileName() && connection_info.vehicle_name.size() > 0) {
Settings child;
child.setInt("SimSysID", connection_info.sim_sysid);
child.setInt("SimCompID", connection_info.sim_compid);

child.setInt("VehicleSysID", connection_info.vehicle_sysid);
child.setInt("VehicleCompID", connection_info.vehicle_compid);

child.setInt("OffboardSysID", connection_info.offboard_sysid);
child.setInt("OffboardCompID", connection_info.offboard_compid);

child.setString("LogViewerHostIp", connection_info.logviewer_ip_address);
child.setInt("LogViewerPort", connection_info.logviewer_ip_port);

child.setString("QgcHostIp", connection_info.qgc_ip_address);
child.setInt("QgcPort", connection_info.qgc_ip_port);

child.setString("SitlIp", connection_info.sitl_ip_address);
child.setInt("SitlPort", connection_info.sitl_ip_port);

child.setString("LocalHostIp", connection_info.local_host_ip);

child.setBool("UseSerial", connection_info.use_serial);
child.setString("UdpIp", connection_info.ip_address);
child.setInt("UdpPort", connection_info.ip_port);
child.setString("SerialPort", connection_info.serial_port);
child.setInt("SerialBaudRate", connection_info.baud_rate);
child.setString("Model", connection_info.model);

settings.setChild(connection_info.vehicle_name, child);
settings.saveJSonFile("settings.json");

// update settings file with any new values that we now have.
if (connection_info.vehicle_name.size() > 0) {

bool changed = child.setInt("SimSysID", connection_info.sim_sysid);
changed |= child.setInt("SimCompID", connection_info.sim_compid);

changed |= child.setInt("VehicleSysID", connection_info.vehicle_sysid);
changed |= child.setInt("VehicleCompID", connection_info.vehicle_compid);

changed |= child.setInt("OffboardSysID", connection_info.offboard_sysid);
changed |= child.setInt("OffboardCompID", connection_info.offboard_compid);

changed |= child.setString("LogViewerHostIp", connection_info.logviewer_ip_address);
changed |= child.setInt("LogViewerPort", connection_info.logviewer_ip_port);

changed |= child.setString("QgcHostIp", connection_info.qgc_ip_address);
changed |= child.setInt("QgcPort", connection_info.qgc_ip_port);

changed |= child.setString("SitlIp", connection_info.sitl_ip_address);
changed |= child.setInt("SitlPort", connection_info.sitl_ip_port);

changed |= child.setString("LocalHostIp", connection_info.local_host_ip);

changed |= child.setBool("UseSerial", connection_info.use_serial);
changed |= child.setString("UdpIp", connection_info.ip_address);
changed |= child.setInt("UdpPort", connection_info.ip_port);
changed |= child.setString("SerialPort", connection_info.serial_port);
changed |= child.setInt("SerialBaudRate", connection_info.baud_rate);
changed |= child.setString("Model", connection_info.model);

// only write to the file if we have new values to save.
if (changed) {
settings.setChild(connection_info.vehicle_name, child);
settings.saveJSonFile("settings.json");
}
}


return connection_info;
}

Expand Down
Loading

0 comments on commit d0ee449

Please sign in to comment.