Jump to content

Recommended Posts

Dear Forum,

 

I' ve to perform a proportional derivate handles but there is a compilation error. This is the code

 

Header :

 

#ifndef _PID_H_
#define _PID_H_

/*
  ........

	file : "pid.h"

	Header file for library "pid.c"
	Function : Proportional Integral Derivative handles 

*/

#include <system.h>
#include <memory.h>
#include "peripheral.h"

// Variable declaration

typedef struct PID 
{
double set_point;		// Desidered Value
double proportion;		// Proportional Const
double integral;		// Integral Const
double derivative;		// Derivative Const
double last_error;		// Error[-1]
double prev_error;		// Error[-2]
double sum_error;		// Sums of Errors

} PID;

// Function Declaration
void pid_init(PID *pp);					// initialize PID structure
double pid_calc (PID *pp, double next_point); // perform one PID iteration


#endif

 

C.file :

/*
  ...

	file : "pid.c"

	Function : Proportional Integral Derivative handles 

*/
#include "pid.h"

// Function

void pid_init(PID *pp)
{
memset(pp,0,sizeof(PID));
}

double pid_calc (PID *pp, double next_point)
{
double derror, error;
pp->sum_error = pp->sum_error + (error = pp->set_point - next_point);	
derror = pp->last_error - pp->prev_error;
pp->prev_error = pp->last_error;
pp->last_error = error;
return (pp->proportion * error + pp->integral * pp->sum_error
		+ pp->derivative * derror);
}

 

now, the error :

pid.cE:\G26CPP\G26RTOS\MainBoard\pid.c(23:9): error: arguments of 'memset8' don't match the parameters of callE:\G26CPP\G26RTOS\MainBoard\pid.c(23:2): error: failed to generate expressionfailureBUILD FAILED: Mon Sep 07 11:30:21 2009

 

where I have wrong ?

Thanks.

Marino Silvio

Link to post
Share on other sites

Try adding address of operator.

 

	memset( &pp,0,sizeof(PID));

 

Beware you floating point code will not compile, BoostC has a set of floating point libraries which have to be explicity called :-(

Take a look at the supplied sample CircleArea.

 

Regards

Dave

Link to post
Share on other sites

Try it this way:

typedef struct
{
double set_point;		// Desidered Value
double proportion;		// Proportional Const
double integral;		// Integral Const
double derivative;		// Derivative Const
double last_error;		// Error[-1]
double prev_error;		// Error[-2]
double sum_error;		// Sums of Errors
} PID;

PID pid;

void pid_init(PID *pp);

void main()
{
pid_init(&pid);
}


void pid_init(PID *pp)
{
memset((void *)pp,0,sizeof(PID));
}

 

Don't declare your variables using the typedef.

 

"double" is not a valid data type even if SourceBoost accepts it. SB will allocate space for a long.

 

Cheers

 

Reynard

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

Loading...
×
×
  • Create New...