Trying to add a new vehicle to Zombie 2.20A release

Post Reply
Kelju
Posts: 171
Joined: Sat Aug 22, 2020 6:54 pm
Location: Finland
Has thanked: 13 times
Been thanked: 18 times

Trying to add a new vehicle to Zombie 2.20A release

Post by Kelju »

I am trying to migrate to this latest FW, but I need to modify the code. I have previously added RX8 vehicle CAN coms to an earlier version.
A lot has changed in the structuring of the code and to the positive direction for sure. However, when I tried to copy-paste my way to having the RX8 functions in, I get an error while attempting to compile. I thought it had something to do with my new c and h files and tried just modifying an existing vehicle according to my needs... still did not work. I am getting the following error:

Code: Select all

src/stm32_vcu.cpp:149:22: error: cannot declare variable 'subaruVehicle' to be of abstract type 'SubaruVehicle'
  149 | static SubaruVehicle subaruVehicle;
      |                      ^~~~~~~~~~~~~
In file included from src/stm32_vcu.cpp:49:
include/subaruvehicle.h:25:7: note:   because the following virtual functions are pure within 'SubaruVehicle':
   25 | class SubaruVehicle : public Vehicle
Been banging my head against the wall with this one for a couple of hours now. A helping hand would be much appreciated. :?
User avatar
tom91
Posts: 2392
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 207 times
Been thanked: 563 times

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by tom91 »

Where is your codw, do you have a github branch? I can add the Mazda RX8 to the one of my branches and once proven merge it.

it took me a while to fix issues with virtual functions. Usually just ends up with me changing things and compiling alot.
Creator of SimpBMS
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
nkiernan
Posts: 559
Joined: Mon Feb 24, 2020 8:59 pm
Location: Ireland
Has thanked: 385 times
Been thanked: 80 times

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by nkiernan »

Kelju wrote: Thu Dec 26, 2024 6:26 pm However, when I tried to copy-paste my way to having the RX8 functions in
Hmmmm, this was the approach I was about to start. Was planning to change the CAN ID's in Damien's E39 class to suit the Range Rover requirments for RPM and gear displays...so maybe its not that straightforward. Interested to see how the RX8 works out
Kelju
Posts: 171
Joined: Sat Aug 22, 2020 6:54 pm
Location: Finland
Has thanked: 13 times
Been thanked: 18 times

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by Kelju »

tom91 wrote: Thu Dec 26, 2024 7:12 pm I can add the Mazda RX8 to the one of my branches and once proven merge it.
I do not have an own branch. I just cloned from Damien's Github and modified the code which is locally on my computer. This is how I have always done it. Adding the new vehicle is not the only thing I need to modify. I also have some custom BMS code and using a LEM CAB300 for current sensing while the Leaf inverter measures the DC-link voltage.
The car is a living thing with constant updates, so I would really like to be able to compile my own code. Thanks for the offer, but is there really no other way?
Kelju
Posts: 171
Joined: Sat Aug 22, 2020 6:54 pm
Location: Finland
Has thanked: 13 times
Been thanked: 18 times

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by Kelju »

another strange thing...
When I clone the V2.20A repo and try to get the dependencies, I get this:

Code: Select all

  GIT SUBMODULE
  MAKE libopencm3
make[1]: Entering directory '/Documents/Stm32-vcu/libopencm3'
  GENHDR  include/libopencm3/stm32/f1/irq.json
/usr/bin/env: ‘python’: No such file or directory
make[1]: *** [Makefile:59: include/libopencm3/stm32/f1/irq.json.genhdr] Error 127
make[1]: Leaving directory '/Documents/Stm32-vcu/libopencm3'
make: *** [Makefile:146: get-deps] Error 2
Once I copy the libopencm3 folder from an earlier cloned project (where the "make get -deps" command worked without errors), I am able to compile.
Anyway, I am now trying to make my RX8 integration changes to my own fork. I'll send a link once I am done so that the compilation error can be debugged.
royhen99
Posts: 261
Joined: Sun Feb 20, 2022 4:23 am
Location: N. Wiltshire. UK
Has thanked: 22 times
Been thanked: 130 times

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by royhen99 »

Python needs to be installed to generate some of the header files.
Kelju wrote: Thu Dec 26, 2024 7:47 pm .....but is there really no other way?
Learn a little bit about virtual and pure virtual function declarations/definitions.

Some functions need to be in the child class as they are not defined in the vehicle parent class.

Code: Select all

  void SetRevCounter(int s) { rpm = s; }
  void SetTemperatureGauge(float) { }
  bool Ready();
The above need to be in your vehicle class header file, equivalent of subaruvehicle.h level even if they are not used. In above SetRevCounter sets a value, SetTemperatureGauge just returns, and Ready() requires function to be defined in .cpp file.

Edit: Just to be clear the above is the minimum required to compile. NoVehicle.h gives minimum to function with T15 and start signals. Look at other vehicles for scheduled tasks and can bus.
User avatar
tom91
Posts: 2392
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 207 times
Been thanked: 563 times

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by tom91 »

The issue with not running along with the main branch and doing manual updates things get missed. Do not ask how I know, it was a tough learning exercise to get github working and understanding how to do it.

There are so many changes happening the modify a lot of files so it is important to review all the changes one by one to understand how each change impacts your modifications. This is alot of work if you are adamant on not being a github branch of the main repo.

This also makes it impossible for me to provide any feedback as I cannot review any of your changes and how they might interfere or break other code sections.

EDIT: Title is also completely incorrect, you are trying to merge your version of code with 2.20A you are not trying to make a new vehicle class.
Creator of SimpBMS
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
User avatar
johu
Site Admin
Posts: 6711
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 368 times
Been thanked: 1541 times
Contact:

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by johu »

You should really fork the repo and create a branch with your custom changes. Then, when ZombieVerter is updated you can merge changes from 'main' to your custom branch to stay up to date and at the same time preserve your custom code. It it much less error prone than manually faffing around
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Kelju
Posts: 171
Joined: Sat Aug 22, 2020 6:54 pm
Location: Finland
Has thanked: 13 times
Been thanked: 18 times

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by Kelju »

Thanks for the comments and instructions. As I wrote earlier, I made a fork, cloned and am doing my changes so that I can push (?) the changes to Git.
I managed to add the RX8 functionality and compile, so here is a step by step (non-coder) instruction for anybody who is attempting the same:

1. Check that you can compile the original project before making any modifications by navigating to the project folder with a terminal and typing make get -deps and then make. If it works, you should find newly updated .bin and .hex files in the project folder.
2. Add new object to the Makefile in OBJSL, e.g.,

Code: Select all

MAZDA_RX8.o
3. Make a header file for your new vehicle, e.g., MAZDA_RX8.h (You can copy an existing one and make your modifications as needed)
3.1. To enable compilation, you need to include at least these:

Code: Select all

	Public:
		bool Ready() { return true; }
   		void SetRevCounter(int speed) { revCounter = speed; }
   		void SetTemperatureGauge(float temp) { temperature = temp; } 
   	Private:
   		int revCounter;
   		float temperature;
4. Make a source file for your new vehicle, e.g., MAZDA_RX8.c (You can copy an existing one and make your modifications as needed)
5. Modify param_prj.h
5.1. Increase VEHMODES MAX value by 1
5.2. Add new vehicle to "define VEHMODES", e.g., <VEHMODES MAX value>=MAZDA_RX8
5.3. Add new vehicle to "enum vehicles", e.g., vMAZDA_RX8 = <VEHMODES MAX value>
6. Modify stm32_vcu.c
6.1. Declear the header file, e.g.,

Code: Select all

#include "MAZDA_RX8.h"
6.2. Instantiate a new class, e.g.,

Code: Select all

static MAZDA_RX8 rx8Vehicle;
6.3. Add new vehicle to switch in function "static void UpdateVehicle()", e.g.,

