Extracting TargetTemperature value for a custom class
-
Hello everyone!
I need help with a small problem that I'm facing in my development project. I'm trying different methods and approches to overcome the problem but I haven't achieved to find a workaround yet and it's probably due to my lack of knowledge regarding DuetFirmware.
About my project:
I have STM32 nucleo board and I'm using it as a full duplex SPI slave to communicate with my Duet3 MB6HC board. I want to send temperature data to my Duet board that i generated on my Nucleo and in the meantime i want to get target temperature data that i typed in on Duet-Webserver.What i did so far:
I customised the ThermocoupleSensor31856 code in RepRapFirmware according to my needs and assigned my nucleo board as a heater to my tool. Currently i send temperature data to my Duet board and so far i can see the temp data on Webserver without a problem. But I want to read the target temperature from Duet board (Active or standby mode doesn't matter). Since i don't want to change the structure of the firmware so much, i want to keep everything in my customised Thermocouple class, if It's possible.ThermocoupleSensor31856 has Poll() function in it and it's been used for sending and receiving data from the sensor. I use this command below to send data to Duet board.
static uint8_t dataOut[4] = {0x0C, myTargetTemp, targettemp_a , targettemp_b}; // myTargetTemp is the data i want to get from Duet and send over SPI TemperatureError sts = DoSpiTransaction(dataOut, ARRAY_SIZE(dataOut), rawVal);
As simple enough, rawVal is what i receive from Nucleo board and dataOut is the array i send to Nucleo over SPI. After this, things get complicated.
i debugged and analysed the firmware as much as i can, and found couple of functions in which i can get the target temperature.
So far the best candidates that i can extract target temps are: Tool.cpp, Heat.cpp. and Reprap.cpp
I tried to do the same or similar ways to get the temp information just like how it is done in ReportToolTemperatures and SetToolHeaterActiveOrStandbyTemperature but no luck so far.
void RepRap::ReportToolTemperatures(const StringRef& reply, const Tool *tool, bool includeNumber) const noexcept { Doing Something... Heat& heat = reprap.GetHeat(); char sep = ':'; for (size_t i = 0; i < tool->HeaterCount(); ++i) { const int heater = tool->GetHeater(i); reply.catf("%c%.1f /%.1f", sep, (double)heat.GetHeaterTemperature(heater), (double)heat.GetTargetTemperature(heater)); sep = ' '; } } }
I also try to get the target temp value in Tool (since i just have 1 tool heater and 1 bed heater). I initiliased a public variable called myTargetTemp(in Tool.h) and implemented it like this:
void Tool::SetToolHeaterActiveOrStandbyTemperature(size_t heaterNumber, float temp, bool active) THROWS(GCodeException) { Doing Something... if (setHeater) { reprap.GetHeat().SetTemperature(heater, temp, active); // This is where the target temperature is actually passed on and set. myTargetTemp = temp; // Defined variable by me in Tool.h } } } }
Main idea was to write the targettemp (temp variable here) to my variable and call that variable in thermocouple class. But i just read "0" from my variable.
Another approach that i thought of was to implement a function like this in thermocouple class and call that function in Poll() to get the updated target variable and pass it into spi tx buffer.
void ThermocoupleSensor31856::TargetTempReceive() THROWS(GCodeException) { //ReadLocker lock(toolListLock); // Requires FreeRtos size_t i = 0; const Tool * const currentTool = reprap.GetCurrentTool(); Heat& heat = reprap.GetHeat(); if(currentTool != nullptr){ i = 0; int heater = currentTool->GetHeater(i); targettemp_a = (uint8_t)heat.GetTargetTemperature(heater); // my 1. variable to read throw GCodeException(-1, -1, "I throw error here in i=0"); i = 1; heater = currentTool->GetHeater(i); targettemp_b = (uint8_t)heat.GetTargetTemperature(heater); // my 2. variable to read throw GCodeException(-1, -1, "I throw error here in i=1"); } }
GCodeExceptions are there to understand if the currentTool is initialised or not because i was getting again zeros. And i noticed currentTool pointer was always a nullptr. There is definetly something here that i cannot get the addresses from GetCurrentTool() function.
One other thing: I tried to implement something like this in Poll() function:
targettemp_a = (uint8_t)reprap.GetCurrentTool()->GetToolHeaterActiveTemperature(i);
But with this line unfornately, whenever Duetboard tries to start up, the spi communication restarts itself and forces the board to initialise/boot up again and again.
This is all i tried so far, except for small things here and there.
Anyways, I tried to explain everything as much as possible. I hope it's enough to give you a rough idea what I'm trying to do. I can provide you with more information if it's needed. But from what i experienced, Im guessing I'm forgetting something very obvious in regard to firmware itself. Maybe forgetting something about pointers or maybe messing with the Rtos in a bad way but im out of ideas for now.If there is a way or a workaround that i can use, it would be a great help!
-
-
So after going through all the code, i notice i dont need an extra variable to save target temp into. It seems reprap object has its on gettargettemp/getactivetemp within itself. After implementing just one line of code like this:
targettemp = reprap.GetHeat().GetTargetTemperature(i); // i is the heaternumber
I was able to read the active and standby temperatures just fine. I'm writing here this so that if anyone needs help regarding the issue can see it.
Thank you all for reading!
-
-
@KOlasmics I'm glad you found a solution!