Dynomotion

Group: DynoMotion Message: 12831 From: nofear53 Date: 2/22/2016
Subject: C program Error

Below is a simplified code snippet that is driving me crazy.  Any help would be greatly appreciated.


1. The last line keeps throwing an error saying [pointer expected].


I'm trying to set the persist value it points to to the new value from the first structure's element axis[0].rawEncPosition.  I know that there is a valid value as it prints fine, but why is it not allowing me to assign it to the pointer's memory loc? Maybe I'm missing something obvious...


2. I've somewhat remedied this second issue, but why can't I assign values to a position in an array by using a variable? For instance:


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch}; 


Where all of the parameters were defined just above it?

Fails because all are variables.  I know if I #define them to be constants it works, but that seems rather odd.


Any ideas?


Thanks in advance! 


int *x1Pos = &persist.UserData[101]; // x1 location input


typedef struct {

int rawEncPosition; //raw encoder position value

float measuredPos; //encoder postion converted to mm or degrees

float degrees; //rotation normalized for coordinate system neg-0-pos

float coordPos; //linear normalized for coordinate system neg-0-pos

}AXIS;


AXIS axis[6];


float steps = 800;

float xyPitch = (.25 * 25.4)/steps;

float zPtich = (1.0 * 25.4)/steps;

float rotPitch = (1/20);


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch};

float coordZero[6] = {xCoordZero,yCoordZero,zCoordZero,zCoordZero,xRotCoordZero,yRotCoordZero};


void ready_axes(void)

{

int i;

for(i=0; i<6; i++)

{

axis[i].rawEncPosition = chan[i].Position; //store raw encoder values

printf("Raw Encoder: %i\n",axis[i].rawEncPosition); //<<<<<<<<<<<<PRINTS EXPECTED VALUE 

axis[i].measuredPos = axis[i].rawEncPosition * normalizeScalar[i]; //convert encoder position to mm

axis[i].degrees = axis[i].measuredPos - coordZero[i];

axis[i].coordPos = axis[i].degrees;

}

}


*x1Pos = axis[0].rawEncPosition;



Group: DynoMotion Message: 12833 From: Tom Kerekes Date: 2/22/2016
Subject: Re: C program Error
Hi,

#1 - Global C Variables (values outside functions may be initialized to constant values by the compiler before any execution begins.  But those values must be constants that the compiler can determine to be known beforehand.  This happens at Program Load time. Your structure variable axis[0].rawEncPosition;  is a variable that changes (based on current motor position).  So the compiler can not write that to something before execution.  And besides the pointer itself (x1Pos) can point to different things which in this case is even outside of the C Program so that isn't even part of the Loaded Program.

Situations like this require executable code that occurs within a function to perform the assignment at a particular time when (hopefully) everything involved has been defined.  ie the value of axis[0].rawEncPosition and where xiPos points.

#2 - In  similar way you can only initialize arrays with that syntax with constants that the compiler knows at compile time.

Again to assign the value of a variable to an array element you must use executable code.  To do the assignment when your program starts execution at the beginning of your main() function you might add:

normalizeScalar[0]=normalizeScalar[1]=xyPitch;
normalizeScalar[2]=normalizeScalar[3]=zPitch;
normalizeScalar[4]=normalizeScalar[5]=rotPitch;

HTH
Regards
TK

On 2/22/2016 5:53 PM, b.sahilu@... [DynoMotion] wrote:
 

Below is a simplified code snippet that is driving me crazy.  Any help would be greatly appreciated.


1. The last line keeps throwing an error saying [pointer expected].


I'm trying to set the persist value it points to to the new value from the first structure's element axis[0].rawEncPosition.  I know that there is a valid value as it prints fine, but why is it not allowing me to assign it to the pointer's memory loc? Maybe I'm missing something obvious...


2. I've somewhat remedied this second issue, but why can't I assign values to a position in an array by using a variable? For instance:


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch}; 


Where all of the parameters were defined just above it?

Fails because all are variables.  I know if I #define them to be constants it works, but that seems rather odd.


Any ideas?


Thanks in advance! 


int *x1Pos = &persist.UserData[101]; // x1 location input


typedef struct {

int rawEncPosition; //raw encoder position value

float measuredPos; //encoder postion converted to mm or degrees

float degrees; //rotation normalized for coordinate system neg-0-pos

float coordPos; //linear normalized for coordinate system neg-0-pos

}AXIS;


AXIS axis[6];


float steps = 800;

float xyPitch = (.25 * 25.4)/steps;

float zPtich = (1.0 * 25.4)/steps;

float rotPitch = (1/20);


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch};

float coordZero[6] = {xCoordZero,yCoordZero,zCoordZero,zCoordZero,xRotCoordZero,yRotCoordZero};


void ready_axes(void)

{

int i;

for(i=0; i<6; i++)

{

axis[i].rawEncPosition = chan[i].Position; //store raw encoder values

printf("Raw Encoder: %i\n",axis[i].rawEncPosition); //<<<<<<<<<<<<PRINTS EXPECTED VALUE 

axis[i].measuredPos = axis[i].rawEncPosition * normalizeScalar[i]; //convert encoder position to mm

axis[i].degrees = axis[i].measuredPos - coordZero[i];

axis[i].coordPos = axis[i].degrees;

}

}


*x1Pos = axis[0].rawEncPosition;




Group: DynoMotion Message: 12835 From: Bruk S Date: 2/22/2016
Subject: Re: C program Error
Tom,

Thanks for the clarification, but how come:

*xPos = chan[0].Position works?

How was the CHAN structure defined that it behaves differently? 



On Mon, Feb 22, 2016 at 6:35 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi,

#1 - Global C Variables (values outside functions may be initialized to constant values by the compiler before any execution begins.  But those values must be constants that the compiler can determine to be known beforehand.  This happens at Program Load time. Your structure variable axis[0].rawEncPosition;  is a variable that changes (based on current motor position).  So the compiler can not write that to something before execution.  And besides the pointer itself (x1Pos) can point to different things which in this case is even outside of the C Program so that isn't even part of the Loaded Program.

Situations like this require executable code that occurs within a function to perform the assignment at a particular time when (hopefully) everything involved has been defined.  ie the value of axis[0].rawEncPosition and where xiPos points.

#2 - In  similar way you can only initialize arrays with that syntax with constants that the compiler knows at compile time.

Again to assign the value of a variable to an array element you must use executable code.  To do the assignment when your program starts execution at the beginning of your main() function you might add:

normalizeScalar[0]=normalizeScalar[1]=xyPitch;
normalizeScalar[2]=normalizeScalar[3]=zPitch;
normalizeScalar[4]=normalizeScalar[5]=rotPitch;

HTH
Regards
TK



On 2/22/2016 5:53 PM, b.sahilu@... [DynoMotion] wrote:
 

Below is a simplified code snippet that is driving me crazy.  Any help would be greatly appreciated.


1. The last line keeps throwing an error saying [pointer expected].


I'm trying to set the persist value it points to to the new value from the first structure's element axis[0].rawEncPosition.  I know that there is a valid value as it prints fine, but why is it not allowing me to assign it to the pointer's memory loc? Maybe I'm missing something obvious...


2. I've somewhat remedied this second issue, but why can't I assign values to a position in an array by using a variable? For instance:


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch}; 


Where all of the parameters were defined just above it?

Fails because all are variables.  I know if I #define them to be constants it works, but that seems rather odd.


Any ideas?


Thanks in advance! 


int *x1Pos = &persist.UserData[101]; // x1 location input


typedef struct {

int rawEncPosition; //raw encoder position value

float measuredPos; //encoder postion converted to mm or degrees

float degrees; //rotation normalized for coordinate system neg-0-pos

float coordPos; //linear normalized for coordinate system neg-0-pos

}AXIS;


AXIS axis[6];


float steps = 800;

float xyPitch = (.25 * 25.4)/steps;

