Jump to content
OMRON Forums

malloc allocation error in a servo control algorithm in the Realtime Routines folder.


moha_sa

Recommended Posts

Hi,   I am receiving this error "implicit declaration of function 'malloc' " when using servoData = (char *)malloc(CHAR_BUF_SIZE_3*sizeof(unsigned char)); in a user-defined ServoCtrl algorithm in the Realtime Routines folder in the IDE. My goal is to use sprintf and send commands to be able to print a float variable to the unsolicited message window and monitor its value as below:

char  *servoData;

servoData = (char *)malloc(CHAR_BUF_SIZE_3*sizeof(unsigned char));

sprintf(servoData,"desired position is  %f  \n", 230.5);

Send(SEND1_PORT,servoData); 

Any idea how I can still use "malloc" without the error to run the "Send" command? Thanks.

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

The following user servo routine will run one time (if applied to motor 0) and send a message on buffer 1. 

double MyServo(struct MotorData *Mptr)
{
	char MyCharArray[100];
    MyCharArray[0]='H';
    Send(1,&MyCharArray);
    pshm->Motor[0].ServoCtrl = 0;
    return 0;
}

Malloc should not be  included in usercode.c. Any time malloc is used, free must also be used to free up that memory.

free(servoData);
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...