Skip to content

Commit

Permalink
Merge pull request #971 from MG-EV-Hackers/MG5SR
Browse files Browse the repository at this point in the history
Add Mg5 short range variant
  • Loading branch information
dexterbg committed Feb 24, 2024
2 parents a4187c8 + 997c970 commit 2b7a721
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 25 deletions.
1 change: 1 addition & 0 deletions vehicle/OVMS.V3/changes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Open Vehicle Monitor System v3 - Change log

????-??-?? ??? ??????? OTA release
- MG EV Added support for MG5 (2020 - 2023) Short Range
- MG EV Added support for MG ZS EV (2023 - ) and MG5 (2020 - 2023) Long Range
- OVMS Server v3 metrics filtering
New configs:
Expand Down
6 changes: 3 additions & 3 deletions vehicle/OVMS.V3/components/vehicle_mgev/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ The Long Range (72.6kWh) variant can easily be supported if BMS scans can be don
MG5 (2020-2023) Variants
------------------------

Currently only the Long Range (57kWh) variant is supported.
Both Short Range (49kWh) and Long Range (57kWh) MG5 Variants are supported and can be selected in the web UI. The Version configuration page can be found in the vehicle menu.

The web UI features a configuration page for Manual Polling in the vehicle menu.
The default setting is for Manual Polling to be on. If this is deselected, the polling will be automatic and will start when the vehicle is in READY or CHARGING and stop automatically when the vehicle is turned off to save the 12V battery. This may cause alarms on the MG5 and if this is a problem please use Manual Polling.
The default setting is for Manual Polling to be on. If this is deselected, the polling will be automatic and will start when the vehicle is in READY or CHARGING and stop automatically when the vehicle is turned off to save the 12V battery. This may cause alarms on the MG5 when locked and charging. If this is a problem, please use Manual Polling.

**Manual Polling** - As the alarm sometimes goes off when the MG5 is locked and charging, the MG5 variant starts up with the polls turned off. Polls can be turned on with the `xmg polls on` command in the shell or via a message in the app. You can also turn on polls by pressing the boot of the car in the app and pressing wakeup. Polls will only start when the car is in ready or charging. When the car is turned off again or charging is turned off, the polls will stop again. Polls can be manually stopped with the `xmg polls off` command.

Expand Down Expand Up @@ -179,4 +179,4 @@ Community channels
------------------

| Forum: https://www.mgevs.com/
| Slack: https://mgevhackers.slack.com/
| Slack: https://mgevhackers.slack.com/
23 changes: 22 additions & 1 deletion vehicle/OVMS.V3/components/vehicle_mgev/src/mg_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,29 @@ void OvmsVehicleMgEv::ConfigChanged(OvmsConfigParam* param)
int BMSVersion = MyConfig.GetParamValueInt("xmg", "bmsval", DEFAULT_BMS_VERSION);
m_dod_lower->SetValue(BMSDoDLimits[BMSVersion].Lower);
m_dod_upper->SetValue(BMSDoDLimits[BMSVersion].Upper);
ESP_LOGD(TAG, "BMS DoD lower = %f upper = %f", MyConfig.GetParamValueFloat("xmg","bms.dod.lower"), MyConfig.GetParamValueFloat("xmg","bms.dod.upper"));
}

if(StandardMetrics.ms_v_type->AsString() == "MG5") {
int VehicleVersion = MyConfig.GetParamValueInt("xmg", "vehval", 0);
//ESP_LOGI(TAG, "Vehicle Version %c", MyConfig.GetParamValue("xmg", "vehtype","unknown"));
if(VehicleVersion == 0) {
ESP_LOGV(TAG,"MG5 Version - SR");
StandardMetrics.ms_v_bat_range_full->SetValue(290.0);
m_batt_capacity->SetValue(48.8);
m_max_dc_charge_rate->SetValue(80);
m_dod_lower->SetValue(36.0);
m_dod_upper->SetValue(994.0);
} else {
ESP_LOGV(TAG,"MG5 Version - LR");
StandardMetrics.ms_v_bat_range_full->SetValue(320.0);
m_batt_capacity->SetValue(57.4);
m_max_dc_charge_rate->SetValue(87);
m_dod_lower->SetValue(36.0);
m_dod_upper->SetValue(950.0);
}
ESP_LOGD(TAG, "MG5 Values - Range: %0.1f Battery kWh: %0.1f Charge Max: %0.1f", StandardMetrics.ms_v_bat_range_full->AsFloat(), m_batt_capacity->AsFloat(), m_max_dc_charge_rate->AsFloat());
}
ESP_LOGD(TAG, "BMS DoD lower = %f upper = %f", MyConfig.GetParamValueFloat("xmg","bms.dod.lower"), MyConfig.GetParamValueFloat("xmg","bms.dod.upper"));
}