float zPtich = (1.0 * 25.4)/steps;

float rotPitch = (1/20);


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch};

float coordZero[6] = {xCoordZero,yCoordZero,zCoordZero,zCoordZero,xRotCoordZero,yRotCoordZero};


void ready_axes(void)

{

int i;

for(i=0; i<6; i++)

{

axis[i].rawEncPosition = chan[i].Position; //store raw encoder values

printf("Raw Encoder: %i\n",axis[i].rawEncPosition); //<<<<<<<<<<<<PRINTS EXPECTED VALUE 

axis[i].measuredPos = axis[i].rawEncPosition * normalizeScalar[i]; //convert encoder position to mm

axis[i].degrees = axis[i].measuredPos - coordZero[i];

axis[i].coordPos = axis[i].degrees;

}

}


*x1Pos = axis[0].rawEncPosition;





Group: DynoMotion Message: 12836 From: Tom Kerekes Date: 2/22/2016
Subject: Re: C program Error
I don't understand what you mean.  Send the complete program as an attachment.

Regards
TK

On 2/22/2016 7:12 PM, Bruk S b.sahilu@... [DynoMotion] wrote:
 
Tom,

Thanks for the clarification, but how come:

*xPos = chan[0].Position works?

How was the CHAN structure defined that it behaves differently? 



On Mon, Feb 22, 2016 at 6:35 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi,

#1 - Global C Variables (values outside functions may be initialized to constant values by the compiler before any execution begins.  But those values must be constants that the compiler can determine to be known beforehand.  This happens at Program Load time. Your structure variable axis[0].rawEncPosition;  is a variable that changes (based on current motor position).  So the compiler can not write that to something before execution.  And besides the pointer itself (x1Pos) can point to different things which in this case is even outside of the C Program so that isn't even part of the Loaded Program.

Situations like this require executable code that occurs within a function to perform the assignment at a particular time when (hopefully) everything involved has been defined.  ie the value of axis[0].rawEncPosition and where xiPos points.

#2 - In  similar way you can only initialize arrays with that syntax with constants that the compiler knows at compile time.

Again to assign the value of a variable to an array element you must use executable code.  To do the assignment when your program starts execution at the beginning of your main() function you might add:

normalizeScalar[0]=normalizeScalar[1]=xyPitch;
normalizeScalar[2]=normalizeScalar[3]=zPitch;
normalizeScalar[4]=normalizeScalar[5]=rotPitch;

HTH
Regards
TK



On 2/22/2016 5:53 PM, b.sahilu@... [DynoMotion] wrote:
 

Below is a simplified code snippet that is driving me crazy.  Any help would be greatly appreciated.


1. The last line keeps throwing an error saying [pointer expected].


I'm trying to set the persist value it points to to the new value from the first structure's element axis[0].rawEncPosition.  I know that there is a valid value as it prints fine, but why is it not allowing me to assign it to the pointer's memory loc? Maybe I'm missing something obvious...


2. I've somewhat remedied this second issue, but why can't I assign values to a position in an array by using a variable? For instance:


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch}; 


Where all of the parameters were defined just above it?

Fails because all are variables.  I know if I #define them to be constants it works, but that seems rather odd.


Any ideas?


Thanks in advance! 


int *x1Pos = &persist.UserData[101]; // x1 location input


typedef struct {

int rawEncPosition; //raw encoder position value

float measuredPos; //encoder postion converted to mm or degrees

float degrees; //rotation normalized for coordinate system neg-0-pos

float coordPos; //linear normalized for coordinate system neg-0-pos

}AXIS;


AXIS axis[6];


float steps = 800;

float xyPitch = (.25 * 25.4)/steps;

float zPtich = (1.0 * 25.4)/steps;

float rotPitch = (1/20);


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch};

float coordZero[6] = {xCoordZero,yCoordZero,zCoordZero,zCoordZero,xRotCoordZero,yRotCoordZero};


void ready_axes(void)

