Go Down

Topic: Invalid operands of types... (Read 1 time) previous topic - next topic

Kalveo

Quote

RadioReceiverPCB_with_MPU_6050.ino: In function 'void ComplementaryFilter(float*, uint16_t, float, long unsigned int)':
RadioReceiverPCB_with_MPU_6050:378: error: invalid operands of types 'double' and 'float*' to binary 'operator*'


Code: [Select]
void ComplementaryFilter(float *newAngle, uint16_t newRate, float accAngle, unsigned long looptime){
  float dt = looptime / 1000.0;
 
  *newAngle += (float)(newRate / 131) * dt;
  *newAngle = (float)(0.95 * newAngle) + (0.05 * accAngle);
}


I don't see why?

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Graynomad

newAngle is a pointer. A pointer multiplied by  0.95 is an interesting concept but but not very useful :)

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Kalveo

Ohh... Missed that :p

Thanks for the help :)

KeithRB

This is an interesting case of parsing. since the *newAngle would make sense, it could also have complained about a missing operator.

PeterH


A pointer multiplied by  0.95 is an interesting concept but but not very useful :)


Might come in handy if you wanted a rounded-off pointer. Less pointy and more blunty.
I only provide help via the forum - please do not contact me for private consultancy.

MarkT


This is an interesting case of parsing. since the *newAngle would make sense, it could also have complained about a missing operator.


Nothing special with parsing a * *b, just like a - -b

Perhaps the routine meant to take a float reference rather than  a pointer:
Code: [Select]
void ComplementaryFilter(float &newAngle, uint16_t newRate, float accAngle, unsigned long looptime){

You only need the generality of pointers when its an array or buffer that you are
going to index, reference types are cleaner for pass-by-reference use-cases (unsurprisingly)
[ I won't respond to messages, use the forum please ]

KeithRB

No but if you have a*b where b is a pointer, you can choose between two errors. Either an invalid type for multiplication, or a missing operator between two compatible types.

Graynomad

Quote
Less pointy and more blunty.

Good for fuzzy-logic algorithms as well, to get a value that roughly correct from an array.

_______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up