[help needed] how to code engine and trigger setup properly

It's all about the code!
Post Reply
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

I measured my trigger signal and coded my settings in the code.
In the code i can see my values , and i feel in control.
Maybe someone can help me by checking whether i do it the right way.

As overview, these files i changed in the firmware dir:(see below)
I excluded the fish files that are simple conversions of the *.bat files to my shell. (fish shell) .
I excluded the autogenerated.
after the code stuff i describe in what order i did things.

cmds and output:

Code: Select all

➤ git log --oneline origin/master^..origin/master #means my origin/master is at 33e...
33e87ba69 (origin/master) Merge branch 'master' of https://github.com/rusefi/rusefi
153aae2fc docs
my engines is named z5 engine by mazda.
if i load the engine with set engine_type 57 ,then the name shows up , but the values that get loaded are wrong . no ign pin , wrong fuel inj mode,etc..

Code: Select all

➤ git diff --stat=300 origin/master firmware|grep -v '.fish'|grep -v 'generated'|grep -v firmware/tunerstudio/rusefi.ini
 firmware/.gitignore                                                   |    7 +-
 firmware/config/engines/engines.mk                                    |    5 +-
 firmware/config/engines/mazda_z5.cpp                                  |   75 ++++++
 firmware/config/engines/mazda_z5.h                                    |   21 ++
 firmware/controllers/algo/engine_configuration.cpp                    |    1 +
 firmware/controllers/algo/rusefi_enums.h                              |    6 +-
 firmware/controllers/trigger/decoders/trigger_mazda.cpp               |   41 +++
 firmware/controllers/trigger/decoders/trigger_mazda.h                 |    1 +
 firmware/controllers/trigger/trigger_decoder.cpp                      |    4 +
 35 files changed, 353 insertions(+), 6504 deletions(-)
this is the code:
i added the engine file to compile:

Code: Select all

diff --git a/firmware/config/engines/engines.mk b/firmware/config/engines/engines.mk
index 971c4af21..2ade3a6bb 100644
--- a/firmware/config/engines/engines.mk
+++ b/firmware/config/engines/engines.mk
@@ -44,3 +44,4 @@ ENGINES_SRC_CPP = $(PROJECT_DIR)/config/engines/ford_aspire.cpp \
 	$(PROJECT_DIR)/config/engines/honda_600.cpp \
-	$(PROJECT_DIR)/config/engines/ford_festiva.cpp
-	
\ No newline at end of file
+	$(PROJECT_DIR)/config/engines/ford_festiva.cpp \
+	$(PROJECT_DIR)/config/engines/mazda_z5.cpp 
+
there the engine:

Code: Select all

