Lil' Blackbox

Coding => v1.0 - v1.1 => Topic started by: hakcenter on July 27, 2015, 10:41:54 PM

Title: Accel Variable
Post by: hakcenter on July 27, 2015, 10:41:54 PM
I'm trying not to butcher up me's thread.. so

I've been working on this variable for the last day.. finally got some time to sit down today and simulate rpm at constant rates and come up with actual working math.

Can't multiply that was totally wrong... lol. So far I'm at this


if (timer % 10 == 0) {
    turbo_accel[2] = (turbo_rpm - last_turbo_rpm) / 10;
    last_turbo_rpm = turbo_rpm;
  }

Time it takes to compute

60uS
16uS
16uS
20uS
20uS
16uS
16uS
16uS
16uS
20uS
60uS


vs some bitwise with 32ms average, polling at 16ms


if (timer % 2 == 0) {
    if (accel_timer == 8) {
      if (alternate_accel) {
        turbo_accel[0] = (turbo_rpm - last_turbo_rpm) >> 4;
        alternate_accel = false;
      } else {
        turbo_accel[1] = (turbo_rpm - last_turbo_rpm) >> 4;
        alternate_accel = true;
      }
      turbo_accel[2] = (turbo_accel[0] + turbo_accel[1]) >> 1;
      last_turbo_rpm = turbo_rpm;
    }
    accel_timer++;
    if (accel_timer > 8) { accel_timer = 1; }
  }

Time it takes to compute

12uS
4uS
4uS
4uS
4uS
4uS
4uS
4uS
8uS
4uS
4uS
4uS
4uS
4uS
4uS
4uS
12uS


thoughts ?
Title: Re: Accel Variable
Post by: hakcenter on July 28, 2015, 10:17:12 PM
Required setup changes


// Turbo
int minimum_turbo_rpm = 1000;
long turbo_rpm = 0;
long last_turbo_rpm = 0;
int turbo_accel[3] = { 0,0,0 };

// Timer2 Variables
unsigned int timer = 0;
boolean alternate_accel = false;
byte accel_timer = 0;
boolean update_vane_position = false;


changing rpm from unsigned, to basically signed, so math can go negative... argh annoying to try to figure that out.


  else if (timer % 50 == 0) { update_vane_position = true; }
  // Update turbo_accel before calculating vane_position
  if (timer % 2 == 0) {
    if (accel_timer == 8) {
      if (alternate_accel) {
        turbo_accel[0] = (turbo_rpm - last_turbo_rpm) >> 4;
        alternate_accel = false;
      } else {
        turbo_accel[1] = (turbo_rpm - last_turbo_rpm) >> 4;
        alternate_accel = true;
      }
      turbo_accel[2] = (turbo_accel[0] + turbo_accel[1]) >> 1;
      last_turbo_rpm = turbo_rpm;
    }
    accel_timer++;
    if (accel_timer > 8) { accel_timer = 1; }
  }
  // Modes
  if (timer % 100 == 0) { calculate_modes(); }


^ def the way to calc it at super fast rates... hopefully its a useful variable
Title: Re: Accel Variable
Post by: Rx7man on July 29, 2015, 11:14:02 AM
I think it will be useful :)
Title: Re: Accel Variable
Post by: hakcenter on August 16, 2015, 10:47:56 AM
Updating it to
Variables

// Turbo
unsigned int minimum_turbo_rpm = 1000;
long turbo_rpm = 0;
long last_turbo_rpm[2] = { 0,0 };
int turbo_accel[3] = { 0,0,0 };

// Timer2 Variables
unsigned int timer = 0;
boolean update_vane_position = false;

Code

  if (timer % 10 == 0) {
    // Division by 10
    turbo_accel[0] = ((turbo_rpm - last_turbo_rpm[0]) * 205) >> 11;
    last_turbo_rpm[0] = turbo_rpm;
    if (timer % 100 == 0) {
      // Division by 100
      turbo_accel[1] = ((turbo_rpm - last_turbo_rpm[1]) * 164) >> 14;
      last_turbo_rpm[1] = turbo_rpm;
    }
    if (turbo_rpm < top_end_rpm) { turbo_accel[2] = turbo_accel[1]; } else { turbo_accel[2] = turbo_accel[0]; }
  }


I was poking around at it, and it didn't seem to do exactly what I wanted, especially in the transition from 100ms > 10ms serial output. It could only be 10ms and still be accurate but it won't necessarily reflect the rpm changes that you see.. I'll probably refine it one more time with a good drive but wanted to make note of it here and update the common code to reflect the small changes.
Title: Re: Accel Variable
Post by: hakcenter on August 17, 2015, 02:57:47 PM
Accel variable seems to be working as expected now. Probably going to use it for tuning the top end curve. I've noticed that shaft speed acceleration peters out depending on where you tuned it.

I was tuning it for 3rd gear, and it barely reaches into 130k land and creeps back, but once I'm in 4th or higher, I can't get over 125k, so I'll probably tune the curve in my highest gear, then relate turbo acceleration > 50rpm/ms goto a bigger vane position.. something like that
Title: Re: Accel Variable
Post by: hakcenter on August 17, 2015, 04:26:41 PM
Here's my 3rd gear

CPOS : 740 | APOS : 740 | RPM :  37560 | Accel :    0 | Mode : Normal | 159
CPOS : 740 | APOS : 741 | RPM :  37620 | Accel :    0 | Mode : Normal | 157
CPOS : 739 | APOS : 741 | RPM :  37740 | Accel :    1 | Mode : Normal | 156
CPOS : 740 | APOS : 740 | RPM :  37260 | Accel :   -5 | Mode : Normal | 156
CPOS : 739 | APOS : 740 | RPM :  38040 | Accel :    7 | Mode : Normal | 156
CPOS : 739 | APOS : 740 | RPM :  37740 | Accel :   -4 | Mode : Normal | 152
CPOS : 739 | APOS : 739 | RPM :  38340 | Accel :    6 | Mode : Normal | 158
CPOS : 737 | APOS : 738 | RPM :  39480 | Accel :   11 | Mode : Normal | 158
CPOS : 736 | APOS : 737 | RPM :  39900 | Accel :    4 | Mode : Normal | 159
CPOS : 737 | APOS : 736 | RPM :  39780 | Accel :   -2 | Mode : Normal | 148
CPOS : 736 | APOS : 736 | RPM :  40140 | Accel :    3 | Mode : Normal | 162
CPOS : 735 | APOS : 735 | RPM :  40740 | Accel :    6 | Mode : Normal | 160
CPOS : 733 | APOS : 733 | RPM :  42540 | Accel :   18 | Mode : Normal | 155
CPOS : 733 | APOS : 732 | RPM :  42480 | Accel :   -1 | Mode : Normal | 156
CPOS : 732 | APOS : 732 | RPM :  42720 | Accel :    2 | Mode : Normal | 162
CPOS : 730 | APOS : 732 | RPM :  44220 | Accel :   15 | Mode : Normal | 161
CPOS : 729 | APOS : 729 | RPM :  45060 | Accel :    8 | Mode : Normal | 162
CPOS : 728 | APOS : 729 | RPM :  45780 | Accel :    7 | Mode : Normal | 166
CPOS : 726 | APOS : 728 | RPM :  46800 | Accel :   10 | Mode : Normal | 162
CPOS : 724 | APOS : 726 | RPM :  48300 | Accel :   15 | Mode : Normal | 163
CPOS : 722 | APOS : 722 | RPM :  50040 | Accel :   17 | Mode : Normal | 166
CPOS : 719 | APOS : 722 | RPM :  52140 | Accel :   21 | Mode : Normal | 177
CPOS : 716 | APOS : 717 | RPM :  54180 | Accel :   20 | Mode : Normal | 189
CPOS : 713 | APOS : 714 | RPM :  56280 | Accel :   21 | Mode : Normal | 203
CPOS : 710 | APOS : 712 | RPM :  58260 | Accel :   19 | Mode : Normal | 193
CPOS : 707 | APOS : 709 | RPM :  60120 | Accel :   18 | Mode : Normal | 213
CPOS : 705 | APOS : 707 | RPM :  61620 | Accel :   15 | Mode : Normal | 206
CPOS : 703 | APOS : 704 | RPM :  63300 | Accel :   16 | Mode : Normal | 205
CPOS : 699 | APOS : 700 | RPM :  65940 | Accel :   26 | Mode : Normal | 196
CPOS : 692 | APOS : 693 | RPM :  69480 | Accel :   35 | Mode : Normal | 204
CPOS : 682 | APOS : 685 | RPM :  74280 | Accel :   48 | Mode : Normal | 212
CPOS : 672 | APOS : 675 | RPM :  79200 | Accel :   49 | Mode : Normal | 220
CPOS : 662 | APOS : 664 | RPM :  84420 | Accel :   52 | Mode : Normal | 226
CPOS : 651 | APOS : 654 | RPM :  89760 | Accel :   53 | Mode : Normal | 219
CPOS : 640 | APOS : 642 | RPM :  95340 | Accel :   55 | Mode : Normal | 238
CPOS : 627 | APOS : 630 | RPM : 101940 | Accel :   66 | Mode : Normal | 253
CPOS : 620 | APOS : 623 | RPM : 105120 | Accel :   54 | Mode : Normal | 131
CPOS : 619 | APOS : 620 | RPM : 105960 | Accel :   84 | Mode : Normal | 23
CPOS : 618 | APOS : 619 | RPM : 106620 | Accel :   66 | Mode : Normal | 27
CPOS : 617 | APOS : 618 | RPM : 107520 | Accel :   90 | Mode : Normal | 24
CPOS : 616 | APOS : 617 | RPM : 108060 | Accel :   54 | Mode : Normal | 28
CPOS : 615 | APOS : 616 | RPM : 108780 | Accel :   72 | Mode : Normal | 24
CPOS : 614 | APOS : 615 | RPM : 109800 | Accel :  102 | Mode : Normal | 31
CPOS : 613 | APOS : 614 | RPM : 110460 | Accel :   66 | Mode : Normal | 29
CPOS : 612 | APOS : 613 | RPM : 111300 | Accel :   84 | Mode : Normal | 29
CPOS : 611 | APOS : 612 | RPM : 111960 | Accel :   66 | Mode : Normal | 25
CPOS : 610 | APOS : 611 | RPM : 112500 | Accel :   54 | Mode : Normal | 25
CPOS : 610 | APOS : 610 | RPM : 113100 | Accel :   60 | Mode : Normal | 26
CPOS : 609 | APOS : 610 | RPM : 113820 | Accel :   72 | Mode : Normal | 25
CPOS : 607 | APOS : 608 | RPM : 114840 | Accel :  102 | Mode : Normal | 29
CPOS : 604 | APOS : 607 | RPM : 117000 | Accel :  216 | Mode : Normal | 30
CPOS : 605 | APOS : 604 | RPM : 116340 | Accel :  -67 | Mode : Normal | 30
CPOS : 605 | APOS : 605 | RPM : 116760 | Accel :   42 | Mode : Normal | 30
CPOS : 604 | APOS : 605 | RPM : 117660 | Accel :   90 | Mode : Normal | 27
CPOS : 603 | APOS : 603 | RPM : 118320 | Accel :   66 | Mode : Normal | 30
CPOS : 602 | APOS : 603 | RPM : 119160 | Accel :   84 | Mode : Normal | 28
CPOS : 600 | APOS : 602 | RPM : 120000 | Accel :   84 | Mode : Normal | 30
CPOS : 500 | APOS : 600 | RPM : 120660 | Accel :   66 | Mode : Normal | 28
CPOS : 500 | APOS : 500 | RPM : 121620 | Accel :   96 | Mode : Normal | 31
CPOS : 400 | APOS : 500 | RPM : 122340 | Accel :   72 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123240 | Accel :   90 | Mode : Normal | 31
CPOS : 400 | APOS : 400 | RPM : 123660 | Accel :   42 | Mode : Normal | 28
CPOS : 340 | APOS : 400 | RPM : 124200 | Accel :   54 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124380 | Accel :   18 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 124440 | Accel :    6 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124200 | Accel :  -25 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 124320 | Accel :   12 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124320 | Accel :    0 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124320 | Accel :    0 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124440 | Accel :   12 | Mode : Normal | 29
CPOS : 340 | APOS : 340 | RPM : 124380 | Accel :   -7 | Mode : Normal | 27
CPOS : 340 | APOS : 340 | RPM : 124740 | Accel :   36 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124980 | Accel :   24 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 125520 | Accel :   54 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 125280 | Accel :  -25 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 125040 | Accel :  -25 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 125580 | Accel :   54 | Mode : Normal | 29
CPOS : 280 | APOS : 340 | RPM : 126060 | Accel :   48 | Mode : Normal | 28
CPOS : 340 | APOS : 280 | RPM : 125940 | Accel :  -13 | Mode : Normal | 35
CPOS : 340 | APOS : 340 | RPM : 125880 | Accel :   -7 | Mode : Normal | 26
CPOS : 280 | APOS : 340 | RPM : 126180 | Accel :   30 | Mode : Normal | 29
CPOS : 280 | APOS : 280 | RPM : 126480 | Accel :   30 | Mode : Normal | 32
CPOS : 280 | APOS : 280 | RPM : 126540 | Accel :    6 | Mode : Normal | 29
CPOS : 280 | APOS : 280 | RPM : 126780 | Accel :   24 | Mode : Normal | 28
CPOS : 280 | APOS : 280 | RPM : 126720 | Accel :   -7 | Mode : Normal | 29
CPOS : 280 | APOS : 280 | RPM : 126960 | Accel :   24 | Mode : Normal | 32
CPOS : 280 | APOS : 280 | RPM : 127020 | Accel :    6 | Mode : Normal | 29
CPOS : 280 | APOS : 280 | RPM : 127140 | Accel :   12 | Mode : Normal | 29
CPOS : 280 | APOS : 280 | RPM : 127200 | Accel :    6 | Mode : Normal | 28
CPOS : 280 | APOS : 280 | RPM : 126960 | Accel :  -25 | Mode : Normal | 33
CPOS : 280 | APOS : 280 | RPM : 127200 | Accel :   24 | Mode : Normal | 29
CPOS : 280 | APOS : 280 | RPM : 127440 | Accel :   24 | Mode : Normal | 28
CPOS : 280 | APOS : 280 | RPM : 127440 | Accel :    0 | Mode : Normal | 35
CPOS : 280 | APOS : 280 | RPM : 127500 | Accel :    6 | Mode : Normal | 27
CPOS : 280 | APOS : 280 | RPM : 127620 | Accel :   12 | Mode : Normal | 28
CPOS : 280 | APOS : 280 | RPM : 127680 | Accel :    6 | Mode : Normal | 33
CPOS : 280 | APOS : 280 | RPM : 127800 | Accel :   12 | Mode : Normal | 29
CPOS : 280 | APOS : 280 | RPM : 127680 | Accel :  -13 | Mode : Normal | 29
CPOS : 261 | APOS : 280 | RPM : 128160 | Accel :   48 | Mode : Normal | 29
CPOS : 280 | APOS : 280 | RPM : 127980 | Accel :  -19 | Mode : Normal | 29
CPOS : 261 | APOS : 280 | RPM : 128160 | Accel :   18 | Mode : Normal | 31
CPOS : 280 | APOS : 261 | RPM : 127920 | Accel :  -25 | Mode : Normal | 27
CPOS : 240 | APOS : 280 | RPM : 128340 | Accel :   42 | Mode : Normal | 29
CPOS : 254 | APOS : 240 | RPM : 128220 | Accel :  -13 | Mode : Normal | 29
CPOS : 261 | APOS : 268 | RPM : 128160 | Accel :   -7 | Mode : Normal | 29
CPOS : 254 | APOS : 261 | RPM : 128220 | Accel :    6 | Mode : Normal | 29
CPOS : 254 | APOS : 254 | RPM : 128220 | Accel :    0 | Mode : Normal | 32
CPOS : 232 | APOS : 254 | RPM : 128400 | Accel :   18 | Mode : Normal | 26
CPOS : 232 | APOS : 232 | RPM : 128400 | Accel :    0 | Mode : Normal | 29
CPOS : 225 | APOS : 225 | RPM : 128460 | Accel :    6 | Mode : Normal | 30
CPOS : 225 | APOS : 225 | RPM : 128460 | Accel :    0 | Mode : Normal | 29
CPOS : 211 | APOS : 225 | RPM : 128580 | Accel :   12 | Mode : Normal | 29
CPOS : 211 | APOS : 211 | RPM : 128580 | Accel :    0 | Mode : Normal | 29
CPOS : 211 | APOS : 211 | RPM : 128580 | Accel :    0 | Mode : Normal | 29
CPOS : 211 | APOS : 204 | RPM : 128580 | Accel :    0 | Mode : Normal | 32
CPOS : 211 | APOS : 211 | RPM : 128580 | Accel :    0 | Mode : Normal | 27
CPOS : 204 | APOS : 211 | RPM : 128640 | Accel :    6 | Mode : Normal | 29
CPOS : 182 | APOS : 204 | RPM : 128820 | Accel :   18 | Mode : Normal | 29
CPOS : 189 | APOS : 182 | RPM : 128760 | Accel :   -7 | Mode : Normal | 29
CPOS : 196 | APOS : 189 | RPM : 128700 | Accel :   -7 | Mode : Normal | 29
CPOS : 175 | APOS : 196 | RPM : 128880 | Accel :   18 | Mode : Normal | 29
CPOS : 175 | APOS : 175 | RPM : 128880 | Accel :    0 | Mode : Normal | 30
CPOS : 182 | APOS : 175 | RPM : 128820 | Accel :   -7 | Mode : Normal | 29
CPOS : 175 | APOS : 182 | RPM : 128880 | Accel :    6 | Mode : Normal | 29
CPOS : 175 | APOS : 211 | RPM : 128880 | Accel :    0 | Mode : Normal | 29
CPOS : 153 | APOS : 175 | RPM : 129060 | Accel :   18 | Mode : Normal | 32
CPOS : 189 | APOS : 153 | RPM : 128760 | Accel :  -31 | Mode : Normal | 27
CPOS : 182 | APOS : 189 | RPM : 128820 | Accel :    6 | Mode : Normal | 29
CPOS : 160 | APOS : 182 | RPM : 129000 | Accel :   18 | Mode : Normal | 29
CPOS : 182 | APOS : 196 | RPM : 128820 | Accel :  -19 | Mode : Normal | 29
CPOS : 160 | APOS : 182 | RPM : 129000 | Accel :   18 | Mode : Normal | 31
CPOS : 146 | APOS : 160 | RPM : 129120 | Accel :   12 | Mode : Normal | 28
CPOS : 168 | APOS : 146 | RPM : 128940 | Accel :  -19 | Mode : Normal | 30
CPOS : 168 | APOS : 168 | RPM : 128940 | Accel :    0 | Mode : Normal | 27
CPOS : 160 | APOS : 153 | RPM : 129000 | Accel :    6 | Mode : Normal | 28
CPOS : 146 | APOS : 160 | RPM : 129120 | Accel :   12 | Mode : Normal | 30
CPOS : 168 | APOS : 146 | RPM : 128940 | Accel :  -19 | Mode : Normal | 27
CPOS : 146 | APOS : 168 | RPM : 129120 | Accel :   18 | Mode : Normal | 27
CPOS : 153 | APOS : 146 | RPM : 129060 | Accel :   -7 | Mode : Normal | 29
CPOS : 175 | APOS : 124 | RPM : 128880 | Accel :  -19 | Mode : Normal | 29
CPOS : 182 | APOS : 175 | RPM : 128820 | Accel :   -7 | Mode : Normal | 30
CPOS : 153 | APOS : 182 | RPM : 129060 | Accel :   24 | Mode : Normal | 29
CPOS : 160 | APOS : 153 | RPM : 129000 | Accel :   -7 | Mode : Normal | 29
CPOS : 153 | APOS : 160 | RPM : 129060 | Accel :    6 | Mode : Normal | 30
CPOS : 153 | APOS : 153 | RPM : 129060 | Accel :    0 | Mode : Normal | 30
CPOS : 146 | APOS : 153 | RPM : 129120 | Accel :    6 | Mode : Normal | 29
CPOS : 175 | APOS : 146 | RPM : 128880 | Accel :  -25 | Mode : Normal | 33
CPOS : 225 | APOS : 175 | RPM : 128460 | Accel :  -43 | Mode : Normal | 29
CPOS : 254 | APOS : 225 | RPM : 128220 | Accel :  -25 | Mode : Normal | 29
CPOS : 280 | APOS : 280 | RPM : 127740 | Accel :  -49 | Mode : Normal | 29
CPOS : 280 | APOS : 280 | RPM : 126840 | Accel :  -91 | Mode : Normal | 29
CPOS : 340 | APOS : 280 | RPM : 125520 | Accel : -133 | Mode : Normal | 28
CPOS : 400 | APOS : 340 | RPM : 123720 | Accel : -181 | Mode : Normal | 28
CPOS : 500 | APOS : 400 | RPM : 121440 | Accel : -229 | Mode : Normal | 27
CPOS : 602 | APOS : 601 | RPM : 118500 | Accel : -295 | Mode : Normal | 30
CPOS : 605 | APOS : 602 | RPM : 116700 | Accel : -181 | Mode : Normal | 26
CPOS : 607 | APOS : 605 | RPM : 114780 | Accel : -193 | Mode : Normal | 26
CPOS : 610 | APOS : 607 | RPM : 113040 | Accel : -175 | Mode : Normal | 26
CPOS : 611 | APOS : 610 | RPM : 111780 | Accel : -127 | Mode : Normal | 24
CPOS : 613 | APOS : 612 | RPM : 110580 | Accel : -121 | Mode : Normal | 26
CPOS : 615 | APOS : 613 | RPM : 109380 | Accel : -121 | Mode : Normal | 27
Title: Re: Accel Variable
Post by: hakcenter on August 17, 2015, 04:26:47 PM
Here's my 4th gear

