Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global/pbref values #7

Open
obielikh opened this issue Apr 20, 2018 · 2 comments
Open

global/pbref values #7

obielikh opened this issue Apr 20, 2018 · 2 comments

Comments

@obielikh
Copy link
Collaborator

check the global variable/pass by reference issue. pbref is not necessary if every single variable is global, and half is pbref half is pbvalue, which might be causing some issues.
put every value to main function and make everything passbyref, which will take time with double checking and stuff
or my suggestion declare the variables globally but assign initial values in main function. no matter where the other functions are called, they might be trying to reach the gloablly assigned value, which is not always what you want.
you can actually remove ALL the passing variables in functions since everything is global
which is a good idea cus having BOTH pbref and pbval version of a variable can cause confusion eg. servoControl function

@michelco86
Copy link
Collaborator

michelco86 commented Apr 20, 2018

https://github.com/hugocool24/RobotSM/blob/2136355b19e5d26ad6cc47e2c06d272900b20c2b/2018/main.ino#L12

try instead: float u[2];

https://github.com/hugocool24/RobotSM/blob/2136355b19e5d26ad6cc47e2c06d272900b20c2b/2018/main.ino#L20

try instead int currAngle; and set int currAngle = 90; in void setup() since in void setup() we write myservo.write(90) to the servo to make it start at angle 90;

https://github.com/hugocool24/RobotSM/blob/82da9c5aa5e3c06492998112109e3cbbadedd8e8/2018/main.ino#L36

float sensorValue[nrOfFrontSensors]; and then intialize them to float sensorValue[nrOfFrontSensors] = {0,0,0}; in void setup(); to give them an initial value.

https://github.com/hugocool24/RobotSM/blob/e036a8b87f4e7118823ae9d28067707d6e64f989/2018/main.ino#L53

change to: int readIndex[nrOfFrontSensors]; then put in void setup(): int readIndex[nrOfFrontSensors] = {0,0,0} to initalize it with the correct starting values

https://github.com/hugocool24/RobotSM/blob/e036a8b87f4e7118823ae9d28067707d6e64f989/2018/main.ino#L54

change to: float total[nrOfFrontSensors]; then put in void setup(): float total[nrOfFrontSensors] = {0.0,0.0,0.0}; to initalize the vector with the correct starting values

https://github.com/hugocool24/RobotSM/blob/e036a8b87f4e7118823ae9d28067707d6e64f989/2018/main.ino#L55

change to: float avgSensorValue[nrOfFrontSensors]; then in void setup(): float avgSensorValue[nrOfFrontSensors] = {0.0,0.0,0.0}; to initialize the vector with the correct starting values

@michelco86
Copy link
Collaborator

As Oleksi points out, we should not define a value to a globally defined variable unless it is a constant value, i.e const int nrOfSensor = 3; or whatever (just an example)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants