Automatic checking and programming of the ESC configuration

Post Reply
PeterPilot
Posts: 19
Joined: Fri Jun 17, 2011 10:08 am

Automatic checking and programming of the ESC configuration

Post by PeterPilot »

Hi folks!

I found a very interesting article about programming turnigy compatible ESCs via an ATmega328P running at 12 MHz.
http://frank.circleofcurrent.com/cache/escprogrammingcardhack.htm
In the MultiWii-Project most of us use the same Processor, but at 16 MHz.
My programming-knowledge ends when it gets to close to bitshifting and hardware-timers, but I hope someone of you could translate the code for our Arduino-Board.

My intention is to do something like that:
- the intended esc config shall be configurable in the MultiWii Sketch (Brake:off, Battery-Type:Ni-xx, Cut-off-Type:Soft-Cut, Cut-off-Voltage:Low, Start-Mode:Normal, Timing-Mode:High, Governor-Mode:OFF)
- there should be a switch in the eeprom like "programm_esc_config"
- if it is set to "1" (via a button in the config-tool or manually when uploading the sketch) then write the ESC config on the next power-up
- reset eeprom switch to "0"

Another feature worth a thought is the calibration of the trottle-range, but I am not sure how to include this in the process.

The ESCs also send their current config to the programming-card so it should also be possible to check the current config with the arduino and rewrite it only when it differs from the intended config. With this it could be possible to automate the whole process and the user can be sure the ESCs are perfectly programmed at every flight.

I am going to donate 15€ (as a little motivation-help ;) ) to the one who adapts the code to our arduino pro mini and shows me a way to integrate it in the MultiWii-Code.

Best regards,
Peter

frank26080115
Posts: 26
Joined: Mon Jul 11, 2011 12:47 pm

Re: Automatic checking and programming of the ESC configurat

Post by frank26080115 »

That's my website, I wrote that code

You should be able to copy and paste almost all of that code into the Arduino IDE and it should work, maybe you need to change the "_delay_us" into "delayMicroseconds", the clock speed difference should be taken care of automatically at compile time

You need to put the Arduino into a state in which it waits for a pending ESC connection, this should be done from the MultiWii GUI somehow, the function "TPC_read_init" will put the Arduino into a wait mode until the ESC has connected. Currently this function blocks the thread completely. After the function returns, then you may edit the data structure and call "TPC_send_config", if it returns, then the operation should have successfully completed.

To calibrate throttle range, the code needs to set all throttle to highest first, and then provide the user with a button, when the button is pressed, all the throttle should go to the lowest value. AeroQuad already has this feature.

PeterPilot
Posts: 19
Joined: Fri Jun 17, 2011 10:08 am

Re: Automatic checking and programming of the ESC configurat

Post by PeterPilot »

Hi Frank,

thanks for your reply! When trying to compile the code with the Arduino IDE I get a bunch of errors:

ESC_Config:18: error: variable or field 'TPC_loadDefault' declared void
ESC_Config:18: error: 'TPC_settings_t' was not declared in this scope
ESC_Config:18: error: 'x' was not declared in this scope
ESC_Config:19: error: variable or field 'TPC_word_to_struct' declared void
ESC_Config:19: error: 'TPC_settings_t' was not declared in this scope
ESC_Config:19: error: 'x' was not declared in this scope
ESC_Config:19: error: expected primary-expression before 'unsigned'
ESC_Config:20: error: 'TPC_settings_t' was not declared in this scope
ESC_Config:20: error: 'x' was not declared in this scope
ESC_Config:25: error: variable or field 'TPC_read_init' declared void
ESC_Config:25: error: 'TPC_settings_t' was not declared in this scope
ESC_Config:25: error: 'x' was not declared in this scope
ESC_Config:26: error: variable or field 'TPC_send_config' declared void
ESC_Config:26: error: 'TPC_settings_t' was not declared in this scope
ESC_Config:26: error: 'x' was not declared in this scope
ESC_Config.cpp: In function 'void TPC_word_to_struct(TPC_settings_t*, short unsigned int)':
ESC_Config:111: error: invalid conversion from 'unsigned int' to 'TPC_cutoffVoltage_t'
ESC_Config:112: error: invalid conversion from 'unsigned int' to 'TPC_startMode_t'
ESC_Config:113: error: invalid conversion from 'unsigned int' to 'TPC_timingMode_t'
ESC_Config:114: error: invalid conversion from 'unsigned int' to 'TPC_lipoCells_t'
ESC_Config.cpp: In function 'short unsigned int TPC_struct_to_word(TPC_settings_t*)':
ESC_Config:119: error: 'short unsigned int TPC_struct_to_word(TPC_settings_t*)' redeclared as different kind of symbol
ESC_Config:20: error: previous declaration of 'short unsigned int TPC_struct_to_word'
ESC_Config.cpp: In function 'void TPC_send_config(TPC_settings_t*)':
ESC_Config:238: error: 'TPC_struct_to_word' cannot be used as a function
ESC_Config.cpp: At global scope:
ESC_Config:270: error: expected primary-expression before '.' token
ESC_Config:270: error: expected primary-expression before '.' token
ESC_Config:270: error: expected primary-expression before '.' token
ESC_Config:270: error: expected primary-expression before '.' token
ESC_Config.cpp: In function 'int main()':
ESC_Config:292: error: invalid conversion from 'volatile TPC_settings_t*' to 'TPC_settings_t*'
ESC_Config:292: error: initializing argument 1 of 'void TPC_read_init(TPC_settings_t*)'
ESC_Config:295: error: 'TPC_struct_to_word' cannot be used as a function
ESC_Config:300: error: invalid conversion from 'int' to 'TPC_battType_t'
ESC_Config:301: error: invalid conversion from 'int' to 'TPC_cutoffType_t'
ESC_Config:302: error: invalid conversion from 'int' to 'TPC_cutoffVoltage_t'
ESC_Config:303: error: invalid conversion from 'int' to 'TPC_startMode_t'
ESC_Config:304: error: invalid conversion from 'int' to 'TPC_timingMode_t'
ESC_Config:305: error: invalid conversion from 'int' to 'TPC_lipoCells_t'
ESC_Config:307: error: 'TPC_struct_to_word' cannot be used as a function
ESC_Config:314: error: invalid conversion from 'volatile TPC_settings_t*' to 'TPC_settings_t*'
ESC_Config:314: error: initializing argument 1 of 'void TPC_send_config(TPC_settings_t*)'

