Understanding of struct

Hello everyone
today I need help of your knowledge of struct
I use lipo battry as source of arduino motor shield.
lipo battery’s voltage keep going down as time goes by
then 12.5V and 11.6V’s 30pwm cannot be the same speed
so I calculate the voltage and make pwm be equal
but when I use struct, variable which saves the pwm is interpret as 0
please read part of my code.

#include <Servo.h>

Servo myservo;

const byte Led1 = 4;
const byte Led2 = 5;
const byte ServoPin =  6;
const byte Motor_pwm = 11;
const byte Motor_dir = 12;

int data[2];

boolean Parking_State = false;

float PWM;
int value;
float VOUT;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0;
float R2 = 10000.0;

/*******************************************************************************************************************************/

void setup()
{
  Serial.begin(57600);
  myservo.attach(ServoPin);

  pinMode(A0, INPUT);
  pinMode(Motor_dir, OUTPUT);
  pinMode(Motor_pwm, OUTPUT);
  pinMode(Led1, OUTPUT);
  pinMode(Led2, OUTPUT);
  digitalWrite(Led1,HIGH);
  digitalWrite(Led2,HIGH);

  myservo.write(95);
  analogWrite(Motor_pwm,0);
  Serial.flush();
}

/*******************************************************************************************************************************/