CPOS : 670 | APOS : 670 | RPM :  80340 | Accel :    5 | Mode : Normal | 228
CPOS : 668 | APOS : 669 | RPM :  81120 | Accel :    7 | Mode : Normal | 222
CPOS : 668 | APOS : 668 | RPM :  81420 | Accel :    3 | Mode : Normal | 225
CPOS : 667 | APOS : 667 | RPM :  81960 | Accel :    5 | Mode : Normal | 223
CPOS : 665 | APOS : 665 | RPM :  82800 | Accel :    8 | Mode : Normal | 220
CPOS : 663 | APOS : 664 | RPM :  83520 | Accel :    7 | Mode : Normal | 213
CPOS : 662 | APOS : 662 | RPM :  84480 | Accel :    9 | Mode : Normal | 221
CPOS : 659 | APOS : 660 | RPM :  85980 | Accel :   15 | Mode : Normal | 223
CPOS : 657 | APOS : 656 | RPM :  86940 | Accel :    9 | Mode : Normal | 227
CPOS : 654 | APOS : 655 | RPM :  88020 | Accel :   10 | Mode : Normal | 222
CPOS : 652 | APOS : 653 | RPM :  89100 | Accel :   10 | Mode : Normal | 236
CPOS : 649 | APOS : 650 | RPM :  90600 | Accel :   15 | Mode : Normal | 227
CPOS : 644 | APOS : 646 | RPM :  93120 | Accel :   25 | Mode : Normal | 236
CPOS : 635 | APOS : 638 | RPM :  97860 | Accel :   47 | Mode : Normal | 257
CPOS : 625 | APOS : 627 | RPM : 102780 | Accel :   49 | Mode : Normal | 259
CPOS : 620 | APOS : 621 | RPM : 105540 | Accel :   78 | Mode : Normal | 105
CPOS : 620 | APOS : 620 | RPM : 105660 | Accel :   12 | Mode : Normal | 25
CPOS : 619 | APOS : 620 | RPM : 106260 | Accel :   60 | Mode : Normal | 25
CPOS : 618 | APOS : 619 | RPM : 107160 | Accel :   90 | Mode : Normal | 23
CPOS : 617 | APOS : 617 | RPM : 107520 | Accel :   36 | Mode : Normal | 28
CPOS : 616 | APOS : 617 | RPM : 108120 | Accel :   60 | Mode : Normal | 24
CPOS : 616 | APOS : 616 | RPM : 108720 | Accel :   60 | Mode : Normal | 26
CPOS : 615 | APOS : 616 | RPM : 109260 | Accel :   54 | Mode : Normal | 26
CPOS : 614 | APOS : 615 | RPM : 109620 | Accel :   36 | Mode : Normal | 25
CPOS : 614 | APOS : 614 | RPM : 110160 | Accel :   54 | Mode : Normal | 24
CPOS : 613 | APOS : 614 | RPM : 110700 | Accel :   54 | Mode : Normal | 26
CPOS : 612 | APOS : 613 | RPM : 111300 | Accel :   60 | Mode : Normal | 28
CPOS : 611 | APOS : 612 | RPM : 111900 | Accel :   60 | Mode : Normal | 25
CPOS : 610 | APOS : 611 | RPM : 112500 | Accel :   60 | Mode : Normal | 26
CPOS : 610 | APOS : 610 | RPM : 113100 | Accel :   60 | Mode : Normal | 25
CPOS : 609 | APOS : 610 | RPM : 113580 | Accel :   48 | Mode : Normal | 29
CPOS : 608 | APOS : 609 | RPM : 114180 | Accel :   60 | Mode : Normal | 30
CPOS : 608 | APOS : 608 | RPM : 114600 | Accel :   42 | Mode : Normal | 29
CPOS : 607 | APOS : 608 | RPM : 115200 | Accel :   60 | Mode : Normal | 26
CPOS : 606 | APOS : 606 | RPM : 115920 | Accel :   72 | Mode : Normal | 30
CPOS : 605 | APOS : 606 | RPM : 116640 | Accel :   72 | Mode : Normal | 33
CPOS : 605 | APOS : 605 | RPM : 116940 | Accel :   30 | Mode : Normal | 24
CPOS : 604 | APOS : 605 | RPM : 117540 | Accel :   60 | Mode : Normal | 30
CPOS : 602 | APOS : 604 | RPM : 118560 | Accel :  102 | Mode : Normal | 27
CPOS : 602 | APOS : 602 | RPM : 118560 | Accel :    0 | Mode : Normal | 26
CPOS : 602 | APOS : 602 | RPM : 119220 | Accel :   66 | Mode : Normal | 28
CPOS : 601 | APOS : 602 | RPM : 119580 | Accel :   36 | Mode : Normal | 26
CPOS : 500 | APOS : 601 | RPM : 120180 | Accel :   60 | Mode : Normal | 32
CPOS : 500 | APOS : 500 | RPM : 120540 | Accel :   36 | Mode : Normal | 26
CPOS : 500 | APOS : 500 | RPM : 121140 | Accel :   60 | Mode : Normal | 28
CPOS : 500 | APOS : 500 | RPM : 121740 | Accel :   60 | Mode : Normal | 29
CPOS : 500 | APOS : 500 | RPM : 121920 | Accel :   18 | Mode : Normal | 26
CPOS : 400 | APOS : 500 | RPM : 122280 | Accel :   36 | Mode : Normal | 27
CPOS : 400 | APOS : 400 | RPM : 122580 | Accel :   30 | Mode : Normal | 32
CPOS : 400 | APOS : 400 | RPM : 122880 | Accel :   30 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 122700 | Accel :  -19 | Mode : Normal | 31
CPOS : 400 | APOS : 400 | RPM : 122880 | Accel :   18 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123120 | Accel :   24 | Mode : Normal | 31
CPOS : 400 | APOS : 400 | RPM : 123360 | Accel :   24 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 122700 | Accel :  -67 | Mode : Normal | 31
CPOS : 400 | APOS : 400 | RPM : 122580 | Accel :  -13 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 122760 | Accel :   18 | Mode : Normal | 32
CPOS : 400 | APOS : 400 | RPM : 122400 | Accel :  -37 | Mode : Normal | 27
CPOS : 400 | APOS : 400 | RPM : 122520 | Accel :   12 | Mode : Normal | 32
CPOS : 400 | APOS : 400 | RPM : 122280 | Accel :  -25 | Mode : Normal | 31
CPOS : 400 | APOS : 400 | RPM : 122460 | Accel :   18 | Mode : Normal | 31
CPOS : 400 | APOS : 400 | RPM : 122460 | Accel :    0 | Mode : Normal | 29
CPOS : 400 | APOS : 400 | RPM : 122280 | Accel :  -19 | Mode : Normal | 29
CPOS : 400 | APOS : 400 | RPM : 122160 | Accel :  -13 | Mode : Normal | 26
CPOS : 400 | APOS : 400 | RPM : 122280 | Accel :   12 | Mode : Normal | 31
CPOS : 400 | APOS : 400 | RPM : 122160 | Accel :  -13 | Mode : Normal | 31
CPOS : 400 | APOS : 400 | RPM : 122040 | Accel :  -13 | Mode : Normal | 24
CPOS : 400 | APOS : 400 | RPM : 122220 | Accel :   18 | Mode : Normal | 32
CPOS : 400 | APOS : 400 | RPM : 122040 | Accel :  -19 | Mode : Normal | 27
CPOS : 400 | APOS : 400 | RPM : 122340 | Accel :   30 | Mode : Normal | 32
CPOS : 400 | APOS : 400 | RPM : 122280 | Accel :   -7 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 122280 | Accel :    0 | Mode : Normal | 33
CPOS : 400 | APOS : 400 | RPM : 122280 | Accel :    0 | Mode : Normal | 29
CPOS : 400 | APOS : 400 | RPM : 122280 | Accel :    0 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 122340 | Accel :    6 | Mode : Normal | 27
CPOS : 400 | APOS : 400 | RPM : 122220 | Accel :  -13 | Mode : Normal | 32
CPOS : 400 | APOS : 400 | RPM : 122580 | Accel :   36 | Mode : Normal | 27
CPOS : 400 | APOS : 400 | RPM : 122400 | Accel :  -19 | Mode : Normal | 32
CPOS : 400 | APOS : 400 | RPM : 122820 | Accel :   42 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 122400 | Accel :  -43 | Mode : Normal | 27
CPOS : 400 | APOS : 400 | RPM : 122880 | Accel :   48 | Mode : Normal | 29
CPOS : 400 | APOS : 400 | RPM : 122820 | Accel :   -7 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 122580 | Accel :  -25 | Mode : Normal | 26
CPOS : 400 | APOS : 400 | RPM : 122940 | Accel :   36 | Mode : Normal | 31
CPOS : 400 | APOS : 400 | RPM : 122820 | Accel :  -13 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123000 | Accel :   18 | Mode : Normal | 27
CPOS : 400 | APOS : 400 | RPM : 122820 | Accel :  -19 | Mode : Normal | 29
CPOS : 400 | APOS : 400 | RPM : 123180 | Accel :   36 | Mode : Normal | 27
CPOS : 400 | APOS : 400 | RPM : 122940 | Accel :  -25 | Mode : Normal | 27
CPOS : 400 | APOS : 400 | RPM : 122940 | Accel :    0 | Mode : Normal | 31
CPOS : 400 | APOS : 400 | RPM : 122820 | Accel :  -13 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123180 | Accel :   36 | Mode : Normal | 32
CPOS : 400 | APOS : 400 | RPM : 123060 | Accel :  -13 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123360 | Accel :   30 | Mode : Normal | 31
CPOS : 400 | APOS : 400 | RPM : 123180 | Accel :  -19 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123360 | Accel :   18 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123960 | Accel :   60 | Mode : Normal | 27
CPOS : 400 | APOS : 400 | RPM : 123480 | Accel :  -49 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123540 | Accel :    6 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123600 | Accel :    6 | Mode : Normal | 31
CPOS : 340 | APOS : 400 | RPM : 125160 | Accel :  156 | Mode : Normal | 32
CPOS : 400 | APOS : 340 | RPM : 123780 | Accel : -139 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123900 | Accel :   12 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123780 | Accel :  -13 | Mode : Normal | 32
CPOS : 340 | APOS : 400 | RPM : 124320 | Accel :   54 | Mode : Normal | 27
CPOS : 400 | APOS : 340 | RPM : 123540 | Accel :  -79 | Mode : Normal | 32
CPOS : 400 | APOS : 400 | RPM : 123780 | Accel :   24 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123660 | Accel :  -13 | Mode : Normal | 28
CPOS : 340 | APOS : 400 | RPM : 124080 | Accel :   42 | Mode : Normal | 32
CPOS : 400 | APOS : 400 | RPM : 123900 | Accel :  -19 | Mode : Normal | 32
CPOS : 400 | APOS : 400 | RPM : 123900 | Accel :    0 | Mode : Normal | 27
CPOS : 400 | APOS : 400 | RPM : 123480 | Accel :  -43 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123780 | Accel :   30 | Mode : Normal | 28
CPOS : 340 | APOS : 400 | RPM : 124140 | Accel :   36 | Mode : Normal | 29
CPOS : 340 | APOS : 400 | RPM : 124140 | Accel :    0 | Mode : Normal | 27
CPOS : 340 | APOS : 340 | RPM : 124080 | Accel :   -7 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124140 | Accel :    6 | Mode : Normal | 31
CPOS : 340 | APOS : 340 | RPM : 125820 | Accel :  168 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124260 | Accel : -157 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 124200 | Accel :   -7 | Mode : Normal | 28
CPOS : 400 | APOS : 340 | RPM : 123960 | Accel :  -25 | Mode : Normal | 32
CPOS : 340 | APOS : 400 | RPM : 124080 | Accel :   12 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124380 | Accel :   30 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 124380 | Accel :    0 | Mode : Normal | 28
CPOS : 340 | APOS : 400 | RPM : 124380 | Accel :    0 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 124200 | Accel :  -19 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124320 | Accel :   12 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124080 | Accel :  -25 | Mode : Normal | 31
CPOS : 340 | APOS : 340 | RPM : 124440 | Accel :   36 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124320 | Accel :  -13 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 124320 | Accel :    0 | Mode : Normal | 28
CPOS : 400 | APOS : 340 | RPM : 123900 | Accel :  -43 | Mode : Normal | 32
CPOS : 340 | APOS : 400 | RPM : 124260 | Accel :   36 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124320 | Accel :    6 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124200 | Accel :  -13 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 124080 | Accel :  -13 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 124440 | Accel :   36 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124560 | Accel :   12 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124620 | Accel :    6 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124680 | Accel :    6 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 124740 | Accel :    6 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 124620 | Accel :  -13 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124740 | Accel :   12 | Mode : Normal | 31
CPOS : 340 | APOS : 340 | RPM : 124740 | Accel :    0 | Mode : Normal | 26
CPOS : 340 | APOS : 340 | RPM : 124800 | Accel :    6 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 124740 | Accel :   -7 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124620 | Accel :  -13 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124560 | Accel :   -7 | Mode : Normal | 32
CPOS : 340 | APOS : 340 | RPM : 124380 | Accel :  -19 | Mode : Normal | 28
CPOS : 340 | APOS : 340 | RPM : 124020 | Accel :  -37 | Mode : Normal | 32
CPOS : 400 | APOS : 340 | RPM : 123480 | Accel :  -55 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123420 | Accel :   -7 | Mode : Normal | 28
CPOS : 400 | APOS : 400 | RPM : 123120 | Accel :  -31 | Mode : Normal | 31
CPOS : 400 | APOS : 400 | RPM : 122040 | Accel : -109 | Mode : Normal | 32
CPOS : 500 | APOS : 500 | RPM : 121560 | Accel :  -49 | Mode : Normal | 27
CPOS : 500 | APOS : 500 | RPM : 120720 | Accel :  -85 | Mode : Normal | 31
CPOS : 601 | APOS : 500 | RPM : 119520 | Accel : -121 | Mode : Normal | 33
CPOS : 603 | APOS : 601 | RPM : 118380 | Accel : -115 | Mode : Normal | 24
CPOS : 604 | APOS : 603 | RPM : 117480 | Accel :  -91 | Mode : Normal | 30
CPOS : 606 | APOS : 605 | RPM : 116160 | Accel : -133 | Mode : Normal | 30
CPOS : 607 | APOS : 606 | RPM : 115200 | Accel :  -97 | Mode : Normal | 26
CPOS : 609 | APOS : 607 | RPM : 113940 | Accel : -127 | Mode : Normal | 29
CPOS : 610 | APOS : 609 | RPM : 112980 | Accel :  -97 | Mode : Normal | 29
CPOS : 611 | APOS : 610 | RPM : 111780 | Accel : -121 | Mode : Normal | 28
CPOS : 612 | APOS : 612 | RPM : 111240 | Accel :  -55 | Mode : Normal | 26
CPOS : 613 | APOS : 612 | RPM : 110460 | Accel :  -79 | Mode : Normal | 25
CPOS : 614 | APOS : 613 | RPM : 110160 | Accel :  -31 | Mode : Normal | 24
Title: Re: Accel Variable
Post by: hakcenter on August 17, 2015, 04:30:03 PM
Here's the full log.