I don't know how to make it work. I understand the basic structure of the code, but I am not able to convert it to Arduinio-Code.
Thats why I offered the 15€ because it my not be a complicate job for someone with adequate programming skills and could be probably done within a few minutes.

As soon as the code runs on the Arduino I think I will be able to go the further steps alone.

Best regards,
Peter

PeterPilot
Posts: 19
Joined: Fri Jun 17, 2011 10:08 am

Re: Automatic checking and programming of the ESC configurat

Post by PeterPilot »

Now I have broken down the errors to their origin.

The problems I cannot solve are all related to the following typedef:

Code: Select all

typedef struct TPC_settings_t_
{
   char brake;
   enum TPC_battType_t battType;
   enum TPC_cutoffType_t cutoffType;
   enum TPC_cutoffVoltage_t cutoffVoltage;
   enum TPC_startMode_t startMode;
   enum TPC_timingMode_t timingMode;
   enum TPC_lipoCells_t lipoCells;
   char governorMode;
   
} TPC_settings_t;


The typedef itself is compilable but as soon as I try to use the typedef the sketch is no longer compilable.
So there has to be a error for example in this function:

Code: Select all

// initializes the settings to default values
void TPC_loadDefault(TPC_settings_t* x)
{
   x->brake = 0;
   x->battType = TPC_battType_Ni;
   x->cutoffType = TPC_cutoffType_softCut;
   x->cutoffVoltage = TPC_cutoffVoltage_low;
   x->startMode = TPC_startMode_normal;
   x->timingMode = TPC_timingMode_high;
   x->lipoCells = TPC_lipoCells_autoDetect;
   x->governorMode = 0;
}


I don't know the right syntax. Please help!

Best regards,
Peter

frank26080115
Posts: 26
Joined: Mon Jul 11, 2011 12:47 pm

Re: Automatic checking and programming of the ESC configurat

Post by frank26080115 »

try this... http://frank.circleofcurrent.com/files/ ... 110711.zip , the TurnigyProgrammingCard.h file needs to be edited with the correct pin definitions before you start

PeterPilot
Posts: 19
Joined: Fri Jun 17, 2011 10:08 am

Re: Automatic checking and programming of the ESC configurat

Post by PeterPilot »

Hi Frank,

ok I tried the library you posted and implemented it in the MultiWii-Sketch.
I edited the Pin-Mapping to Pin 3 (Front-motor-esc) to test the sketch. At first it worked and the startup speed was set to "very slow" . Then I tried to go a step further and use a variable for the pin-number and from that point on nothing worked... So I went back to the starting point but even that didn't help....
It's a miracle...
In the end I had to use the programming-card to reset the ESC...

Are there any requirements or timings I should pay attention to?

Best Regards,
Peter

refractions
Posts: 92
Joined: Thu Dec 01, 2011 8:55 pm
Location: Scotter, Lincolnshire, UK

Re: Automatic checking and programming of the ESC configurat

Post by refractions »

Hi, Did you get any further with this? Just starting to play with the idea myself.

Many thanks

iain

bicycle
Posts: 27
Joined: Sun May 06, 2012 4:58 am

Re: Automatic checking and programming of the ESC configurat

Post by bicycle »

I can revitalize this topic. I have a 6a Pentium esc with SIL chip that couldn't be programmed by stick movements. I have an Arduino Diecimila so I downloaded the zip file posted earlier. It needed to be updated a bit but I used the library. It seemed to write OK but as I do not have a programming card I had to verify my efforts by listening carefully to the motor. There is a definite problem in the value that delays between reads. Ones read double all the time, and zeroes read double 1/4 the time. This makes it even more difficult to verify programming! I could set this value as low as 1500us and as high as 3000us with varying levels of success. I eventually got the programming I wanted, once I figured out the error was consistent, so I let it be. Anyway the code works with a bunch of tweaking. Saved me $4.

Post Reply