diff --git a/firmware/config/engines/mazda_z5.cpp b/firmware/config/engines/mazda_z5.cpp
new file mode 100644
index 000000000..f273c4ce8
--- /dev/null
+++ b/firmware/config/engines/mazda_z5.cpp
@@ -0,0 +1,75 @@
+/**
+ * @file	mazda_z5.cpp
+ *
+ * @date Nov 16, 2018
+ * @author Andrey Belomutskiy, (c) 2012-2018
+ * @author Alexander Wilhelmi, (c) 2018
+ */
+
+#include "mazda_z5.h"
+#include "settings.h"
+#include "allsensors.h"
+#include "engine_math.h"
+#include "rusefi_enums.h"
+
+void setMazda_z5_EngineConfiguration(engine_configuration_s *engineConfiguration, board_configuration_s *boardConfiguration) {
+
+        // Basic Setup
+	setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR);
+	engineConfiguration->engineType = MAZDA_Z5;
+	engineConfiguration->specs.cylindersCount = 4;
+	engineConfiguration->specs.displacement = 1.5;
+	engineConfiguration->specs.firingOrder = FO_1_3_4_2;
+	engineConfiguration->rpmHardLimit = 6500;
+
+        // Trigger
+	engineConfiguration->trigger.type = TT_MAZDA_Z5;
+
+
+	// Ignition 
+	engineConfiguration->ignitionMode = IM_ONE_COIL;
+
+
+	// Fuel
+	engineConfiguration->fuelAlgorithm = LM_PLAIN_MAF;
+	engineConfiguration->injector.flow = 180;
+	engineConfiguration->cranking.baseFuel = 2.5;
+
+
+	// stock sensors parameters
+	engineConfiguration->tpsMin = 80;
+	engineConfiguration->tpsMax = 764;
+	setCommonNTCSensor(&engineConfiguration->iat);
+	setThermistorConfiguration(&engineConfiguration->iat, -10, 30000, 9, 4000, 80, 240);
+	setCommonNTCSensor(&engineConfiguration->clt);
+	setThermistorConfiguration(&engineConfiguration->clt, -20, 20000, 20, 2400, 80, 600);
+
+
+	// boardconfig
+	engineConfiguration->clt.config.bias_resistor = 3300;
+	engineConfiguration->iat.config.bias_resistor = 3300;
+	boardConfiguration->ignitionPinMode = OM_INVERTED;
+
+	//wiring
+	boardConfiguration->triggerInputPins[0] = GPIOA_5; 
+	boardConfiguration->triggerInputPins[1] = GPIOC_6; 
+	engineConfiguration->tpsAdcChannel = EFI_ADC_5;
+	engineConfiguration->mafAdcChannel = EFI_ADC_3;
+	engineConfiguration->clt.adcChannel = EFI_ADC_1;
+	engineConfiguration->iat.adcChannel = EFI_ADC_2;
+	boardConfiguration->ignitionPins[0] = GPIOE_6;
+	boardConfiguration->ignitionPins[1] = GPIO_UNASSIGNED;
+	boardConfiguration->ignitionPins[2] = GPIO_UNASSIGNED;
+	boardConfiguration->ignitionPins[3] = GPIO_UNASSIGNED;
+	boardConfiguration->injectionPins[0] = GPIOB_9;
+	boardConfiguration->injectionPins[1] = GPIOD_5;
+	boardConfiguration->injectionPins[2] = GPIOB_8;
+	boardConfiguration->injectionPins[3] = GPIOB_7;
+	boardConfiguration->injectionPins[4] = GPIO_UNASSIGNED;
+	boardConfiguration->injectionPins[5] = GPIO_UNASSIGNED;
+	boardConfiguration->fanPin = GPIOE_6;
+	boardConfiguration->o2heaterPin = GPIOC_3;
+	boardConfiguration->fuelPumpPin = GPIOC_13;
+	boardConfiguration->idle.solenoidPin = GPIOE_4;
+        engineConfiguration->brakePedalPin = GPIOA_7;
+}
engine header

Code: Select all

diff --git a/firmware/config/engines/mazda_z5.h b/firmware/config/engines/mazda_z5.h
new file mode 100644
index 000000000..8e3d9f300
--- /dev/null
+++ b/firmware/config/engines/mazda_z5.h
@@ -0,0 +1,21 @@
+/**
+ * @file	mazda_z5.h
+ *
+ * 94-2000 Mazda 323 (1.5l DOHC)
+ *
+ * https://rusefi.com/forum/viewtopic.php?f=3&t=1441
+ *
+ *
+ * @date Nov 16, 2018
+ * @author Andrey Belomutskiy, (c) 2012-2017
+ * @author Alexander Wilhelmi, (c) 2018
+ */
+
+#ifndef MAZDA_Z5_H_
+#define MAZDA_Z5_H_
+
+#include "engine.h"
+
+void setMazda_z5_EngineConfiguration(engine_configuration_s *engineConfiguration);
+
+#endif /* MAZDA_Z5_H_ */
include it here:

Code: Select all

diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp
index 32c983ebb..e3886955d 100644
--- a/firmware/controllers/algo/engine_configuration.cpp
+++ b/firmware/controllers/algo/engine_configuration.cpp
@@ -61,2 +61,3 @@
 #include "mazda_626.h"
+#include "mazda_z5.h"

need enums for engine and trigger type