The number past the mode, is how many times loop ran between each serial output. What that also includes, is all the timers running, so take that into account.

You can tell that as shaft speed increases, the computational time for loop decreases, so it gets faster as the turbo gets faster.
Title: Re: Accel Variable
Post by: hakcenter on August 18, 2015, 10:23:01 PM
So I kept thinking to myself... That speed on the right is way slow...

I was working on it today and got it up to  2000+ loops per 100ms now...  I forgot what I did! I'll have to compare to the posted code but I think the frequency read was the major slow down going from double to long

So then I increased the array from 64 to 128... And the output got all screwed up and i spent more time trying to figure out what I broke copying and pasting each tab until I figured it out..  So not entirely sure what made it go faster
Title: Re: Accel Variable
Post by: hakcenter on August 20, 2015, 12:34:54 AM
Bark

CPOS : 420 | APOS : 420 | RPM : 125760 | Accel :   12 | Mode : Normal | 22
CPOS : 420 | APOS : 420 | RPM : 125700 | Accel :   -7 | Mode : Normal | 21
CPOS : 420 | APOS : 420 | RPM : 125700 | Accel :    0 | Mode : Normal | 22
CPOS : 420 | APOS : 420 | RPM : 125760 | Accel :    6 | Mode : Normal | 21
CPOS : 420 | APOS : 420 | RPM : 125820 | Accel :    6 | Mode : Normal | 22
CPOS : 420 | APOS : 420 | RPM : 125880 | Accel :    6 | Mode : Normal | 21
CPOS : 380 | APOS : 420 | RPM : 126060 | Accel :   18 | Mode : Normal | 22
CPOS : 380 | APOS : 420 | RPM : 126060 | Accel :    0 | Mode : Normal | 21
CPOS : 380 | APOS : 380 | RPM : 126240 | Accel :   18 | Mode : Normal | 22
CPOS : 380 | APOS : 380 | RPM : 126180 | Accel :   -7 | Mode : Normal | 21
CPOS : 380 | APOS : 380 | RPM : 126060 | Accel :  -13 | Mode : Normal | 22
CPOS : 420 | APOS : 380 | RPM : 125940 | Accel :  -13 | Mode : Normal | 21
CPOS : 420 | APOS : 420 | RPM : 125820 | Accel :  -13 | Mode : Normal | 22
CPOS : 420 | APOS : 420 | RPM : 125220 | Accel :  -61 | Mode : Normal | 21
CPOS : 420 | APOS : 420 | RPM : 124800 | Accel :  -43 | Mode : Normal | 21
CPOS : 460 | APOS : 420 | RPM : 123960 | Accel :  -85 | Mode : Normal | 22
CPOS : 460 | APOS : 460 | RPM : 123060 | Accel :  -91 | Mode : Normal | 20
CPOS : 520 | APOS : 460 | RPM : 121980 | Accel : -109 | Mode : Normal | 21
CPOS : 520 | APOS : 520 | RPM : 120600 | Accel : -139 | Mode : Normal | 21
CPOS : 602 | APOS : 520 | RPM : 119100 | Accel : -151 | Mode : Normal | 20
CPOS : 604 | APOS : 602 | RPM : 117540 | Accel : -157 | Mode : Normal | 20
CPOS : 606 | APOS : 604 | RPM : 115860 | Accel : -169 | Mode : Normal | 20
CPOS : 608 | APOS : 607 | RPM : 114240 | Accel : -163 | Mode : Normal | 19
CPOS : 610 | APOS : 608 | RPM : 112920 | Accel : -133 | Mode : Normal | 19
CPOS : 611 | APOS : 610 | RPM : 112200 | Accel :  -73 | Mode : Normal | 19
CPOS : 611 | APOS : 611 | RPM : 112020 | Accel :  -19 | Mode : Normal | 20
CPOS : 612 | APOS : 611 | RPM : 111660 | Accel :  -37 | Mode : Normal | 19
CPOS : 611 | APOS : 611 | RPM : 111960 | Accel :   30 | Mode : Normal | 19
CPOS : 611 | APOS : 611 | RPM : 112080 | Accel :   12 | Mode : Normal | 19
CPOS : 608 | APOS : 611 | RPM : 114240 | Accel :  216 | Mode : Normal | 19
CPOS : 610 | APOS : 608 | RPM : 112980 | Accel : -127 | Mode : Normal | 19
CPOS : 611 | APOS : 610 | RPM : 112320 | Accel :  -67 | Mode : Normal | 19
CPOS : 613 | APOS : 612 | RPM : 110580 | Accel : -175 | Mode : Normal | 19
CPOS : 615 | APOS : 613 | RPM : 108960 | Accel : -163 | Mode : Normal | 19
CPOS : 618 | APOS : 615 | RPM : 107040 | Accel : -193 | Mode : Normal | 18
CPOS : 620 | APOS : 618 | RPM : 105600 | Accel : -145 | Mode : Normal | 18
CPOS : 628 | APOS : 623 | RPM : 101340 | Accel : -130 | Mode : Normal | 70
CPOS : 639 | APOS : 637 | RPM :  95760 | Accel :  -56 | Mode : Normal | 167