Expand Down
64 changes: 62 additions & 2 deletions vehicle/OVMS.V3/components/vehicle_mgev/src/mg_web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void OvmsVehicleMgEv::Mg5WebInit()
{
// vehicle menu:
MyWebServer.RegisterPage("/xmg/features", "Features", MG5WebCfgFeatures, PageMenu_Vehicle, PageAuth_Cookie);
MyWebServer.RegisterPage("/xmg/version", "Version", MG5WebCfgVersion, PageMenu_Vehicle, PageAuth_Cookie);
}

void OvmsVehicleMgEv::FeaturesWebInit()
Expand All @@ -95,6 +96,11 @@ void OvmsVehicleMgEv::FeaturesWebDeInit()
MyWebServer.DeregisterPage("/xmg/features");
}

void OvmsVehicleMgEv::VersionWebDeInit()
{
MyWebServer.DeregisterPage("/xmg/version");
}

/**
* WebCfgFeatures: configure general parameters (URL /xmg/config)
*/
Expand Down Expand Up @@ -158,8 +164,7 @@ void OvmsVehicleMgEv::WebCfgFeatures(PageEntry_t &p, PageContext_t &c)
void OvmsVehicleMgEv::MG5WebCfgFeatures(PageEntry_t &p, PageContext_t &c)
{
std::string error;

bool pollingmanual = MyConfig.GetParamValueInt("xmg", "polling.manual");
bool pollingmanual = MyConfig.GetParamValueInt("xmg", "polling.manual");

if (c.method == "POST") {
pollingmanual = (c.getvar("pollingmanual") == "yes");
Expand Down Expand Up @@ -211,6 +216,61 @@ void OvmsVehicleMgEv::MG5WebCfgFeatures(PageEntry_t &p, PageContext_t &c)
c.done();
}

/**
* MG5WebCfgVersion: configure general parameters (URL /xmg/config)
*/
void OvmsVehicleMgEv::MG5WebCfgVersion(PageEntry_t &p, PageContext_t &c)
{
std::string error;
std::string vehtype;
int vehval;

if (c.method == "POST") {
vehtype = c.getvar("vehtype");
vehval = atoi(vehtype.c_str());


if (error == "") {
// store:
MyConfig.SetParamValueInt("xmg", "vehval", vehval);
MyConfig.SetParamValue("xmg", "vehtype", vehtype);

c.head(200);
c.alert("success", "<p class=\"lead\">MG5 version configuration saved.</p>");
MyWebServer.OutputHome(p, c);
c.done();
return;
}
// output error, return to form:
error = "<p class=\"lead\">Error!</p><ul class=\"errorlist\">" + error + "</ul>";
c.head(400);
c.alert("danger", error.c_str());
} else {
vehval = MyConfig.GetParamValueInt("xmg", "vehval",0);
vehtype = MyConfig.GetParamValue("xmg", "vehtype", "Short Range 49kWh");

c.head(200);
}
// generate form:
c.panel_start("primary", "MG5 version configuration");
c.form_start(p.uri);

c.fieldset_start("MG5 Version Selection");
//When we have more versions, need to change this to select and updatedbms to int
c.input_radio_start("Version", "vehtype");
c.input_radio_option("vehtype", "Short Range 49kWh", "0", vehval == 0);
c.input_radio_option("vehtype", "Long Range 57kWh", "1", vehval == 1);
c.input_radio_end("");

c.fieldset_end();
c.print("<hr>");
c.input_button("default", "Save");
c.form_end();
c.panel_end();
c.done();
}


/**
* WebCfgBattery: configure battery parameters (URL /xmg/battery)
*/
Expand Down
37 changes: 25 additions & 12 deletions vehicle/OVMS.V3/components/vehicle_mgev/src/vehicle_mg5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,29 @@ OvmsVehicleMg5::OvmsVehicleMg5()

// Set manual polling on
MyConfig.SetParamValueInt("xmg", "polling.manual", 1);
// Set Max Range to WLTP Range
StandardMetrics.ms_v_bat_range_full->SetValue(WLTP_RANGE);
m_batt_capacity->SetValue(BATT_CAPACITY);
m_max_dc_charge_rate->SetValue(MAX_CHARGE_RATE);
m_dod_lower->SetValue(BMSDoDLowerLimit);
m_dod_upper->SetValue(BMSDoDUpperLimit);

//Initialise GWM state to Unknown
//m_gwm_state->SetValue(static_cast<int>(GWMStates::Unknown));

// Set up initial values from the version setting
int VehicleVersion = MyConfig.GetParamValueInt("xmg", "vehval", 0);
if(VehicleVersion == 0) {
ESP_LOGV(TAG,"MG5 Version - SR");
StandardMetrics.ms_v_bat_range_full->SetValue(290.0);
m_batt_capacity->SetValue(48.8);
m_max_dc_charge_rate->SetValue(80);
m_dod_lower->SetValue(36.0);
m_dod_upper->SetValue(994.0);

} else {
ESP_LOGV(TAG,"MG5 Version - LR");
StandardMetrics.ms_v_bat_range_full->SetValue(320.0);
m_batt_capacity->SetValue(57.4);
m_max_dc_charge_rate->SetValue(87);
m_dod_lower->SetValue(36.0);
m_dod_upper->SetValue(950.0);
}
ESP_LOGD(TAG, "MG5 Values - Range: %0.1f Battery kWh: %0.1f Charge Max: %0.1f", StandardMetrics.ms_v_bat_range_full->AsFloat(),
m_batt_capacity->AsFloat(),
m_max_dc_charge_rate->AsFloat());

//Add variant specific poll data
ConfigureMG5PollData(mg5_obdii_polls, sizeof(mg5_obdii_polls));

Expand All @@ -153,7 +166,6 @@ OvmsVehicleMg5::OvmsVehicleMg5()

// Register shell commands
cmd_xmg->RegisterCommand("polls", "Turn polling on", PollsCommandShell, "<command>\non\tTurn on\noff\tTurn off", 1, 1);

//PollSetState(PollStateRunning);
#ifdef CONFIG_OVMS_COMP_WEBSERVER
Mg5WebInit();
Expand All @@ -166,6 +178,7 @@ OvmsVehicleMg5::~OvmsVehicleMg5()
ESP_LOGI(TAG, "Shutdown MG5");
#ifdef CONFIG_OVMS_COMP_WEBSERVER
FeaturesWebDeInit();
VersionWebDeInit();
#endif
}