Code: Select all

	case vehicles::vMAZDA_RX8:
        		selectedVehicle = &rx8Vehicle;
        		break;
7. Save all modified files and compile with "make"
User avatar
Bigpie
Posts: 1771
Joined: Wed Apr 10, 2019 8:11 pm
Location: South Yorkshire, UK
Has thanked: 82 times
Been thanked: 422 times

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by Bigpie »

The RX8 is a fairly common conversion so your code to support it would be good to merge
BMW E91 2006
ZombieVerter
GS450h
Outlander Charger DC/DC
Renault Kangoo 36kWh battery
FOCCCI CCS
Kelju
Posts: 171
Joined: Sat Aug 22, 2020 6:54 pm
Location: Finland
Has thanked: 13 times
Been thanked: 18 times

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by Kelju »

tom91 wrote: Thu Dec 26, 2024 7:12 pm Where is your codw, do you have a github branch? I can add the Mazda RX8 to the one of my branches and once proven merge it.

it took me a while to fix issues with virtual functions. Usually just ends up with me changing things and compiling alot.
Now I have my own branch.
https://github.com/Keljua/Stm32-vcu/tre ... ntegration

I cannot get the Zombie to register my user CAN messages, though. Or at least that is what I suspect.
0x4B1 has the wheel speed info which is then saved into variable "VehicleSpeed".
Then, in the Task100ms, the vehicle speed is send to the dash in 0x201.
This all worked just fine with an earlier release FW that I hacked, but does not work with the V2.20...
0x201 also has the engine RPM, which is being updated to the RPM gauge in the dash just fine, so at least the 0x201 is being correctly sent to CAN2.

Also confirmed that the speedo works fine, when I send the 0x201 (with some speed) manually with an USB-CAN adapter.
User avatar
johu
Site Admin
Posts: 6711
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 368 times
Been thanked: 1541 times
Contact:

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by johu »

I wonder if it ran out of CAN filters on hardware level? The library itself allows 30 user messages per interface. You can try increasing it by adding -DMAX_USER_MESSAGES=35 to CPPFLAGS in Makefile
But there is also a hardware limit. You'd have to go in there with a debugger to find out how many user messages are used up
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
tom91
Posts: 2392
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 207 times
Been thanked: 563 times

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by tom91 »

In your rx8.h

Code: Select all

void DecodeCAN(int, uint32_t* data); 
You are missing variable name 'id', might not cause the issue but who knows.

Easy way to check if you got too many CAN ids set,turn off all CAN except the vehicle one.

Also add a debug line by dumping a counter into an unused spot value.
Creator of SimpBMS
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
Kelju
Posts: 171
Joined: Sat Aug 22, 2020 6:54 pm
Location: Finland
Has thanked: 13 times
Been thanked: 18 times

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by Kelju »

I checked that the Zombie indeed receives the wheel speed and it also sends it forward to the dash. At this point I was very confused as to what the hell was going on. Then I once more opened up the reverse engineered CAN database of the RX8 and noticed that there are actually two CAN IDs that have the wheel speed info.
I was using 0x4B1, which is "Wheel Speeds/100 (IN KPH)", however, the dash is expecting the data in format: "(Wheel Speeds - 10000)/100 (IN KPH)".
The correct format can be found in the CAN message 0x4B0.

I checked my old code and guess what... Some idiot had updated the registering of user CAN message correctly to 0x4B0, but kept all the naming in the code as "4B1". (just to clarify, the idiot is staring at me from the mirror. ;) )

The speedo works just fine now.
Next thing to do is the control of the fuel gauge.
User avatar
johu
Site Admin
Posts: 6711
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 368 times
Been thanked: 1541 times
Contact:

Re: Trying to add a new vehicle to Zombie 2.20A release

Post by johu »

Hence why magic numbers are discouraged ;) (but I do it, too).

Simple improvement

Code: Select all

#define WHEEL_CAN_ID 0x4B0
...
   can->RegisterUserMessage(WHEEL_CAN_ID)
...
   case WHEEL_CAN_ID:
...
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Post Reply