Pretty crazy it was caught in a log.
Title: Re: Accel Variable
Post by: hakcenter on August 24, 2015, 03:08:54 PM
Last little bit, to smooth out the acceleration, I've added division arrgh, no way around it though, need the extra resolution.


void loop() {
  // Sleep
  unsigned int sleep = 0;
  // Freq Measure
  unsigned long sum[32];
  float final_sum = 0.0f;
  byte count = 0;
  byte i = 0;

  // main loop
  while(1) {
    t1.update();
    t2.update();
    // Freq Measure
    if (FreqMeasure.available()) {
      timing++;
      sleep = 0;
      // average several reading together
      sum[count] = FreqMeasure.read();
      final_sum = 0.0f;
      for (i = 0 ; i < 32 ; i++) { final_sum += sum[i]; }
      // turbo_rpm = Freq(sum / count) * 60
      final_sum = FreqMeasure.countToFrequency(final_sum / 32.0f);
      turbo_rpm = final_sum * 60.0f;
      count++;
      if (count > 31) { count = 0; }
    }
  }
}


I've added this curve tuning to the top end, after the vane has been calculated, to adjust the curve lower based on how fast it is accelerating.


        if (turbo_rpm > 122000) {
          if (turbo_accel[2] > 60) { vane_position -= half_cm; }
          if (turbo_accel[2] > 90) { vane_position -= half_cm; }
        }