Code: Select all

diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h
index 3804ed1e2..ed5e2ba80 100644
--- a/firmware/controllers/algo/rusefi_enums.h
+++ b/firmware/controllers/algo/rusefi_enums.h
@@ -177,2 +177,4 @@ typedef enum {
 
+	MAZDA_Z5 = 57,
+
 	PROMETHEUS_DEFAULTS = 100,
@@ -290,3 +292,5 @@ typedef enum {
 
-	TT_UNUSED = 42, // this is used if we want to iterate over all trigger types
+	TT_MAZDA_Z5 = 42,
+
+	TT_UNUSED = 43, // this is used if we want to iterate over all trigger types
 
I coded the trigger, after measuring it and denoising the values with japnese sword.
TriggerShape header file had nice doc in it.
If i enable this trigger with

Code: Select all

set trigger_type 42 
i get many of these: EngineState: FATAL error: invalid switchTimes @0: 0.00/0.00

Code: Select all

diff --git a/firmware/controllers/trigger/decoders/trigger_mazda.cpp b/firmware/controllers/trigger/decoders/trigger_mazda.cpp
index f5b79639f..4c7550211 100644
--- a/firmware/controllers/trigger/decoders/trigger_mazda.cpp
+++ b/firmware/controllers/trigger/decoders/trigger_mazda.cpp
@@ -51,2 +51,43 @@ void initializeMazdaMiataNaShape(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX
 }
+void initialize_Mazda_Engine_z5_Shape(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX) {
+	s->initialize(FOUR_STROKE_CAM_SENSOR, true);
+	/**
+	 * My Signal is:      60,      60,      102,     60
+	 *               120,     120,     120,      78,
+	 *                                              ^  
+	 *                                              |
+	 *                                              sync point = 0 degree from now on 
+	 * All rising edges are 60 befor some OT.
+	 * If the edge goes high, it should look at the last past 2 events. (high-low-now)
+	 * time1/time2 == 78/102 = 13/17 then triggerevent '0' would be nice.
+	 * 
+	 */
+	s->useRiseEdge = true; 
+        s->gapBothDirections = true;
+	s->useOnlyPrimaryForSync = true;
+        /*
+	 * 60 or 420
+	 */
+	s->tdcPosition = 60;
+	s->setTriggerSynchronizationGap(0.9);  // because the gab is 0.9 shorter than the others befor rising edge
+        s->setSecondTriggerSynchronizationGap(1.1); // because the gab is 1.1 longer than the others befor falling edge
+
+	s->isSynchronizationNeeded = true; // would not explode if not
+        s->invertOnAdd = false;
+	/**
+	 * Total count of shaft events per CAM or CRANK shaft revolution.
+	 */
+        s->size = 8;
+	s->addEvent2(60.0f,   T_PRIMARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
+	s->addEvent2(180.0f,  T_PRIMARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);
+
+	s->addEvent2(240.0f,  T_PRIMARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
+	s->addEvent2(360.0f,  T_PRIMARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);
+
+	s->addEvent2(420.0f,  T_PRIMARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
+	s->addEvent2(540.0f,  T_PRIMARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);
+
+	s->addEvent2(618.0f,  T_PRIMARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
+	s->addEvent2(720.0f,  T_PRIMARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);
+}
here i found a place to add trigger shape

Code: Select all

diff --git a/firmware/controllers/trigger/decoders/trigger_mazda.h b/firmware/controllers/trigger/decoders/trigger_mazda.h
index d1423f439..786329242 100644
--- a/firmware/controllers/trigger/decoders/trigger_mazda.h
+++ b/firmware/controllers/trigger/decoders/trigger_mazda.h
@@ -21,2 +21,3 @@ void configureMazdaProtegeSOHC(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX);
 void configureMazdaProtegeLx(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX);
+void initialize_Mazda_Engine_z5_Shape(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX);

and here some decoder adding

Code: Select all

diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp
index 75bbb9e1b..c59526f57 100644
--- a/firmware/controllers/trigger/trigger_decoder.cpp
+++ b/firmware/controllers/trigger/trigger_decoder.cpp
@@ -497,2 +497,6 @@ void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMET
 
+	case TT_MAZDA_Z5:
+		initialize_Mazda_Engine_z5_Shape(this PASS_ENGINE_PARAMETER_SUFFIX);
+		break;
+
 	case TT_MIATA_VVT:
i also did a git diff for the java console dir

Code: Select all

➤ git diff --stat origin/master java_console |grep -v '.fish'|grep -v '.gitignore'
 java_console/build.xml                             |    8 +-
 java_console/io/src/com/rusefi/TsPageSize.java     |    5 +
 java_console/legal/rusefi_console_legal.txt        |    5 -
 java_console/lib/jlatexmath-1.0.3.jar              |  Bin 0 -> 1014482 bytes
 .../models/src/com/rusefi/config/Fields.java       | 1920 --------------------
 java_console/rusefi.xml                            |  240 ---
 7 files changed, 12 insertions(+), 2170 deletions(-)
The java console / some crc test failed without the following mod.
Here the change for java console build.xml ... i think this is not the right solution

Code: Select all

diff --git a/java_console/build.xml b/java_console/build.xml
index 0dbc78f74..90300de6e 100644
--- a/java_console/build.xml
+++ b/java_console/build.xml
@@ -20,10 +20,10 @@
             <src path="tools/src"/>
         </javac>

-        <junit fork="no"
-               maxmemory="512m"
+        <junit fork="yes"
+               maxmemory="4G"
                printsummary="yes"
-               haltonfailure="yes">
+               haltonfailure="no">

             <jvmarg value="-ea"/>
             <jvmarg value="-XX:+HeapDumpOnOutOfMemoryError"/>
@@ -102,4 +102,4 @@
         </copy>

     </target>
-</project>
\ No newline at end of file
+</project>
This is the order i did things
  • git status # my master is clean
  • git log #check if origin is update
  • git diff --stat=300 origin/master java_console firmware |grep -v '.fish'|grep -v 'generated'|grep -v firmware/tunerstudio/rusefi.ini|grep -v java_console/io/src/com/rusefi/TsPageSize.java ## check what in my branch diffs from origin, excluding autogen stuff.
  • enter firmware dir
  • export "PATH=/tmp/gcc-arm-none-eabi-7-2018-q2-update/bin:/usr/bin:/bin:/usr/sbin:/sbin/";make clean;./gen_enum_to_string.bat.fish;./gen_config.bat.fish;make -j16
  • st-flash (texane version) some params ... flash verify ok , blue led on and flashing. Cool thing! it compiles. I get high from this :-)
  • enter java console dir
  • ant
  • java -jar ../java_console_binary/rusefi_console.jar
Many thanks for any help.
Last edited by alexander-n8hgeg5e on Wed Nov 21, 2018 6:26 pm, edited 2 times in total.
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

  • one thing i discovered... i have wrong function definiton in the engine header.
  • java_console builds now with only this change. crc test work so.
  • found out in mazda_z5.cpp has to be a extern; statement... upsi

Code: Select all

-        <junit fork="no"
-               maxmemory="512m"
+        <junit fork="yes"
+               maxmemory="4G"
Last edited by alexander-n8hgeg5e on Wed Nov 21, 2018 10:17 pm, edited 5 times in total.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: how to code engine and trigger setup properly

Post by AndreyB »

Can you please attach all changes as one patch text file?

Did you create your own github fork? Do you want to commit into your public personal fork or create a pull request on github?
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

_
Last edited by alexander-n8hgeg5e on Wed Nov 21, 2018 9:52 pm, edited 1 time in total.
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

russian wrote:
Wed Nov 21, 2018 9:13 pm
Can you please attach all changes as one patch text file?
Did you create your own github fork? Do you want to commit into your public personal fork or create a pull request on github?
I can do whatever is best. I think i apply it to a fork.

here is it cleaned up other stuff. but,... not working... yet
(stat ist git diff --stat, for shorter view)
now the patches are on up-to-date commit and only the files that are for the z5 engine
mazda_z5_not_working.stat.txt
(563 Bytes) Downloaded 584 times
mazda_z5_not_working.patch.txt
(8.97 KiB) Downloaded 589 times
applied on github fork , branch: originmaster
git@github.com:alexander-n8hgeg5e/rusefi.git
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: how to code engine and trigger setup properly

Post by AndreyB »

First issue I see is that you are manually setting "s->size = 8;" while "addEvent2()" actually increments this variable on it's own. Please remove "s->size = 8". I need to think how to hide this variable, I will maybe rename it to "privateSize". Do not want to use getSize() since method invocations are not free :(

Also how do you not get
{code}
Compiling engine_configuration.cpp
./controllers/algo/auto_generated_enums.cpp: In function 'const char* getEngine_type_e(engine_type_e)':
./controllers/algo/auto_generated_enums.cpp:11:7: error: enumeration value 'MAZDA_Z5' not handled in switch [-Werror=switch]
switch(value) {
^
./controllers/algo/auto_generated_enums.cpp: In function 'const char* getTrigger_type_e(trigger_type_e)':
./controllers/algo/auto_generated_enums.cpp:153:7: error: enumeration value 'TT_MAZDA_Z5' not handled in switch [-Werror=switch]
switch(value) {
^
./controllers/trigger/trigger_central.cpp:240:27: warning: always_inline function might not be inlinable [-Wattributes]
{code}

while compiling?

Last but not least. Do you want your engine configuration in the public main repo or only your trigger decoder code? Can you create a separate PR for ONLY the trigger change without the decoder? Worst case scenario I can commit under my user manually picking pieces of your change.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

russian wrote:
Wed Nov 21, 2018 11:40 pm
First issue I see is that you are manually setting "s->size = 8;" while "addEvent2()" actually increments this variable on it's own. Please remove "s->size = 8". I need to think how to hide this variable, I will maybe rename it to "privateSize". Do not want to use getSize() since method invocations are not free :(
ok cool i fix, it .
Also how do you not get..
I deleted controllers/algo/auto_generated_enums.cpp to check it.
then i compiled with

Code: Select all

export "PATH=/tmp/gcc-arm-none-eabi-7-2018-q2-update/bin:/usr/bin:/bin:/usr/sbin:/sbin/";make clean;./gen_enum_to_string.bat.fish;./gen_config.bat.fish;make -j16
so i do a gen_enum... and a gen_config... the file gets regenerated.
then i got an error , but one that i had befor.

Code: Select all

Compiling auto_generated_enums.cpp
./controllers/algo/auto_generated_enums.cpp:8:10: fatal error: main.h: No such file or directory
 #include "main.h"
I remembered i fixed something by changeing main.h to global.h but forget where. I will figure out.
update: i can find out with my git , because the other branch compiles with the same command.... on the hunt
I think i got it.
I think all tools have to be recompiled and all the autogenerated stuff deleted.
If i do it with the following commands it works. main.h will be global.h
the script contains delete command "rm ..." so i post it here as seperate commands.

Code: Select all

#i do:
git checkout github/originmaster
git diff github/originmaster
#output of diff noting, everything clean. except .gitignore stuff can hide i think.
# basically i ignored the files that will be deleted below.
# So nothing else shoutld be there.
# i enter firmware dir
make clean
cd ..
rm firmware/controllers/algo/auto_generated_enums.cpp
rm firmware/controllers/algo/auto_generated_enums.h
rm firmware/controllers/algo/engine_configuration_generated_structures.h
rm firmware/tunerstudio/rusefi.ini
rm java_console/models/src/com/rusefi/config/Fields.java
cd java_tools/enum_to_string
ant
cd ../..
cd java_tools/configuration_definition
ant
cd ../..
cd firmware
export "PATH=/tmp/gcc-arm-none-eabi-7-2018-q2-update/bin:/usr/bin:/bin:/usr/sbin:/sbin/"
./gen_enum_to_string.bat.fish
./gen_config.bat.fish
make -j16
I can do a fresh git clone to check for sure.
Last but not least. Do you want your engine configuration in the public main repo or only your trigger decoder code?
For me it is ok so or so. What you think its better for the rusefi code.
Can you create a separate PR for ONLY the trigger change without the decoder? Worst case scenario I can commit under my user manually picking pieces of your change.
I will seperate the things no prop.
Last edited by alexander-n8hgeg5e on Thu Nov 22, 2018 1:36 am, edited 4 times in total.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: how to code engine and trigger setup properly

Post by AndreyB »

Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

github link
Nice and fresh code as i like it, and todo deleted.
I think the name would have stopped me probably from manipulating it.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: how to code engine and trigger setup properly

Post by AndreyB »

alexander-n8hgeg5e wrote:
Thu Nov 22, 2018 12:20 am
I remembered i fixed something by changeing main.h to global.h but forget where. I will figure out.
so problem is while .java code for enum2string utility was fixed to generate "global.h" not "main.h", the pre-compiled .jar file in GIT was not updated

I've just fixed that and this should work better now - https://github.com/rusefi/rusefi/commit/0c5f31f5e53ea294ef9550a6683ddac903636cf2
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

trigger loads without errors . really cool :)
I will put a jumper wire on...
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: how to code engine and trigger setup properly

Post by AndreyB »

alexander-n8hgeg5e wrote:
Thu Nov 22, 2018 1:58 am
trigger loads without errors . really cool :)
I will take the trigger code pull request :)
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

russian wrote:
Thu Nov 22, 2018 2:01 am
alexander-n8hgeg5e wrote:
Thu Nov 22, 2018 1:58 am
trigger loads without errors . really cool :)
I will take the trigger code pull request :)
I splitted all things out to some ennumberated branches. originmaster1 2 3 4 till 6.
So you could pick them easily with git pull remote originmaster1 ...
I'm not sure how you intended to split them.
The trigger code is not tested if it works, the set engine_type does not load the settings, but the trigger loads at least.
here is the splitting:

Code: Select all

branch: originmaster1
 firmware/controllers/trigger/decoders/trigger_mazda.cpp | 41 +++++++++++++++++++++++++++++++++++++++++
 firmware/controllers/trigger/decoders/trigger_mazda.h   |  1 +
 2 files changed, 42 insertions(+)

branch: originmaster2
 firmware/controllers/trigger/trigger_decoder.cpp | 4 ++++
 1 file changed, 4 insertions(+)

branch: originmaster3
 firmware/controllers/algo/rusefi_enums.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

branch: originmaster4
 firmware/config/engines/engines.mk | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

branch: originmaster5
 firmware/controllers/algo/engine_configuration.cpp | 1 +
 1 file changed, 1 insertion(+)

branch: originmaster6
 firmware/config/engines/mazda_z5.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 firmware/config/engines/mazda_z5.h   | 21 +++++++++++++++++++++
 2 files changed, 101 insertions(+)

I first pushed the bug... 'size' corrected now.
I will try to make a pull request.
git hub dont want to do it somehow ...
Last edited by alexander-n8hgeg5e on Thu Nov 22, 2018 3:20 am, edited 1 time in total.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: how to code engine and trigger setup properly

Post by AndreyB »

I do not follow your proposal, this could be above my git skillset or just not right. I was thinking about a nice pull request which I would see on github which would allow me to just hit "merge" button and the code would be checked under your name.

Also have you notices the cool unit tests folder? One of the unit tests is trying to run all triggers. And it's failing at the moment

Code: Select all

ratio 0.50: current=59999 previous=120000

0: cur 0.50 expected from 0.67 to 1.12 error=1

1: cur 2.00 expected from 0.83 to 1.38 error=1

2: cur 0.50 expected from nan to 100000.00 error=1

3: cur 2.00 expected from nan to 100000.00 error=1

TT_MAZDA_Z5 isSynchronizationPoint=0 index=1004 SHAFT_PRIMARY_FALLING

nextTriggerEvent index=1005

feedSimulatedEvent: 4>5 primary 0>1 secondary 0>0

TT_MAZDA_Z5 event SHAFT_PRIMARY_RISING 90540000

ratio 2.00: current=120001 previous=59999

0: cur 2.00 expected from 0.67 to 1.12 error=1

1: cur 0.50 expected from 0.83 to 1.38 error=1

2: cur 2.00 expected from nan to 100000.00 error=1

3: cur 0.50 expected from nan to 100000.00 error=1

TT_MAZDA_Z5 isSynchronizationPoint=0 index=1005 SHAFT_PRIMARY_RISING

nextTriggerEvent index=1006

feedSimulatedEvent: 5>6 primary 1>0 secondary 0>0

TT_MAZDA_Z5 event SHAFT_PRIMARY_FALLING 90618000

ratio 0.65: current=78000 previous=120001

0: cur 0.65 expected from 0.67 to 1.12 error=1

1: cur 2.00 expected from 0.83 to 1.38 error=1

2: cur 0.50 expected from nan to 100000.00 error=1

3: cur 2.00 expected from nan to 100000.00 error=1

TT_MAZDA_Z5 isSynchronizationPoint=0 index=1006 SHAFT_PRIMARY_FALLING

nextTriggerEvent index=1007

feedSimulatedEvent: 6>7 primary 0>1 secondary 0>0

TT_MAZDA_Z5 event SHAFT_PRIMARY_RISING 90720000

ratio 1.31: current=102000 previous=78000

0: cur 1.31 expected from 0.67 to 1.12 error=1

1: cur 0.65 expected from 0.83 to 1.38 error=1

2: cur 2.00 expected from nan to 100000.00 error=1

3: cur 0.50 expected from nan to 100000.00 error=1

TT_MAZDA_Z5 isSynchronizationPoint=0 index=1007 SHAFT_PRIMARY_RISING

nextTriggerEvent index=1008

unit_test_warning: findTriggerZeroEventIndex() failed

Trigger error 42
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: how to code engine and trigger setup properly

Post by AndreyB »

Code: Select all

	s->setTriggerSynchronizationGap(0.9);  // because the gab is 0.9 shorter than the others befor rising edge
        s->setSecondTriggerSynchronizationGap(1.1); // because the gab is 1.1 longer than the others befor falling edge
this would not work well. Engine revolutions are not perfect so I set a range of values close to gap

Code: Select all

setTriggerSynchronizationGap3(0, syncRatio * 0.75f, syncRatio * 1.25f);
yours 0.9 and 1.1 are just too close, ranges would overlap. Your homework would be to implement validation code which would throw trigger definition error if trying to do this. https://github.com/rusefi/rusefi/issues/624
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

Github does not like me today. Maybe because i force updated a branch ...
Tried klicking all buttons...
The pull request is in work.
For now github wins.
I will try out these unit test.
Screenshot.png
Screenshot.png (67.45 KiB) Viewed 13213 times
what the picture says is not true. I checked on commandline...
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

russian wrote:
Thu Nov 22, 2018 3:27 am

Code: Select all

	s->setTriggerSynchronizationGap(0.9);  // because the gab is 0.9 shorter than the others befor rising edge
        s->setSecondTriggerSynchronizationGap(1.1); // because the gab is 1.1 longer than the others befor falling edge
this would not work well. Engine revolutions are not perfect so I set a range of values close to gap

Code: Select all

setTriggerSynchronizationGap3(0, syncRatio * 0.75f, syncRatio * 1.25f);
yours 0.9 and 1.1 are just too close, ranges would overlap. Your homework would be to implement validation code which would throw trigger definition error if trying to do this. https://github.com/rusefi/rusefi/issues/624
Ok, i need to think. I think I did not understand how it works. Is it so?: 0.9 is the Trigger Ratio , so this gets feed to setTriggerSynchronizationGap3,
and then the acceptable range is 0.675 to 1.125 . And if the ratio is in that range, -> triggerevent.
And the seconde trigger is an additional requirement. That was my image.
So 1.1 , -> 1.375 and 0.825 means the both ones overlap... Thats the thing ?
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: how to code engine and trigger setup properly

Post by AndreyB »

I am not thinking straight now. I am now not sure if what I said about ranges overlap in fact makes sense.

but considering the simplicity of the trigger I just do not see (based on experience and gut fill) why would we need two gaps to detect sync here.

On the other hand I am failing to change the code so that unit tests would fail and this really puzzles me.

also while looking for other "s->useRiseEdge = false;" (note how this is not a common case) I've found a scary "s->initialState[T_PRIMARY] = 1;" in configureNeon1995TriggerShape, not sure if this is relevant here or another corner case.


Probably does not matter but you want "s->initialize(FOUR_STROKE_CAM_SENSOR, false);" not true since second parameter is "bool needSecondTriggerInput"

You really need to get unit tests running otherwise I cannot image now would you test your trigger? With real hardware? That would be painful.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: how to code engine and trigger setup properly

Post by AndreyB »

Anyway, I got it to work :)

Code: Select all

/**
 * by alexander-n8hgeg5e
 * See https://rusefi.com/forum/viewtopic.php?f=5&t=1447
 */
void initialize_Mazda_Engine_z5_Shape(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX) {
	s->initialize(FOUR_STROKE_CAM_SENSOR, false);
	/**
	 * My Signal is:      60,      60,      102,     60
	 *               120,     120,     120,      78,
	 *                                              ^  
	 *                                              |
	 *                                              sync point = 0 degree from now on 
	 * All rising edges are 60 befor some OT.
	 * If the edge goes high, it should look at the last past 2 events. (high-low-now)
	 * time1/time2 == 78/102 = 13/17 then triggerevent '0' would be nice.
	 * 
	 */
	s->useRiseEdge = false;
	 // todo s->tdcPosition = 60; look at picture
	s->setTriggerSynchronizationGap(0.7);

	s->addEvent2(60.0f,   T_PRIMARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
	s->addEvent2(180.0f,  T_PRIMARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);

	s->addEvent2(240.0f,  T_PRIMARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
	s->addEvent2(360.0f,  T_PRIMARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);

	s->addEvent2(420.0f,  T_PRIMARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
	s->addEvent2(540.0f,  T_PRIMARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);

	s->addEvent2(618.0f,  T_PRIMARY, TV_FALL PASS_ENGINE_PARAMETER_SUFFIX);
	s->addEvent2(720.0f,  T_PRIMARY, TV_RISE PASS_ENGINE_PARAMETER_SUFFIX);
}
and here is the image https://rusefi.com/images/triggers/trigger_42.png

Please try to get a PR or I will later push this under my username if that's fine with you
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

russian wrote:
Thu Nov 22, 2018 4:18 am
Anyway, I got it to work :)
Really cool, makes me happy :) . Many Thanks. Can't wait to check it out.

Push it, I don't care about usernames (but the persons).
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

It's so cool! I can watch it in the javaconsole stimulating itself.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: how to code engine and trigger setup properly

Post by AndreyB »

alexander-n8hgeg5e wrote:
Thu Nov 22, 2018 3:02 pm
It's so cool!
"Building cool ECU, slowly but steadily" is our motto here.

Thank you for the PR! Just merged it and enum - https://github.com/rusefi/rusefi/commit/c77ab926c2b67eed8ae1aae8604ce9a3db7cb474 - some minor comments added

You still need to figure out the proper TDC position for this trigger.
Actually this remind me to add more comments https://github.com/rusefi/rusefi/commit/2fa22132270df3ccc15d94f9502a286f14c35a5e
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: how to code engine and trigger setup properly

Post by alexander-n8hgeg5e »

russian wrote:
Thu Nov 22, 2018 3:25 pm
You still need to figure out the proper TDC position for this trigger.
I will test everything out and give you a PR when it runs smoothly like it should.
Now I have learned to do PR's.
Post Reply