Expand Down Expand Up @@ -203,7 +216,7 @@ void OvmsVehicleMg5::MainStateMachine(canbus* currentBus, uint32_t ticker)
StandardMetrics.ms_v_bat_12v_voltage->AsFloat() >= CHARGING_THRESHOLD);

if(MyConfig.GetParamValueInt("xmg", "polling.manual") == 1) {
ESP_LOGD(TAG,"Polling is manual");
//ESP_LOGD(TAG,"Polling is manual");
if(!StandardMetrics.ms_v_env_charging12v->AsBool()) {
// 12V not being charged so vehicle is off
StandardMetrics.ms_v_env_awake->SetValue(false);
Expand Down Expand Up @@ -379,6 +392,6 @@ OvmsVehicleMg5Init::OvmsVehicleMg5Init()
{
ESP_LOGI(TAG, "Registering Vehicle: MG5 (9000)");

MyVehicleFactory.RegisterVehicle<OvmsVehicleMg5>("MG5", "MG 5 (LR) (2020-2023)");
MyVehicleFactory.RegisterVehicle<OvmsVehicleMg5>("MG5", "MG 5 (2020-2023)");
}

6 changes: 0 additions & 6 deletions vehicle/OVMS.V3/components/vehicle_mgev/src/vehicle_mg5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@

#include "vehicle_mgev.h"

#define WLTP_RANGE 320.0 //km
#define BATT_CAPACITY 57.4 //kWh
#define MAX_CHARGE_RATE 87 //kW
#define BMSDoDUpperLimit 950.0
#define BMSDoDLowerLimit 36.0

class OvmsVehicleMg5 : public OvmsVehicleMgEv
{
public:
Expand Down
2 changes: 2 additions & 0 deletions vehicle/OVMS.V3/components/vehicle_mgev/src/vehicle_mgev.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,10 @@ class OvmsVehicleMgEv : public OvmsVehicle
void Mg5WebInit();
void FeaturesWebInit();
void FeaturesWebDeInit();
void VersionWebDeInit();
static void WebCfgFeatures(PageEntry_t& p, PageContext_t& c);
static void MG5WebCfgFeatures(PageEntry_t &p, PageContext_t &c);
static void MG5WebCfgVersion(PageEntry_t &p, PageContext_t &c);
static void WebCfgBattery(PageEntry_t& p, PageContext_t& c);
void GetDashboardConfig(DashboardConfig& cfg);
static void WebDispChgMetrics(PageEntry_t &p, PageContext_t &c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ OvmsVehicleMgEvA::OvmsVehicleMgEvA()
m_dod_upper->SetValue(BMSDoDLimits[BMSVersion].Upper);
m_batt_capacity->SetValue(BATT_CAPACITY);
m_max_dc_charge_rate->SetValue(MAX_CHARGE_RATE);


ESP_LOGD(TAG, "BMS DoD lower = %f upper = %f",
MyConfig.GetParamValueFloat("xmg","bms.dod.lower"),
MyConfig.GetParamValueFloat("xmg","bms.dod.upper"));

//Add variant specific poll data
ConfigurePollData(obdii_polls_a, sizeof(obdii_polls_a));

Expand Down

0 comments on commit 2b7a721

Please sign in to comment.