Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Become a Premium Member and unlock a new, free course in leading technologies each month.

Solved

Posted on 2007-03-21

Hello,

I am trying to implement a function that calculates the position for a counter of a motor. I would like to store the postion values for the different times in a vector (or array?). This is the function I implemented:

void main(void)

{

float pi=0; //initial position; later != 0

float a=pi;

float vi=0; //initial velocity

float b=vi;

float qf; //final position

qf=8200; //approximately 2 turns

float c=3*qf;

float d=-2*qf;

float Tf=1; //final time

float Ti=0; //initial time

float Ts=0.01; //sampling time

float nmuestras = Tf/Ts;

int i;

for (i=1;i<=nmuestras;i++)

{

float tiempo=i*Ts; //real time

float t=tiempo/Tf;

/*

float *ptr;

float pos;

ptr = &pos;

*ptr = a+b*t+c*t^2+d*t^3;

*/

//pos_final(t);

float pos;

pos = a+b*t+c*t^2+d*t^3;

//float pos = a+b*t+c*t^2+d*t^3;

int k;

pos_vector[k] = pos;//put the counter value in the array for storing counter values

k++;

}

I get the following errors and don´t know how to get rid of them:

ompiling...

test control2.cpp

C:\datos\judith\proyecto_judith\pci 1784\test control2.cpp(18) : warning C4305: 'initializing' : truncation from 'const double' to 'float'

C:\datos\judith\proyecto_judith\pci 1784\test control2.cpp(37) : error C2296: '^' : illegal, left operand has type 'float'

C:\datos\judith\proyecto_judith\pci 1784\test control2.cpp(37) : error C2297: '^' : illegal, right operand has type 'float'

C:\datos\judith\proyecto_judith\pci 1784\test control2.cpp(40) : error C2065: 'pos_vector' : undeclared identifier

C:\datos\judith\proyecto_judith\pci 1784\test control2.cpp(40) : error C2109: subscript requires array or pointer type

C:\datos\judith\proyecto_judith\pci 1784\test control2.cpp(40) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data

C:\datos\judith\proyecto_judith\pci 1784\test control2.cpp(40) : error C2106: '=' : left operand must be l-value

Error executing cl.exe.

test control2.obj - 5 error(s), 2 warning(s)

Do I maybe have to include libraries or introduce pointers?

Judith

I am trying to implement a function that calculates the position for a counter of a motor. I would like to store the postion values for the different times in a vector (or array?). This is the function I implemented:

void main(void)

{

float pi=0; //initial position; later != 0

float a=pi;

float vi=0; //initial velocity

float b=vi;

float qf; //final position

qf=8200; //approximately 2 turns

float c=3*qf;

float d=-2*qf;

float Tf=1; //final time

float Ti=0; //initial time

float Ts=0.01; //sampling time

float nmuestras = Tf/Ts;

int i;

for (i=1;i<=nmuestras;i++)

{

float tiempo=i*Ts; //real time

float t=tiempo/Tf;

/*

float *ptr;

float pos;

ptr = &pos;

*ptr = a+b*t+c*t^2+d*t^3;

*/

//pos_final(t);

float pos;

pos = a+b*t+c*t^2+d*t^3;

//float pos = a+b*t+c*t^2+d*t^3;

int k;

pos_vector[k] = pos;//put the counter value in the array for storing counter values

k++;

}

I get the following errors and don´t know how to get rid of them:

ompiling...

test control2.cpp

C:\datos\judith\proyecto_j

C:\datos\judith\proyecto_j

C:\datos\judith\proyecto_j

C:\datos\judith\proyecto_j

C:\datos\judith\proyecto_j

C:\datos\judith\proyecto_j

C:\datos\judith\proyecto_j

Error executing cl.exe.

test control2.obj - 5 error(s), 2 warning(s)

Do I maybe have to include libraries or introduce pointers?

Judith

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

- Help others & share knowledge
- Earn cash & points
- Learn & ask questions

3 Comments

One of your main problems is that you do not seem to be aware that expressions involving mixed decimal types always result in a value of type double. To assign the result of such an expression to a float you need to perform a cast.

e.g.

float nmuestras = Tf/Ts; //should change to float nmuestras = (float) (Tf/Ts);

You also have a problem with this expression,

pos = a+b*t+c*t^2+d*t^3

^ is the XOR operator in C++. If you want to raise numbers to certain powers you have to use the pow() function in the Math library.

e.g. pos = (float) (a+b*t+c*pow(t, 2)+d*pow(t, 3));

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

Earn Certification

HTML5 Specialist - Certification

Free withPremium

Course of the Month8 days, 3 hours left to enroll

Join the community of 500,000 technology professionals and ask your questions.