Seems to work out good. So I've tuned the turbo in final gear, then adjusted these values to help the turbo from overspinning in the lower gears.
Title: Re: Accel Variable
Post by: me78569 on August 25, 2015, 10:46:56 AM
nice I am liking that.


Can you explain the

final_sum = [color=red]0.0f[/color];

Why the "f" ? 

I am really liking this though.  I need to test it, but life has been and will continue to be nuts for awhile longer here.
Title: Re: Accel Variable
Post by: Rx7man on August 25, 2015, 01:15:32 PM
I think that forces is to be calculated as a float not an int, though I think just defining it as 0.0 rather than 0 does the same thing? and since the variable is declared as a float I don't know if you'd need either.. the times you'd use it are like


float p = 2/4; (returns 0 I think since it's doing integer math)
float p = 2.0/4.0; (returns 0.5 as expected as it's forced into floating point math)
Title: Re: Accel Variable
Post by: me78569 on August 25, 2015, 01:26:58 PM
got ya.  Thanks!
Title: Re: Accel Variable
Post by: hakcenter on August 25, 2015, 02:42:46 PM
Ya you have to force the floating point math, I added the f so it wouldn't be double. Even though in our AVR double/float is the same. The designation is for our eyes.

Also only 1 part has to be float/double to force it into that kind of work.

You can do like


float sum = 2 / 3.0f;


Or a really interesting one


unsigned int test = (2/3.0) * 100;
float final_test = test / 100.0;

Precision of only 2 digits.. etc. Do some high low byte work or move the decimal around now that you know where it is.. etc.
Title: Re: Accel Variable
Post by: Rx7man on August 25, 2015, 11:02:36 PM
the particular instance here

float final_sum = 0.0f;

you could just declare as

float final_sum = 0;

and it would be the same thing.. you only need the "f" when there's math involved... right?
Title: Re: Accel Variable
Post by: hakcenter on August 26, 2015, 12:12:45 AM
If you don't add the .0, it won't kick into float math it'll be stuck in int math.. I think it has more to do with the compiler than anything else really.

https://www.arduino.cc/en/Reference/Float
Quote
If doing math with floats, you need to add a decimal point, otherwise it will be treated as an int. See the Floating point constants page for details.

I'm not sure if you can sneak in casting to float and not need the .0 though
Title: Re: Accel Variable
Post by: Rx7man on August 26, 2015, 01:13:22 AM
I think you only need to at the .0 when dealing with literals


float var1 = 1;
float var2 = 2;
float var3 = var1/var2;

that should work as expected, that is, var3 = 0.5, because the math is being done on 2 floating point numbers... in the line where var3 is assigned, it has no 'knowledge' of if you declared var2 as '2' or '2.0', they're stored the same way
Title: Re: Accel Variable
Post by: hakcenter on August 26, 2015, 01:45:15 AM
Without the decimal place, those will be treated as integers and upon compiling will evaluate to 0.

Read the link from Arduino.
https://www.arduino.cc/en/Reference/Float
https://www.arduino.cc/en/Reference/Fpconstants


   int x;
   int y;
   float z;

   x = 1;
   y = x / 2;            // y now contains 0, ints can't hold fractions
   z = (float)x / 2.0;   // z now contains .5 (you have to use 2.0, not 2)

x had to be type casted to float, to get 0.5 and the division requires 2.0 not 2.

Compiler optimizations and what not. Float math is avoided cause its slow.
Title: Re: Accel Variable
Post by: Rx7man on August 26, 2015, 08:50:47 AM
yes, that's true, you're using literals.. in my example the math was done on floats, but assigned without using the '.0'


int var1 = 1;
int var2 = 2;
float var3 = var1;
float var4 = var2;

float var5 = var1/var2; //returns 0   the types are integers
float var6 = var3/var2; // should return 0.5, one of the variables is a float, forcing floating point math
float var7 = var3/var4; //returns 0.5, both are floats


I think that's right.
Title: Re: Accel Variable
Post by: hakcenter on August 26, 2015, 12:52:51 PM
Quote from: Rx7man on August 26, 2015, 08:50:47 AM
yes, that's true, you're using literals.. in my example the math was done on floats, but assigned without using the '.0'


int var1 = 1;
int var2 = 2;
float var3 = var1;
float var4 = var2;

float var5 = var1/var2; //returns 0   the types are integers
float var6 = var3/var2; // should return 0.5, one of the variables is a float, forcing floating point math
float var7 = var3/var4; //returns 0.5, both are floats


I think that's right.


int var1 = 1;
int var2 = 2;
float var3 = (float) var1;
float var4 = (float) var2;

float var5 = var1/var2; //returns 0   the types are integers
float var6 = var3/(float) var2; // should return 0.5, one of the variables is a float, forcing floating point math
float var7 = var3/var4; //returns 0.5, both are floats


Now yes... if you put an int into a float, it uses int math.
Title: Re: Accel Variable
Post by: Rx7man on August 26, 2015, 03:29:24 PM
I had to try it

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
int var1 = 1;
int var2 = 2;
float var3 = var1;
float var4 = var2;

float var5 = var1/var2; //returns 0   the types are integers
float var6 = var3/var2; // should return 0.5, one of the
float var7 = var3/var4; //returns 0.5, both are floats

Serial.println(var5);
Serial.println(var6);
Serial.println(var7);


}

void loop() {
  // put your main code here, to run repeatedly:

}


returns:
0
0.5
0.5

int to float conversion is done implicitly in var3=var1, you don't need to specify it
Title: Re: Accel Variable
Post by: hakcenter on August 26, 2015, 09:52:17 PM
Nice to see it goes against what they say, wonder if its the same throughout the IDE versions
Title: Re: Accel Variable
Post by: Rx7man on August 27, 2015, 01:23:08 PM
it should...

when you're converting the literal 2 to a float, it gets converted implicitly so there's no need to put the decimal on it, you only need to specify it when using literals as they could be any type.. like '1' could be a boolean, float, double, or integer, and there's no way of knowing if it even should be stored with the sign bit... so if you want it to be a float, you need either the ".0" behind it of 'f'
Title: Re: Accel Variable
Post by: hakcenter on August 27, 2015, 01:57:23 PM
I understand the basic logic. But when you read their documentation and their code example its wrong.

They type cast x, when it is unnecessary. They also stated that unless you use point 0 or f, the compiler uses integer math.

Best to pull the machine code to see if using a float = 2/3 saves memory and time versus float = 2.0 / 3

Or if they are the same anyways.
Title: Re: Accel Variable
Post by: Rx7man on August 28, 2015, 12:23:29 AM
I don't know if I've forgotten how to program, but I am unable to test how fast it works either way... no matter how many loops I make it do, it's always saying 4 microseconds... I don't believe it... I'll figure it out someday I guess
Title: Re: Accel Variable
Post by: Rx7man on August 28, 2015, 12:26:18 AM
Quote
Best to pull the machine code to see if using a float = 2/3 saves memory and time versus float = 2.0 / 3

float = 2/3 will be done in integer math because you're using integer literals

Title: Re: Accel Variable
Post by: hakcenter on August 28, 2015, 08:32:30 AM
If it all lands up on the same micros, then its most likely creating the same code both ways.

Take the elf and run it against obj-dump

windows bat file

@echo off
cls
echo Disassembler for the .elf file by avr-objdump.exe
rem Place avr-objdump.exe and this batch file in the same folder
rem Don't use filenames with spaces

avr-objdump -S name_of_elf.elf > assembler.txt
pause



void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
int var1 = 1;
int var2 = 2;
float var3 = var1;
float var4 = var2;

float var5 = var1/var2; //returns 0   the types are integers
float var6 = var3/var2; // should return 0.5, one of the
float var7 = var3/var4; //returns 0.5, both are floats

Serial.println(var5);
Serial.println(var6);
Serial.println(var7);


}

void loop() {
  // put your main code here, to run repeatedly:

}


My big grimace about doing things this way, is making the assumption that var1 and var2 are type casted to float, without the typecast. The assumption is float test = int 1 + int 2; is a float, when its coming in as ints, to me shows inequal types. I would expect float test = (float) (int 1 + int 2);