{

int i;

for(i=0; i<6; i++)

{

axis[i].rawEncPosition = chan[i].Position; //store raw encoder values

printf("Raw Encoder: %i\n",axis[i].rawEncPosition); //<<<<<<<<<<<<PRINTS EXPECTED VALUE 

axis[i].measuredPos = axis[i].rawEncPosition * normalizeScalar[i]; //convert encoder position to mm

axis[i].degrees = axis[i].measuredPos - coordZero[i];

axis[i].coordPos = axis[i].degrees;

}

}


*x1Pos = axis[0].rawEncPosition;






Group: DynoMotion Message: 12837 From: Bruk S Date: 2/22/2016
Subject: Re: C program Error
Tom,

Ultimately the objective with this program is to create a collision detection algorithm.  I will have a gimbal like mechanism that I will manipulate using 2 rotational motors.  From these I will determine the equation of the plane at it's current position and with another known point, which I manipulate using 3 motors for XYZ, I should know the distance between the plane and the point.  Based on a threshold, I should be able to avoid collision of the point and the plane.

In the mean-time, I wanted to see if I could output live data stream to my custom app which was where I ran into the error of assigning the calculated value to the pointer *xPos.

You'll notice in the update_current_rawPos() function, the only one I have using the custom structure is *xPos. The others are assigned their values using chan[i].Position.  I'm still a bit flustered as to what the difference is.

I've attached the program. 

On Mon, Feb 22, 2016 at 7:27 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

I don't understand what you mean.  Send the complete program as an attachment.

Regards
TK



On 2/22/2016 7:12 PM, Bruk S b.sahilu@... [DynoMotion] wrote:
 
Tom,

Thanks for the clarification, but how come:

*xPos = chan[0].Position works?

How was the CHAN structure defined that it behaves differently? 



On Mon, Feb 22, 2016 at 6:35 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi,

#1 - Global C Variables (values outside functions may be initialized to constant values by the compiler before any execution begins.  But those values must be constants that the compiler can determine to be known beforehand.  This happens at Program Load time. Your structure variable axis[0].rawEncPosition;  is a variable that changes (based on current motor position).  So the compiler can not write that to something before execution.  And besides the pointer itself (x1Pos) can point to different things which in this case is even outside of the C Program so that isn't even part of the Loaded Program.

Situations like this require executable code that occurs within a function to perform the assignment at a particular time when (hopefully) everything involved has been defined.  ie the value of axis[0].rawEncPosition and where xiPos points.

#2 - In  similar way you can only initialize arrays with that syntax with constants that the compiler knows at compile time.

Again to assign the value of a variable to an array element you must use executable code.  To do the assignment when your program starts execution at the beginning of your main() function you might add:

normalizeScalar[0]=normalizeScalar[1]=xyPitch;
normalizeScalar[2]=normalizeScalar[3]=zPitch;
normalizeScalar[4]=normalizeScalar[5]=rotPitch;

HTH
Regards
TK



On 2/22/2016 5:53 PM, b.sahilu@... [DynoMotion] wrote:
 

Below is a simplified code snippet that is driving me crazy.  Any help would be greatly appreciated.


1. The last line keeps throwing an error saying [pointer expected].


I'm trying to set the persist value it points to to the new value from the first structure's element axis[0].rawEncPosition.  I know that there is a valid value as it prints fine, but why is it not allowing me to assign it to the pointer's memory loc? Maybe I'm missing something obvious...


2. I've somewhat remedied this second issue, but why can't I assign values to a position in an array by using a variable? For instance:


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch}; 


Where all of the parameters were defined just above it?

Fails because all are variables.  I know if I #define them to be constants it works, but that seems rather odd.


Any ideas?


Thanks in advance! 


int *x1Pos = &persist.UserData[101]; // x1 location input


typedef struct {

int rawEncPosition; //raw encoder position value

float measuredPos; //encoder postion converted to mm or degrees

float degrees; //rotation normalized for coordinate system neg-0-pos

float coordPos; //linear normalized for coordinate system neg-0-pos

}AXIS;


AXIS axis[6];


float steps = 800;

float xyPitch = (.25 * 25.4)/steps;

float zPtich = (1.0 * 25.4)/steps;

float rotPitch = (1/20);


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch};

float coordZero[6] = {xCoordZero,yCoordZero,zCoordZero,zCoordZero,xRotCoordZero,yRotCoordZero};


void ready_axes(void)

{

int i;

for(i=0; i<6; i++)

{

axis[i].rawEncPosition = chan[i].Position; //store raw encoder values

printf("Raw Encoder: %i\n",axis[i].rawEncPosition); //<<<<<<<<<<<<PRINTS EXPECTED VALUE 

axis[i].measuredPos = axis[i].rawEncPosition * normalizeScalar[i]; //convert encoder position to mm

axis[i].degrees = axis[i].measuredPos - coordZero[i];

axis[i].coordPos = axis[i].degrees;

}

}


*x1Pos = axis[0].rawEncPosition;







  @@attachment@@
Group: DynoMotion Message: 12838 From: Tom Kerekes Date: 2/22/2016
Subject: Re: C program Error [1 Attachment]
Hi Bruk,

I just remembered I think we met at the show!

But I see in your program you use the variable name "axis" two different ways:

#1 - as a global Array of AXIS Structures
AXIS axis[6];