void loop(){
  for(int i = 0; i < 2; i++){
    data[i] = Serial.read();
    delay(3);
  }
  PWM = Parking_pwm();
  if(data[0] + data[1] ==255){
    Choose_Parking_State(data[0]);
    if(Parking_State == false)
      Driving_algorithm(data[0]);
    else if(Parking_State == true)
      Parking_algorithm(data[0]);
  }

struct CarControlData_2
{
  int Var;
  byte Degree;
  byte Direction;
  int MotorPWM;
  byte LED1;
  byte LED2;
};

#define PARK_SIZE 15

CarControlData_2 ParkControlDataTable[PARK_SIZE] =
{
  {154,  45,  LOW, PWM,  LOW,  LOW},  // FR50
  {153,  45, NULL,   0, HIGH, HIGH},  // HR50
  {152,  45, HIGH, PWM,  LOW,  LOW},  // BR50

  {151,  70,  LOW, PWM,  LOW,  LOW},  // FR25
  {150,  70, NULL,   0, HIGH, HIGH},  // HR25
  {149,  70, HIGH, PWM,  LOW,  LOW},  // BR25

  {148,  95,  LOW, PWM,  LOW,  LOW},  // FS00
  {147,  95, NULL,   0, HIGH, HIGH},  // HS00
  {146,  95, HIGH, PWM,  LOW,  LOW},  // BS00

  {145, 120,  LOW, PWM,  LOW,  LOW},  // FL25
  {144, 120, NULL,   0, HIGH, HIGH},  // HL25
  {143, 120, HIGH, PWM,  LOW,  LOW},  // BL25

  {142, 145,  LOW, PWM,  LOW,  LOW},  // FL50
  {141, 145, NULL,   0, HIGH, HIGH},  // HL50
  {140, 145, HIGH, PWM,  LOW,  LOW}   // BL50
};

void Parking_algorithm(int Var)
{
  int Var2 = 255 - Var;
  for(int i =0; i < PARK_SIZE; i++)
  {
    CarControlData_2 ParkControlDataItem = ParkControlDataTable[i];

    if(Var == ParkControlDataItem.Var || Var2 == ParkControlDataItem.Var)
    {
      myservo.write(ParkControlDataItem.Degree);
      digitalWrite(Motor_dir,ParkControlDataItem.Direction);
      analogWrite(Motor_pwm, ParkControlDataItem.MotorPWM);
      digitalWrite(Led1,ParkControlDataItem.LED1);
      digitalWrite(Led2,ParkControlDataItem.LED2);
    }
  }
}

/*******************************************************************************************************************************/

float Parking_pwm()
{
  value = analogRead(A0);
  vout = (value * 5.0) / 1024.0;
  vin = vout / (R2/(R1+R2));
  float pwm = (48 * 12.5)/vin;
  return pwm;
}

this is just a part of my code
struct MotorPWM variable should saves Parking_pwm() 's returned variable
but it doesnt

How could I saves the returned value in struct MotoPWM variable?
please help me

data[i] = Serial.read(); don't you want to check there's something to read before reading it?

PWM = Parking_pwm();And . . ?

AWOL:
data[i] = Serial.read(); don't you want to check there's something to read before reading it?

when I use Serial.available()
its too slow to read my datas
and in struct my MotorPWM 's data is PWM
so PWM should be returned value I thought
if I am wrong how could I use returned value in struct?
that was my question not Serial

I can't see any comments in your code, so the intent is not clear to me, but you don't appear to do anything with the variable called "PWM"

when I use Serial.available()
its too slow to read my datas

I simultaneously don't understand and don't believe that statement.

when I use Serial.available()
its too slow to read my datas

Complete nonsense. Putting delay() in the loop that reads possibly non-existant data is NOT how to speed things up.

PaulS:
Complete nonsense. Putting delay() in the loop that reads possibly non-existant data is NOT how to speed things up.

dont know why but when I use Serial.available() whit no delay(4) state
arduino receive pair of datas per 10seconds
so I use some kind of checksum.
if two datas sum is equal to 255
do what i intended

AWOL:

 PWM = Parking_pwm();

And . . ?

AWOL:
I can't see any comments in your code, so the intent is not clear to me, but you don't appear to do anything with the variable called "PWM"
I simultaneously don't understand and don't believe that statement.

CarControlData_2 ParkControlDataTable[PARK_SIZE] =
{
  {154,  45,  LOW, PWM,  LOW,  LOW},  // FR50
  {153,  45, NULL,   0, HIGH, HIGH},  // HR50
  {152,  45, HIGH, PWM,  LOW,  LOW},  // BR50

  {151,  70,  LOW, PWM,  LOW,  LOW},  // FR25
  {150,  70, NULL,   0, HIGH, HIGH},  // HR25
  {149,  70, HIGH, PWM,  LOW,  LOW},  // BR25

  {148,  95,  LOW, PWM,  LOW,  LOW},  // FS00
  {147,  95, NULL,   0, HIGH, HIGH},  // HS00
  {146,  95, HIGH, PWM,  LOW,  LOW},  // BS00

  {145, 120,  LOW, PWM,  LOW,  LOW},  // FL25
  {144, 120, NULL,   0, HIGH, HIGH},  // HL25
  {143, 120, HIGH, PWM,  LOW,  LOW},  // BL25

  {142, 145,  LOW, PWM,  LOW,  LOW},  // FL50
  {141, 145, NULL,   0, HIGH, HIGH},  // HL50
  {140, 145, HIGH, PWM,  LOW,  LOW}   // BL50
};

I want to use PWM variable here
but maybe this is wrong way to do
and thats why I want to ask to professional user

I want to use PWM variable here

What is the value of PWM when that array is initialised?
PWM is a global - why bother also trying to keep a copy of the value in a struct?

thats why I want to ask to professional user

Sorry, I do not know any - maybe try over in the gigs section.

AWOL:
What is the value of PWM when that array is initialised?
PWM is a global - why bother also trying to keep a copy of the value in a struct?
Sorry, I do not know any - maybe try over in the gigs section.

struct CarControlData_2
{
  int Var;
  byte Degree;
  byte Direction;
  float MotorPWM;
  byte LED1;
  byte LED2;
};

#define PARK_SIZE 15

CarControlData_2 ParkControlDataTable[PARK_SIZE] =
{
  {154,  45,  LOW, PWM,  LOW,  LOW},  // FR50
  {153,  45, NULL,   0, HIGH, HIGH},  // HR50
  {152,  45, HIGH, PWM,  LOW,  LOW},  // BR50

  {151,  70,  LOW, PWM,  LOW,  LOW},  // FR25
  {150,  70, NULL,   0, HIGH, HIGH},  // HR25
  {149,  70, HIGH, PWM,  LOW,  LOW},  // BR25

  {148,  95,  LOW, PWM,  LOW,  LOW},  // FS00
  {147,  95, NULL,   0, HIGH, HIGH},  // HS00
  {146,  95, HIGH, PWM,  LOW,  LOW},  // BS00

  {145, 120,  LOW, PWM,  LOW,  LOW},  // FL25
  {144, 120, NULL,   0, HIGH, HIGH},  // HL25
  {143, 120, HIGH, PWM,  LOW,  LOW},  // BL25

  {142, 145,  LOW, PWM,  LOW,  LOW},  // FL50
  {141, 145, NULL,   0, HIGH, HIGH},  // HL50
  {140, 145, HIGH, PWM,  LOW,  LOW}   // BL50
};

void Parking_algorithm(int Var)
{
  int Var2 = 255 - Var;
  for(int i =0; i < PARK_SIZE; i++)
  {
    CarControlData_2 ParkControlDataItem = ParkControlDataTable[i];

    if(Var == ParkControlDataItem.Var || Var2 == ParkControlDataItem.Var)
    {
      myservo.write(ParkControlDataItem.Degree);
      digitalWrite(Motor_dir,ParkControlDataItem.Direction);
      analogWrite(Motor_pwm, ParkControlDataItem.MotorPWM);
      digitalWrite(Led1,ParkControlDataItem.LED1);
      digitalWrite(Led2,ParkControlDataItem.LED2);
    }
  }
}

/*******************************************************************************************************************************/

float Parking_pwm()
{
  value = analogRead(A0);
  vout = (value * 5.0) / 1024.0;
  vin = vout / (R2/(R1+R2));
  float pwm = (48 * 12.5)/vin;
  return pwm;
}

MotorPWM is that
before this code there were hundred of if and else if statements
so I try to use struct
and I like I told you before my power source of motor driver is lipo battery
so when lipo battery’s voltage is going low
so the same pwm speed is different compare to before

If you read my code. I calculate the voltage going into motor shield
and trying to make the same speed when how much battery left
my standard is 12V 30pwm. PWM is speed of pwm when voltage is 12V
this means that when battery is 11.5V PWM is bigger than 30pwm
this is why I trying to do this process

The values in the array of structs are NOT bound to the value in PWM. They are a copy of what was in PWM when the array is initialized. What AWOL is asking is WHAT that value is. Why can’t you answer such a simple question?