int var1 = 1;
int var2 = 2;
int var3 = var1;
int var4 = var2;

float var5 = var1 / var2;
float var6 = (float) var3 / var2;
float var7 = (float) var3 / (float) var4;


When I read that, I see var5 as int math, my expectation is var5 is a float for size even though an unsigned long would probably be just as good.

Where as var6 and var7, I know that the purpose is to have a decimal place with actual division.

I imagine in compiling the type castings are removed/ignored, but it does help other readers understand the implicit goal. Why Arduino states their compiler uses int math wherever an int is not type casted is beyond me, when you've already shown it doesn't. I would like to think maybe older compilers in the older IDE's probably did. Who knows, there could be a difference between windows avr-gcc+ and linux avr-gcc+. I know that in my testing I'm strictly using my Gentoo laptop while I'm mobile code testing, versus sometimes I bring the lbb in at my desk and compile on my desktop (w7).

I will say that, assumptions can really put a cork in coding. Haha. Like when you send a negative number to the turbo, and it makes it 3cm^2 instead of 25cm^2. How it became negative was someone made the assumption (me haha) that this particular math wouldn't go negative or need constraints. Assumptions like the arduino map() command constrains at the start and end points, where as it actually just creates a slope between 2 numbers, so it will continue that linear way in either direction. :-D
Title: Re: Accel Variable
Post by: Rx7man on August 28, 2015, 09:12:47 AM
the "map" function is documented as saying it does NOT apply constraints though :P


int var1 = 1;
int var2 = 2;
int var3 = var1;
int var4 = var2;

float var5 = var1 / var2;
float var6 = (float) var3 / var2;
float var7 = (float) var3 / (float) var4;


where 
float var5 = var1/var2, the compiler knows that both types are integer *types*, thus cannot be anything other than an integer

but
float var8 = var3/var4, the compiler knows that both types are float *types*, but holding an integer *value*... it only cares about the type, so it does floating point math

take this for example

int var1 = 20;

for (float i = 1; i<5; i +=.5){
  float result = var1 / i;
  Serial.println(result);
}

in this example, every other iteration through the loop it will be an integer *value*, while the underlying type remains float.
If it did the math based on the value stored, every time i was an integer value, the result would be calculated with integer math, and be wrong...
the right results are
1
1/1.5 (whatever that works out to in decimal)
.5
1/2.5
1/3
etc

while the wrong results if it did integer math when the value rather than type was an integer
1
1/1.5
0
1/2.5
0
1/3.5
Title: Re: Accel Variable
Post by: hakcenter on August 29, 2015, 12:38:43 AM
Pretty sure you missed what I said up above lol.
Title: Re: Accel Variable
Post by: Rx7man on August 29, 2015, 09:13:12 AM
I might still be missing it!
Quote
The assumption is float test = int 1 + int 2; is a float, when its coming in as ints, to me shows inequal types. I would expect float test = (float) (int 1 + int 2);

The conversion from int to float is what I think they call a widening conversion, meaning you'll never get an overflow or lose precision in the conversion, which is probably why they don't warn about it, it's perfectly safe to do implicitly... though the arduino IDE is rather rudimentary.  I've been getting to know Atmel Studio... I like it but it has some things that peeve me to no end with autocomplete
Title: Re: Accel Variable
Post by: hakcenter on August 29, 2015, 04:13:19 PM
lol you are haha.

While its true that you can do it, and it seems to go away from the white papers so to speak from Arduino. That's not what I'm really talking about anymore.

Context is what I'm getting after. When I see two int variables doing math, I see int math. When I see two Strings doing stuff, I think Strings. When I see char arrays I think char, does that make sense ? Without a typecast, to me it looks wrong. You take unequal types and try to equate them without a typecast, throws all kinds of errors in other IDEs for similar languages. Java, c#, etc. And while the compiler can and will make it happen, without the typecast only the original author knows the intent behind it.

Like for instance, in java you can't just take a int and print it to string. You have to add it to a string, or typecast it.


int test = 15;
String output = "Value of test : ";
String final_output = output;
final_output += test;
^^ generally will throw an error of unequal types, sometimes strings get away with things that other datatypes don't in certain IDEs.



int test = 15;
String output = "Value of test : ";
String final_output = output + String.of(test);
or
String final_output = output + ((String) test);
Title: Re: Accel Variable
Post by: Rx7man on August 29, 2015, 09:02:41 PM
OK, I think I get what you're after.  I usually don't care so much about the type as long as its a numerical type, and a widening conversion
Title: Re: Accel Variable
Post by: me78569 on September 12, 2015, 07:58:11 PM
ive finally gotten a couple minutes to look over this all in depth.

Is the top end accel tuning not in your 1.1.2 code?   
Title: Re: Accel Variable
Post by: hakcenter on September 13, 2015, 01:03:53 AM
No I'm not sure it's 100% stable yet
Title: Re: Accel Variable
Post by: me78569 on September 13, 2015, 09:55:36 AM
alright,

Thanks


I the top end stuff in my code.

        if (curved){  //End pos of 17cm  start 16cm
                 if (turbo_rpm <= 120000) { vane_position = 458 - TPS_range;} //************************
            else if (turbo_rpm <= 128000) { vane_position = 416 - TPS_range;} //************************
            else if (turbo_rpm <= 140000) {
                     if (turbo_accel[2] > 20){vane_position = last_vane_position - 5;}
                else if (turbo_accel[2] < -20){vane_position = last_vane_position + 5;}
                else {vane_position = last_vane_position;}
          }
        }
        // Overrun protection
      if (turbo_rpm > 140000){ 
        if (turbo_accel[2] > 0){
          if (!curvea) {vane_position -= 5;}         //this will creep the vane position more open each code cycle if turbo rpms are above 140,000 if not in curvea ( perf mode defined by "F_watchpot" tab)
        }
        else {vane_position = last_vane_position;}
      }
   }


Still messing with it, but the turbo no longer "overreacts" to shaft speed above 140,000.  I don't really like that shaft speeds get up that high, but I am working the curve down. 

The accel variable is VERY useful. 
Title: Re: Accel Variable
Post by: hakcenter on September 13, 2015, 02:07:21 PM
Glad to see more than me using it.
Title: Re: Accel Variable
Post by: me78569 on September 13, 2015, 02:47:18 PM
Yep,

Its works really well.  It solves the prior issue of shaft speed being over 140k, but it was decreasing in speed, but the vanes were still opening. 

Very handy.   

Still working on moving the top limit down some to 130ish, but right now it stays pretty steady at 140,000. 


I cannot believe how much difference there is with this turbo at sea level.  So much easier to manage down there compared to up here.  The top is was much easier to keep at or below 130k
Title: Re: Accel Variable
Post by: hakcenter on September 25, 2015, 01:34:18 PM
A little bit more watching and I'll integrate it pretty soon.

I've been setting my idle to 40 (full open). Then snapping closed to 880 on take off. It's working pretty good, using the accel to keep it at idle when rpms fall then slightly increase over idle.. which would make it bounce back into 880. So making sure the turbo isn't accelerating while waiting at idle seems to be working pretty good!


          // -----
          // Idle Section
          idle_check = false;
          if (turbo_rpm <= idle_rpm) {
            vane_position = idle_position;
            idle_mode = true;
            idle_walkdown_mode = false;
          } else {
            idle_mode = false;
            if (idle_walkdown_mode) {
              if (last_vane_position >= min_position + two_cm) { vane_position = last_vane_position - two_cm; } else { vane_position = min_position; }
            } else if (turbo_accel[2] > 1){ vane_position = turbo_curve[0]; }
          }
Title: Re: Accel Variable
Post by: hakcenter on October 07, 2015, 06:47:38 PM
So I've fallen on this so far, anyone else is welcome to try it out as long as you have the accel variable


      if (turbo_rpm <= curve_rpm[4]) {
        if (turbo_rpm <= curve_rpm[0]) {
          // -----
          // Idle Section
          idle_check = false;
          if (turbo_rpm <= idle_rpm) {
            idle_mode = true;
            idle_walkdown_mode = false;
          } else {
            idle_mode = false;
          }
          if (turbo_accel[2] <= 2) { vane_position = idle_position; } else { vane_position = turbo_curve[0]; }
        } else {
          // -----
          // Curve section
               if (idle_walkdown_mode) {
                 if (last_vane_position >= min_position + half_cm) { vane_position = last_vane_position - half_cm; } else { vane_position = min_position; }
               }
          else if (turbo_rpm <= curve_rpm[1]) { vane_position = map(turbo_rpm, curve_rpm[0], curve_rpm[1], turbo_curve[0], turbo_curve[1]); }
          else if (turbo_rpm <= curve_rpm[2]) { vane_position = turbo_curve[1]; }
          else if (turbo_rpm <= curve_rpm[3]) { vane_position = map(turbo_rpm, curve_rpm[2], curve_rpm[3], turbo_curve[1], turbo_curve[2]); }
          else { vane_position = map(turbo_rpm, curve_rpm[3], curve_rpm[4], turbo_curve[2], turbo_curve[3]); }
        }
      } else if (turbo_rpm < top_end_rpm) {
        vane_position = map(turbo_rpm, curve_rpm[4], top_end_rpm, turbo_curve[3], turbo_curve[4]);
      } else {
        // -----
        // TOP End Control Section


also this at the back end of the section


  // Default Full Open Position if no RPM signal
  } else { vane_position = min_position; }
  if (turbo_rpm < idle_walkdown_rpm && idle_check) {
    idle_check = false;
    idle_walkdown_mode = true;
  }
  if (turbo_rpm > idle_walkdown_rpm && !idle_check) {
    idle_check = true;
    idle_walkdown_mode = false;
  }
  // Keep vane position within constraints
  constrain(vane_position, min_position, max_position);
}


I'll probably finalize it later by making the walkdown rpm slightly higher and check against acceleration instead of rpm.

So far the off idle response is super awesome, and I haven't had an issue with it going 40 > 800 and back and forth so seems about right atm. I'll update to 1.3.0 after maybe another month and running it.
Title: Re: Accel Variable
Post by: hakcenter on October 22, 2015, 11:00:05 AM
If I get a chance to drive my truck I'll probably release 1.2.0 with the variable added this weekend.
Title: Re: Accel Variable
Post by: Rx7man on October 23, 2015, 09:34:24 AM
cool :)
Title: Re: Accel Variable
Post by: me78569 on October 27, 2015, 10:07:12 PM
Gonna read through it in a next couple days. 
Title: Re: Accel Variable
Post by: hakcenter on October 30, 2015, 10:57:31 AM
Quote from: Rx7man on August 26, 2015, 03:29:24 PM
I had to try it

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
int var1 = 1;
int var2 = 2;
float var3 = var1;
float var4 = var2;

float var5 = var1/var2; //returns 0   the types are integers
float var6 = var3/var2; // should return 0.5, one of the
float var7 = var3/var4; //returns 0.5, both are floats

Serial.println(var5);
Serial.println(var6);
Serial.println(var7);


}

void loop() {
  // put your main code here, to run repeatedly:

}


returns:
0
0.5
0.5

int to float conversion is done implicitly in var3=var1, you don't need to specify it

I thought I would ressurect this post rx7man.

I had to typecast back to int, otherwise values were ALL over the place, 0, 255, etc...

turbo_accel[0] = (int) (turbo_rpm - last_turbo_rpm[0]) / 10.0f;
    last_turbo_rpm[0] = turbo_rpm;
    if (timer % 100 == 0) {
      turbo_accel[1] = (int) (turbo_rpm - last_turbo_rpm[1]) / 100.0f;
      last_turbo_rpm[1] = turbo_rpm;
    }

Figure that one out.

Looks like float math only goes up, not down. ie: ints can go up to floats, but floats can't be pressed down to ints without typecasting. I know a 'duh' moment, but wondering how smart the compiler really is.
Title: Re: Accel Variable
Post by: Rx7man on October 31, 2015, 01:16:36 AM
very weird... I've never needed to, and my example did work, but it is good practice to do it explicitly because you will notice it, while you may not notice an implicit one
Title: Re: Accel Variable
Post by: Rx7man on October 31, 2015, 01:19:19 AM
I could see it behaving strangely if your float was a bigger number than an INT could hold.. causing an overflow that doesn't get trapped
Title: Re: Accel Variable
Post by: hakcenter on October 31, 2015, 07:21:36 AM
Ya except at idle, accel is either -1, 0 or 1
Title: Re: Accel Variable
Post by: Rx7man on November 03, 2015, 08:08:56 AM
Ah.. I haven't studied the new code in a while...

I'm thinking of doing my turbo install when I get the 6 speed tranny so I don't run into any tranny mount interferences with the new pipe.
Title: Re: Accel Variable
Post by: hakcenter on November 03, 2015, 04:10:10 PM
That would be a good idea, especially if you use a 4" downpipe. My pipe fits with a 1/16th clearance next to the trans and then the frame too
Title: Re: Accel Variable
Post by: Rx7man on November 03, 2015, 09:54:50 PM
I notice a lot of my exhaust is getting pretty raggedy.. and when I was looking at it I figure I can run a straight piece of pipe all the way from the front to the back if I tuck it up a little higher and toward the frame a little more, and then I don't need a hump to get over the rear axle, which would simplify things a lot... Probably put a flex piece in just after the DP.

I can't remember.. did you use the 12V manifold or did you use the one for the turbo?  That would change the requirements a fair bit.  I think the auto tranny may be wider too, but I hear the NV5600's are beasts as well
Title: Re: Accel Variable
Post by: me78569 on November 04, 2015, 06:38:24 AM
My 4" downpipe has a hole rubbed in it, 

Anyways I gotta say the changes to the shaft speed calc sure did help.  I am not able to run 16 reads vs 32 reads without any spikes.  Very snappy and VERY responsive in terms of what I would expect to see the turbo speed doing when I am on/off the throttle. 
Title: Re: Accel Variable
Post by: hakcenter on November 04, 2015, 08:13:00 PM
Quote from: Rx7man on November 03, 2015, 09:54:50 PM
I notice a lot of my exhaust is getting pretty raggedy.. and when I was looking at it I figure I can run a straight piece of pipe all the way from the front to the back if I tuck it up a little higher and toward the frame a little more, and then I don't need a hump to get over the rear axle, which would simplify things a lot... Probably put a flex piece in just after the DP.

I can't remember.. did you use the 12V manifold or did you use the one for the turbo?  That would change the requirements a fair bit.  I think the auto tranny may be wider too, but I hear the NV5600's are beasts as well

stock late 2nd gen no egr with adapter plate.
Quote from: me78569 on November 04, 2015, 06:38:24 AM
My 4" downpipe has a hole rubbed in it, 

Anyways I gotta say the changes to the shaft speed calc sure did help.  I am not able to run 16 reads vs 32 reads without any spikes.  Very snappy and VERY responsive in terms of what I would expect to see the turbo speed doing when I am on/off the throttle. 

ya surprising when I spend more than a day coding things, thinking it through. I was timing a lot of sections and adjusting things. Overall I'm very happy with how everything is running, I'll get some more time maybe next week or so and remove the bottom end jitter (which is possible) so hopefully I can find a simple approach and get it dialed in.


On another note, I haven't honestly noticed any difference mpg wise between using cruise and not using it at all. I don't know if maybe the curves aren't aggressive enough though they seem to be just right to my ass dyno... /shrug

I think I'll re-adjust my cruise switch to be perf and start working on that. I also want to move the curves from ints to longs, to help with people possibly making them larger than they should be causing issues.
Title: Re: Accel Variable
Post by: me78569 on November 05, 2015, 08:17:48 AM
I would agree that I don't really see any MPG difference in ANY of the curves I have.  running the turbo at 12 cm or 14cm only vs the curve or vs etc etc doesn't seem to matter.

Strange to me, but oh well.  I can drive with 0 drive pressure with the turbo set wide open and get the same MPG as 9cm with 10 psi of drive hahah.

I should upload my code at some point, it has changed quite a lot since the last time you helped out.
Title: Re: Accel Variable
Post by: Rx7man on November 06, 2015, 10:12:53 PM
What are your boost pressures?  I found with my HX35, a 70mph cruise (4:10 gears ~2300 RPM) I usually need about 10 PSI boost or 15 PSI drive... pushing a headwind or with a trailer it'll quickly double, and my mileage CRASHES
Title: Re: Accel Variable
Post by: me78569 on November 07, 2015, 04:14:12 PM
Cruising at 55-60

boost seems to settle around 5ish psi with my current curve, bout 9cm typically

12-14cm curve bosot settles around 1-2

25cm boost and drive are 0. 

I was pretty surprised to not see much difference in mpg between the curves.

Title: Re: Accel Variable
Post by: Rx7man on November 07, 2015, 07:52:39 PM
5 PSI is nothing.. you won't notice a difference at that pressure.. but you start putting 15-20 PSI load on it and you do notice it... I'm going to start experimenting in a while
Title: Re: Accel Variable
Post by: me78569 on November 07, 2015, 08:04:36 PM
It is just strange how quickly mpg falls off with the hx35 as soon as you hit 5 psi.  The 351ve doesn't have that same issue.
Title: Re: Accel Variable
Post by: Rx7man on November 07, 2015, 09:04:49 PM
I'm always at about 8-10 PSI on my truck