ShadowWalker 发表于 2013-8-17 17:12:40

Arduino语言的函数不支持自定义类变量的传递

在把一位大神的四轴姿态解算代码(STM32)移植到Arduino的时候被卡在了一个函数上,老是编译不通过

typedefstruct
        {
          float w;
          float x;
          float y;
          float z;
        }quaternion;            
static inline void quaternion_loadIdentity(quaternion * q)
    {
      q->w = 1;
      q->x = q->y = q->z = 0;
    }
   
void quaternion_normalize(quaternion * q)
{
    float norm_r = math_rsqrt(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z);
    q->w *= norm_r;
    q->x *= norm_r;
    q->y *= norm_r;
    q->z *= norm_r;
}
上网看了看有人这么说:Arduino编程语言的函数好像只支持基本类型的参数传递,不支持自定义类或者结构体指针或变量的传递,编译都无法通过。见http://www.seguesoft.net/535a5ba2/91cd5199arduino677f5b507a0b5e8f
肿么办?这么多四元数和矩阵计算的函数要我重写吗?

pathletboy 发表于 2013-8-17 18:51:00

struct quaternion
{
float w;
float x;
float y;
float z;
};            
static inline void quaternion_loadIdentity(struct quaternion * q)
{
q->w = 1;
q->x = q->y = q->z = 0;
}

void quaternion_normalize(struct quaternion * q)
{
float norm_r = math_rsqrt(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z);
q->w *= norm_r;
q->x *= norm_r;
q->y *= norm_r;
q->z *= norm_r;
}

ShadowWalker 发表于 2013-8-17 22:21:55

pathletboy 发表于 2013-8-17 18:51 static/image/common/back.gif
struct quaternion
{
float w;


大神啊,跪谢。

鸿子子 发表于 2014-12-17 14:41:20

有四元数的库么
页: [1]
查看完整版本: Arduino语言的函数不支持自定义类变量的传递