# 2 - as an integer function parameter
void update_current_rawPos(int axis)
{
    switch (axis)
    {
        case axis_X1:
        *x1Pos = axis[axis_X1].rawEncPosition;



The C language allows this (and doesn't warn you about it).  The C compiler always assumes the meaning of the more local scope.  So within the update function it is an integer.  But outside the function it is an array of structures.  The compiler sees you trying to treat an integer as an array (an array name is really a pointer to a list of things) and give the error "expecting a pointer".

So use a different name like axis_channel within the function and it should work.

HTH
Regards
TK




On 2/22/2016 7:42 PM, Bruk S b.sahilu@... [DynoMotion] wrote:
 
Tom,

Ultimately the objective with this program is to create a collision detection algorithm.  I will have a gimbal like mechanism that I will manipulate using 2 rotational motors.  From these I will determine the equation of the plane at it's current position and with another known point, which I manipulate using 3 motors for XYZ, I should know the distance between the plane and the point.  Based on a threshold, I should be able to avoid collision of the point and the plane.

In the mean-time, I wanted to see if I could output live data stream to my custom app which was where I ran into the error of assigning the calculated value to the pointer *xPos.

You'll notice in the update_current_rawPos() function, the only one I have using the custom structure is *xPos. The others are assigned their values using chan[i].Position.  I'm still a bit flustered as to what the difference is.

I've attached the program. 

On Mon, Feb 22, 2016 at 7:27 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

I don't understand what you mean.  Send the complete program as an attachment.

Regards
TK



On 2/22/2016 7:12 PM, Bruk S b.sahilu@... [DynoMotion] wrote:
 
Tom,

Thanks for the clarification, but how come:

*xPos = chan[0].Position works?

How was the CHAN structure defined that it behaves differently? 



On Mon, Feb 22, 2016 at 6:35 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi,

#1 - Global C Variables (values outside functions may be initialized to constant values by the compiler before any execution begins.  But those values must be constants that the compiler can determine to be known beforehand.  This happens at Program Load time. Your structure variable axis[0].rawEncPosition;  is a variable that changes (based on current motor position).  So the compiler can not write that to something before execution.  And besides the pointer itself (x1Pos) can point to different things which in this case is even outside of the C Program so that isn't even part of the Loaded Program.

Situations like this require executable code that occurs within a function to perform the assignment at a particular time when (hopefully) everything involved has been defined.  ie the value of axis[0].rawEncPosition and where xiPos points.

#2 - In  similar way you can only initialize arrays with that syntax with constants that the compiler knows at compile time.

Again to assign the value of a variable to an array element you must use executable code.  To do the assignment when your program starts execution at the beginning of your main() function you might add:

normalizeScalar[0]=normalizeScalar[1]=xyPitch;
normalizeScalar[2]=normalizeScalar[3]=zPitch;
normalizeScalar[4]=normalizeScalar[5]=rotPitch;

HTH
Regards
TK



On 2/22/2016 5:53 PM, b.sahilu@... [DynoMotion] wrote:
 

Below is a simplified code snippet that is driving me crazy.  Any help would be greatly appreciated.


1. The last line keeps throwing an error saying [pointer expected].


I'm trying to set the persist value it points to to the new value from the first structure's element axis[0].rawEncPosition.  I know that there is a valid value as it prints fine, but why is it not allowing me to assign it to the pointer's memory loc? Maybe I'm missing something obvious...


2. I've somewhat remedied this second issue, but why can't I assign values to a position in an array by using a variable? For instance:


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch}; 


Where all of the parameters were defined just above it?

Fails because all are variables.  I know if I #define them to be constants it works, but that seems rather odd.


Any ideas?


Thanks in advance! 


int *x1Pos = &persist.UserData[101]; // x1 location input


typedef struct {

int rawEncPosition; //raw encoder position value

float measuredPos; //encoder postion converted to mm or degrees

float degrees; //rotation normalized for coordinate system neg-0-pos

float coordPos; //linear normalized for coordinate system neg-0-pos

}AXIS;


AXIS axis[6];


float steps = 800;

float xyPitch = (.25 * 25.4)/steps;

float zPtich = (1.0 * 25.4)/steps;

float rotPitch = (1/20);


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch};

float coordZero[6] = {xCoordZero,yCoordZero,zCoordZero,zCoordZero,xRotCoordZero,yRotCoordZero};


void ready_axes(void)

{

int i;

for(i=0; i<6; i++)

{

axis[i].rawEncPosition = chan[i].Position; //store raw encoder values

printf("Raw Encoder: %i\n",axis[i].rawEncPosition); //<<<<<<<<<<<<PRINTS EXPECTED VALUE 

axis[i].measuredPos = axis[i].rawEncPosition * normalizeScalar[i]; //convert encoder position to mm

axis[i].degrees = axis[i].measuredPos - coordZero[i];

axis[i].coordPos = axis[i].degrees;

}

}


*x1Pos = axis[0].rawEncPosition;








Group: DynoMotion Message: 12839 From: Bruk S Date: 2/22/2016
Subject: Re: C program Error
Tom,

Yes we met at the show! Glad you remembered! 

By the way, you're awesome! That was it! I changed the passed in variable name to desired_axis so that it wouldn't confuse it.

I can finally move forward with my life now! Thanks again for being so helpful.

I'll keep you posted with the progress of the project.



On Mon, Feb 22, 2016 at 9:42 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi Bruk,

I just remembered I think we met at the show!

But I see in your program you use the variable name "axis" two different ways:

#1 - as a global Array of AXIS Structures
AXIS axis[6];

# 2 - as an integer function parameter
void update_current_rawPos(int axis)
{
    switch (axis)
    {
        case axis_X1:
        *x1Pos = axis[axis_X1].rawEncPosition;



The C language allows this (and doesn't warn you about it).  The C compiler always assumes the meaning of the more local scope.  So within the update function it is an integer.  But outside the function it is an array of structures.  The compiler sees you trying to treat an integer as an array (an array name is really a pointer to a list of things) and give the error "expecting a pointer".

So use a different name like axis_channel within the function and it should work.

HTH
Regards
TK






On 2/22/2016 7:42 PM, Bruk S b.sahilu@... [DynoMotion] wrote:
 
Tom,

Ultimately the objective with this program is to create a collision detection algorithm.  I will have a gimbal like mechanism that I will manipulate using 2 rotational motors.  From these I will determine the equation of the plane at it's current position and with another known point, which I manipulate using 3 motors for XYZ, I should know the distance between the plane and the point.  Based on a threshold, I should be able to avoid collision of the point and the plane.

In the mean-time, I wanted to see if I could output live data stream to my custom app which was where I ran into the error of assigning the calculated value to the pointer *xPos.

You'll notice in the update_current_rawPos() function, the only one I have using the custom structure is *xPos. The others are assigned their values using chan[i].Position.  I'm still a bit flustered as to what the difference is.

I've attached the program. 

On Mon, Feb 22, 2016 at 7:27 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

I don't understand what you mean.  Send the complete program as an attachment.

Regards
TK



On 2/22/2016 7:12 PM, Bruk S b.sahilu@... [DynoMotion] wrote:
 
Tom,

Thanks for the clarification, but how come:

*xPos = chan[0].Position works?

How was the CHAN structure defined that it behaves differently? 



On Mon, Feb 22, 2016 at 6:35 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi,

#1 - Global C Variables (values outside functions may be initialized to constant values by the compiler before any execution begins.  But those values must be constants that the compiler can determine to be known beforehand.  This happens at Program Load time. Your structure variable axis[0].rawEncPosition;  is a variable that changes (based on current motor position).  So the compiler can not write that to something before execution.  And besides the pointer itself (x1Pos) can point to different things which in this case is even outside of the C Program so that isn't even part of the Loaded Program.

Situations like this require executable code that occurs within a function to perform the assignment at a particular time when (hopefully) everything involved has been defined.  ie the value of axis[0].rawEncPosition and where xiPos points.

#2 - In  similar way you can only initialize arrays with that syntax with constants that the compiler knows at compile time.

Again to assign the value of a variable to an array element you must use executable code.  To do the assignment when your program starts execution at the beginning of your main() function you might add:

normalizeScalar[0]=normalizeScalar[1]=xyPitch;
normalizeScalar[2]=normalizeScalar[3]=zPitch;
normalizeScalar[4]=normalizeScalar[5]=rotPitch;

HTH
Regards
TK



On 2/22/2016 5:53 PM, b.sahilu@... [DynoMotion] wrote:
 

Below is a simplified code snippet that is driving me crazy.  Any help would be greatly appreciated.


1. The last line keeps throwing an error saying [pointer expected].


I'm trying to set the persist value it points to to the new value from the first structure's element axis[0].rawEncPosition.  I know that there is a valid value as it prints fine, but why is it not allowing me to assign it to the pointer's memory loc? Maybe I'm missing something obvious...


2. I've somewhat remedied this second issue, but why can't I assign values to a position in an array by using a variable? For instance:


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch}; 


Where all of the parameters were defined just above it?

Fails because all are variables.  I know if I #define them to be constants it works, but that seems rather odd.


Any ideas?


Thanks in advance! 


int *x1Pos = &persist.UserData[101]; // x1 location input


typedef struct {

int rawEncPosition; //raw encoder position value

float measuredPos; //encoder postion converted to mm or degrees

float degrees; //rotation normalized for coordinate system neg-0-pos

float coordPos; //linear normalized for coordinate system neg-0-pos

}AXIS;


AXIS axis[6];


float steps = 800;

float xyPitch = (.25 * 25.4)/steps;

float zPtich = (1.0 * 25.4)/steps;

float rotPitch = (1/20);


float normalizeScalar[6] = {xyPitch,xyPitch,zPitch,zPitch,rotPitch,rotPitch};

float coordZero[6] = {xCoordZero,yCoordZero,zCoordZero,zCoordZero,xRotCoordZero,yRotCoordZero};


void ready_axes(void)

{

int i;

for(i=0; i<6; i++)

{

axis[i].rawEncPosition = chan[i].Position; //store raw encoder values

printf("Raw Encoder: %i\n",axis[i].rawEncPosition); //<<<<<<<<<<<<PRINTS EXPECTED VALUE 

axis[i].measuredPos = axis[i].rawEncPosition * normalizeScalar[i]; //convert encoder position to mm

axis[i].degrees = axis[i].measuredPos - coordZero[i];

axis[i].coordPos = axis[i].degrees;

}

}


*x1Pos = axis[0].rawEncPosition;