Created
September 14, 2017 05:34
-
-
Save OtacilioN/6d442471d19fc044ec02e1c0428c3021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "bobuniverse.h" | |
int main(void){ | |
int distance; | |
Universe myBob(100, 30, 100); | |
distance = myBob.getDistance(); | |
printf("%d", distance); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* bobuniverse.cpp | |
* | |
* It is a Bob Robot Universe Simulator | |
* | |
* Created on September 13, 2017 | |
* By Otacilio Neto (github: @OtacilioN | Email: contato@otaciliomaia.com) | |
* | |
* Published under mit license | |
*/ | |
#include "bobuniverse.h" | |
Universe::Universe(int initialDistance, int setPoint, int friction) { | |
_initialDistance = initialDistance; | |
_setPoint = setPoint; | |
_friction = friction; | |
position = _initialDistance; | |
} | |
int Universe::getStatus() { | |
if(position < 0) // The robot crash into the wall | |
status = -1; | |
if(position = _setPoint && speed == 0) // Success | |
status = 0; | |
return status; | |
} | |
void Universe::move(int power) { | |
if(status > 0){ | |
if(speed > 0.9) | |
acceleration = (power - _friction)/1000.0; | |
else if(speed < 0.9) | |
acceleration = (power + _friction)/1000.0; | |
else if(power > _friction) | |
acceleration = (power - _friction)/1000.0; | |
else if(power < _friction*-1) | |
acceleration = (power + _friction)/1000.0; | |
speed += acceleration; | |
position += speed; | |
seconds++; | |
getStatus(); | |
} | |
return ; | |
} | |
int Universe::getDistance() { | |
return (int)position; // The sensor has a int precision | |
} | |
int Universe::getSpeed() { | |
return (int)speed; // The sensor has a int precision | |
} | |
int Universe::getTime() { | |
return seconds; // The sensor has a int precision | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* bobuniverse.h | |
* | |
* It is a Bob Robot Universe Simulator | |
* | |
* Created on September 13, 2017 | |
* By Otacilio Neto (github: @OtacilioN | Email: contato@otaciliomaia.com) | |
* | |
* Published under mit license | |
*/ | |
#ifndef bobuniverse_h | |
#define bobuniverse_h | |
class Universe { | |
public: | |
Universe(int initialDistance, int setPoint, int friction = 100); | |
int getStatus(); | |
void move(int power); | |
int getDistance(); | |
int getSpeed(); | |
int getTime(); | |
private: | |
int _initialDistance; | |
int _setPoint; | |
int _friction; | |
float speed = 0; | |
float acceleration; | |
float position; | |
int status = 1; | |
int seconds = 0; | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ g++ agent-simpleonoff.cpp | |
In file included from agent-simpleonoff.cpp:2:0: | |
bobuniverse.h:27:23: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default] | |
float speed = 0; | |
^ | |
bobuniverse.h:30:22: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default] | |
int status = 1; | |
^ | |
bobuniverse.h:31:23: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default] | |
int seconds = 0; | |
^ | |
/tmp/cciobolU.o: In function `main': | |
agent-simpleonoff.cpp:(.text+0x1f): undefined reference to `Universe::Universe(int, int, int)' | |
agent-simpleonoff.cpp:(.text+0x2b): undefined reference to `Universe::getDistance()' | |
collect2: error: ld returned 1 exit status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[Resolvido] Para os warnings era só fazer a inicialização no constructor da classe, e para o erro era só gerar um arquivo objeto da biblioteca e linkar na compilação.