Variable declaration issue

Hi, I’m trying to merge the T-Hex 4 dof and a pixycam code but I’m having an issue that I’m not able to solve.
Even inf the variable ServoMoveTime is regularly declared into the ino, m receiving this error:

sketch\Pixy.cpp: In function ‘void read_pixy_data()’:

Pixy.cpp:112:11: error: ‘ServoMoveTime’ was not declared in this scope

ServoMoveTime += 150;

^~~~~~~~~~~~~

Pixy.cpp:115:11: error: ‘ServoMoveTime’ was not declared in this scope

ServoMoveTime = 150;

^~~~~~~~~~~~~

Pixy.cpp:121:11: error: ‘ServoMoveTime’ was not declared in this scope

ServoMoveTime += 150;

^~~~~~~~~~~~~

Pixy.cpp:124:11: error: ‘ServoMoveTime’ was not declared in this scope

ServoMoveTime = 150;

^~~~~~~~~~~~~

exit status 1
‘ServoMoveTime’ was not declared in this scope

Can you help me?
Thanks!!

Hex_Cfg.h (13 KB)

Hex_Globals.h (3.72 KB)

InputController.h (2.16 KB)

phoenix_driver_ssc32.cpp (19.4 KB)

Pixy.cpp (4.76 KB)

PS2_controller.cpp (15.4 KB)

ServoDriver.h (2.17 KB)

T-Hex_4_dof_Emix_buono_con_pixy.ino (55.9 KB)

Well, nothing in your source code seems to use it. Just comment the offending block out and see what happens.

-jim lee

ServoMoveTime is defined in T-Hex...ino and being used in Pixy.cpp without either definition or declaration.

add an extern declarion for ServoMoveTime in Hex_Globals.h

gcjr:
ServoMoveTime is defined in T-Hex...ino and being used in Pixy.cpp without either definition or declaration.

add an extern declarion for ServoMoveTime in Hex_Globals.h

OP: Before you do that, you need to think. Why should the camera class know ANYTHING about servos?

One of the tenets of OOP is encapsulation. A camera class should know about a camera, and nothing else. Everything to do with the camera should be handled by the camera class, and the camera class should do nothing else.

A servo class should know about a servo, and nothing else. Everything to do with the servo should be done by the servo class, and the servo class should do nothing else.

The Arduino sketch should be asking the camera class instance about camera stuff, and telling the servo class instance to do servo stuff.

Its more that this though, exposing variables inherently tends to lead to bugs since a remote module
doesn't know how to use the variables and shouldn't be able to assign them arbitrarily. Its best to
expose only functions or methods which can police themselves.

Remote modules do need to know about using the exposed methods, encapsulation is about hiding
detail, not knowledge as such - in fact a good interface tries to be self-explanatory.

And the real issue is keeping interfaces to modules well defined and fixed, even if the internals change,
so that all the existing client code isn't made completely brittle on a new release. Where you do want
to expose detail in an interface you try to keep it at a high level and optional - perhaps as heuristics.

MarkT:
Its best to
expose only functions or methods which can police themselves.

And there we are, age old question: How smart are getter and setter? (imo they are not at all)

But lets stay with the topic: I am with Paul in this point. Your code should only know about stuff it really requires: else it will be very hard to manage, debug, update your code. I promise you, you will forget in two weeks, that your camera manipulates values from motor.

How smart are getter and setter? (imo they are not at all)

That depends on the programmer. A real programmer will not let a user set phoneNumber to "Well, you know, it's 7 on my speed dial".