Pages: [1]   Go Down
Author Topic: Invalid operands of types...  (Read 836 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 1
Posts: 98
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25838
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
(0.95 * newAngle)
Just there.
Logged

"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.

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8473
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Jr. Member
**
Karma: 1
Posts: 98
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ohh... Missed that :p

Thanks for the help smiley
Logged

Offline Offline
Edison Member
*
Karma: 32
Posts: 1389
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12577
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Might come in handy if you wanted a rounded-off pointer. Less pointy and more blunty.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11718
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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)
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Edison Member
*
Karma: 32
Posts: 1389
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8473
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Less pointy and more blunty.
Good for fuzzy-logic algorithms as well, to get a value that roughly correct from an array.

_______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: