When compiling Zumo Line following, got an error message

Good day,

I just got a Zumo for Arduino kit from online shop, I can get it to work, but when I compiling the code form ZumoShield called: LineFollower, I got an error message:

/Arduino/libraries/ZumoShield/ZumoIMU.cpp: In member function ‘void ZumoIMU::readMag()’:
/Arduino/libraries/ZumoShield/ZumoIMU.cpp:272:22: warning: narrowing conversion of ‘((ZumoIMU*)this)->ZumoIMU::swapBytes(((uint16_t)((ZumoIMU*)this)->ZumoIMU::m.ZumoIMU::vector::x))’ from ‘uint16_t {aka unsigned int}’ to ‘int’ inside { } [-Wnarrowing]
m = { swapBytes(m.x), swapBytes(m.z), swapBytes(m.y) };
~~~~~^
/Arduino/libraries/ZumoShield/ZumoIMU.cpp:272:38: warning: narrowing conversion of ‘((ZumoIMU*)this)->ZumoIMU::swapBytes(((uint16_t)((ZumoIMU*)this)->ZumoIMU::m.ZumoIMU::vector::z))’ from ‘uint16_t {aka unsigned int}’ to ‘int’ inside { } [-Wnarrowing]
m = { swapBytes(m.x), swapBytes(m.z), swapBytes(m.y) };
~~~~~^
/Arduino/libraries/ZumoShield/ZumoIMU.cpp:272:54: warning: narrowing conversion of ‘((ZumoIMU*)this)->ZumoIMU::swapBytes(((uint16_t)((ZumoIMU*)this)->ZumoIMU::m.ZumoIMU::vector::y))’ from ‘uint16_t {aka unsigned int}’ to ‘int’ inside { } [-Wnarrowing]
m = { swapBytes(m.x), swapBytes(m.z), swapBytes(m.y) };
~~~~~^

my zumo still able to follow the line just fine, just wondering what are those message showing when I compiling the code? How can I fix it?

Thank you

Sam

Hello, Sam.

Those warnings are safe to ignore. They are there because we are treating the magnetometer readings as unsigned while rearranging the bytes, but then interpreting the values as signed like they should be, and we did not use explicit casts to tell the compiler that that is intended. We will try to fix it in the future, but if you really want to make the warnings go away, you can fix it yourself by adding those casts yourself, i.e. change line 272 in ZumoIMU.cpp to:

m = { (int16_t)swapBytes(m.x), (int16_t)swapBytes(m.z), (int16_t)swapBytes(m.y) };.

- Amanda

Thants great explanation Amanda! Thank you for your help! Still new to this robotic thing and coding in C++. I am sure I will be asking a lot newbie questions here… bear with me :slight_smile: