diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje.VC.db" "b/Nesne Tabanl\304\261 Programlama I - Proje.VC.db" new file mode 100644 index 0000000..63d320a Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje.VC.db" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje.sln" "b/Nesne Tabanl\304\261 Programlama I - Proje.sln" new file mode 100644 index 0000000..a2e7b1d --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje.sln" @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Nesne Tabanlı Programlama I - Proje", "Nesne Tabanlı Programlama I - Proje\Nesne Tabanlı Programlama I - Proje.vcxproj", "{70BF864F-193A-4D0B-B337-3AF969661238}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {70BF864F-193A-4D0B-B337-3AF969661238}.Debug|x64.ActiveCfg = Debug|x64 + {70BF864F-193A-4D0B-B337-3AF969661238}.Debug|x64.Build.0 = Debug|x64 + {70BF864F-193A-4D0B-B337-3AF969661238}.Debug|x86.ActiveCfg = Debug|Win32 + {70BF864F-193A-4D0B-B337-3AF969661238}.Debug|x86.Build.0 = Debug|Win32 + {70BF864F-193A-4D0B-B337-3AF969661238}.Release|x64.ActiveCfg = Release|x64 + {70BF864F-193A-4D0B-B337-3AF969661238}.Release|x64.Build.0 = Release|x64 + {70BF864F-193A-4D0B-B337-3AF969661238}.Release|x86.ActiveCfg = Release|Win32 + {70BF864F-193A-4D0B-B337-3AF969661238}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/LaserSensor.cpp" "b/Nesne Tabanl\304\261 Programlama I - Proje/LaserSensor.cpp" new file mode 100644 index 0000000..2f78604 --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/LaserSensor.cpp" @@ -0,0 +1,43 @@ +#include "LaserSensor.h" + + + +LaserSensor::LaserSensor() +{ +} + +float LaserSensor::getRange(int index) +{ + return 0; +} + +void LaserSensor::setRange(float range[]) +{ + +} + +void LaserSensor::updateSensor(float ranges[]) +{ + +} + +float LaserSensor::getMax() +{ + return this->max; +} + +float LaserSensor::getMin() +{ + return this -> min; +} + +float LaserSensor::operator[](int i) +{ + return 0.0f; +} + + + +LaserSensor::~LaserSensor() +{ +} diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/LaserSensor.h" "b/Nesne Tabanl\304\261 Programlama I - Proje/LaserSensor.h" new file mode 100644 index 0000000..b7b749f --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/LaserSensor.h" @@ -0,0 +1,20 @@ +#pragma once +#include "RangeSensor.h" +//Eklenen Birþey Varsa burasý düzeltilecek açýklama yok getRange diye birþey almamýz mümkün deðil +class LaserSensor : public RangeSensor +{ + float min; + float max; + string type; +public: + LaserSensor(); + float getRange(int index); + void setRange(float range[]); + void updateSensor(float ranges[]); + float getMax(); + float getMin(); + float operator[](int i); + ~LaserSensor(); + +}; + diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/Menu.cpp" "b/Nesne Tabanl\304\261 Programlama I - Proje/Menu.cpp" new file mode 100644 index 0000000..78d5333 --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/Menu.cpp" @@ -0,0 +1,423 @@ +#include "Menu.h" + + + +Menu::Menu() +{ + this->position = new Position(); + this->sensor = new SonarSensor(); + this->robotInterface = new PioneerRobotInterface(this->sensor,this->position); + this->robotControl = new RobotControl(robotInterface, this->position, this->sensor); + this->connectionStatus = false; + mainMenu(); +} + +int Menu::controlInput(int menuRange,string input) +{ + if(menuRange < 10) + { + if (input.length() > 1) + { + return 0; + } + else if (isdigit(input.at(0))) + { + int choice = atoi(input.c_str()); + if (choice > 0 && choice <= menuRange) + { + return choice; + } + else + { + return 0; + } + } + } + else + { + int choice; + try + { + choice = atoi(input.c_str()); + } + catch (const std::exception&) + { + return 0; + } + return choice; + } + return 0; +} + +void Menu::mainMenu() +{ + while (true) + { + string input; + cout << "Main Menu" << endl; + cout << "1. Connection" << endl; + cout << "2. Motion" << endl; + cout << "3. Sensor" << endl; + cout << "4. Quit" << endl; + cout << "Choose one : "; + cin >> input; + int choice = controlInput(4, input); + switch (choice) + { + case 1: + system("cls"); + cout << " Main Menu -> "; + connectionMenu(); + break; + case 2: + system("cls"); + cout << "Main Menu -> "; + motionMenu(); + break; + case 3: + system("cls"); + cout << "Main Menu -> "; + sensorMenu(); + break; + case 4: + cout << "Quitting the program " << endl; + Sleep(200); + return; + default: + cout << "Please enter input between 1 and 4" << endl; + system("cls"); + break; + } + } +} +void Menu::connectionMenu() +{ + while (true) + { + string input; + cout << "Connection Menu" << endl; + cout << "1. Connect Robot" << endl; + cout << "2. Disconnect Robot" << endl; + cout << "3. Back" << endl; + cout << "Choose one : "; + cin >> input; + int choice = controlInput(3, input); + switch (choice) + { + case 1: + + if (!connectionStatus) + { + if (!robotInterface->open()) { + cout << "Could not connect..." << endl; + cout << "Please open mobile sim if mobile sim opened that means unknown error" << endl; + Sleep(200); + system("cls"); + return; + } + else + { + cout << "Robot Connection Established" << endl; + Sleep(200); + system("cls"); + connectionStatus = true; + } + } + else + { + cout << "Robot Connection Already Established" << endl; + Sleep(200); + system("cls"); + } + break; + case 2: + if (connectionStatus) + { + if (!robotInterface->close()) + { + cout << "Robot connection could not closed.Seems have Mobile Sim has a problem" << endl; + Sleep(200); + system("cls"); + } + else + { + cout << "Robot connection closed" << endl; + connectionStatus = false; + Sleep(200); + system("cls"); + exit(0); + } + } + else + { + cout << "Robot connection already closed" << endl; + Sleep(200); + system("cls"); + } + break; + case 3: + system("cls"); + return; + default: + cout << "Please enter input between 1 and 3" << endl; + Sleep(200); + system("cls"); + break; + } + } +} + +void Menu::motionMenu() +{ + while (true) + { + if (connectionStatus) + { + string input; + cout << "Motion Menu" << endl; + cout << "1. Move Robot" << endl; + cout << "2. Safe Move Robot" << endl; + cout << "3. Turn Left" << endl; + cout << "4. Turn Right" << endl; + cout << "5. Forward" << endl; + cout << "6. Move Distance" << endl; + cout << "7. Close Wall" << endl; + cout << "8. Stop Robot" << endl; + cout << "9. Print Data" << endl; + cout << "10. Back" << endl; + cout << "Choose one : "; + cin >> input; + int choice = controlInput(10, input); + float speedFloat = 0; + int speedInteger = 0; + float distance = 0; + switch (choice) + { + case 1: + //Move Menu ask Speed + speedFloat = askSpeed(); + if ((int)speedFloat == 0) + { + cout << "You have entered wrong input don't enter 0 or char value" << endl; + system("cls"); + Sleep(1000); + } + else + { + robotInterface->move(speedFloat); + system("cls"); + } + break; + case 2: + speedInteger = askSafeMoveSpeed(); + if (speedInteger == 0) + { + cout << "You have entered wrong input don't enter 0 or char value" << endl; + Sleep(1000); + system("cls"); + } + else + { + robotControl->safeMove(speedInteger); + system("cls"); + } + break; + case 3: + robotControl->turnLeft(); + cout << "Turning Left" << endl; + Sleep(1000); + system("cls"); + break; + case 4: + robotControl->turnRight(); + cout << "Turning Right" << endl; + Sleep(1000); + system("cls"); + break; + case 5: + robotControl->forward(); + cout << "Moving Forward" << endl; + Sleep(1000); + system("cls"); + break; + case 6: + distance = askDistance(); + if ((int)distance == 0) + { + cout << "You have entered wrong input don't enter 0 or char value" << endl; + system("cls"); + Sleep(1000); + } + else + { + robotControl->moveDistance(distance); + cout << "Distance moved" << endl; + system("cls"); + Sleep(1000); + } + break; + case 7: + robotControl->closeWall(); + cout << "Closing front wall completed succesfully" << endl; + Sleep(1000); + system("cls"); + break; + case 8: + robotInterface->stop(); + cout << "Robot stopped" << endl; + Sleep(1000); + system("cls"); + break; + case 9: + robotControl->print(); + Sleep(2000); + system("cls"); + break; + case 10: + system("cls"); + return; + default: + cout << "Please enter input between 1 and 10" << endl; + Sleep(1000); + system("cls"); + break; + } + } + else + { + system("cls"); + cout << "Robot connection closed please open connection first" << endl; + Sleep(1000); + system("cls"); + return; + } + } +} + +void Menu::sensorMenu() +{ + if (connectionStatus) + { + while (true) + { + string input; + cout << "Sensor Menu" << endl; + cout << "1. Get Type" << endl; + cout << "2. Set Type" << endl; + cout << "3. Get Min" << endl; + cout << "4. Get Max" << endl; + cout << "5. Back" << endl; + cout << "Choose : "; + cin >> input; + string type; + int choice = controlInput(5, input); + switch (choice) + { + case 1: + cout << sensor->getType() << endl; + Sleep(1000); + system("cls"); + break; + case 2: + cout << "Please enter type of sensor" << endl; + cin >> type; + sensor->setType(type); + cout << "Sensor type changed" << endl; + Sleep(1000); + system("cls"); + break; + case 3: + cout << sensor->getMin() << endl; + Sleep(1000); + system("cls"); + break; + case 4: + cout << sensor->getMax() << endl; + Sleep(1000); + system("cls"); + break; + case 5: + system("cls"); + return; + default: + cout << "Please enter input between 1 and 5" << endl; + Sleep(1000); + system("cls"); + break; + } + } + } + else + { + system("cls"); + cout << "Robot connection closed please open connection first" << endl; + Sleep(1000); + system("cls"); + return; + } +} + +float Menu::askDistance() +{ + string input; + float distance; + cout << "Enter distance :" << endl; + cin >> input; + distance = controlFloat(input); + return distance; +} + +int Menu::askSafeMoveSpeed() +{ + string input; + int speed; + cout << "Enter speed :" << endl; + cin >> input; + speed = controlInteger(input); + return speed; +} + +float Menu::askSpeed() +{ + string input; + float speed; + cout << "Enter speed :" << endl; + cin >> input; + speed = controlFloat(input); + return speed; +} + +float Menu::controlFloat(string input) +{ + float data; + try + { + data = stof(input); + } + catch (const std::exception&) + { + return 0; + } + return data; +} + +int Menu::controlInteger(string input) +{ + int data; + try + { + data = stoi(input); + } + catch (const std::exception&) + { + return 0; + } + return data; +} + + + + +Menu::~Menu() +{ +} diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/Menu.h" "b/Nesne Tabanl\304\261 Programlama I - Proje/Menu.h" new file mode 100644 index 0000000..32bcc6b --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/Menu.h" @@ -0,0 +1,98 @@ +/** +* @File Menu.h +* @Date December, 2017 +* @Author Yusuf Furkan Yücesoy (yusuffurkanyucesoy@gmail.com) +* +* \brief Menu Class +* \brief This class is the menu section of the application. +*/ +#pragma once + + +#include "RobotInterface.h" +#include "RobotControl.h" + +#include +class Menu +{ + /** + * \brief position attribute (from Position class using aggregation) + */ + Position *position; + /** + * \brief range sensor attribute(from RangeSensor class using aggregation) + */ + RangeSensor *sensor; + /** + * \brief robot interface attribute(from RobotInterface class using aggregation) + */ + RobotInterface *robotInterface; + /** + * \brief robot control attribute(from robotControl class using aggregation) + */ + RobotControl *robotControl; + /** + * \brief connection status attribute. + * \brief parameter indicating that robot connection + */ + boolean connectionStatus; +public: + /** + * \brief constructor function of Menu class + */ + Menu(); + /** + * \brief This function is control function for inputs + * \param menuRange is integer type parameter + * \param input is string type parameter + */ + int controlInput(int menuRange,string input); + /** + * \brief This function prints main menu to screen and asks the user what action he wants to perform + */ + void mainMenu(); + /** + * \brief This function prints connetion menu to screen and asks the user what action he wants to perform + */ + void connectionMenu(); + /** + * \brief This function prints motion menu to screen and asks the user what action he wants to perform + */ + void motionMenu(); + /** + * \brief This function prints sensor menu to screen and asks the user what action he wants to perform + */ + void sensorMenu(); + /** + * \brief This function asks to distance from user and turns it + * \return distance is float parameter + */ + float askDistance(); + /** + * \brief This function asks to speed from user and turns it + * \return speed is integer parameter + */ + int askSafeMoveSpeed(); + /** + * \brief This function asks to speed from user and turns it + * \return speed is float parameter + */ + float askSpeed(); + /** + * \brief This function converts string parameter to float parameter + * \param input is string + * \return data is float + */ + float controlFloat(string input); + /** + * \brief This function converts string parameter to integer parameter + * \param input is string + * \return data is integer + */ + int controlInteger(string input); + /** + * \brief destrutor function of Menu class + */ + ~Menu(); +}; + diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/Nesne Tabanl\304\261 Programlama I - Proje.vcxproj" "b/Nesne Tabanl\304\261 Programlama I - Proje/Nesne Tabanl\304\261 Programlama I - Proje.vcxproj" new file mode 100644 index 0000000..6948e4f --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/Nesne Tabanl\304\261 Programlama I - Proje.vcxproj" @@ -0,0 +1,141 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {70BF864F-193A-4D0B-B337-3AF969661238} + NesneTabanlıProgramlamaIProje + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + + + + + Level3 + Disabled + true + C:\Users\Furkan\Desktop\Proje_Paketi_v1_1;C:\Users\Furkan\Desktop\Proje_Paketi_v1_1\Aria;%(AdditionalIncludeDirectories) + + + C:\Users\Furkan\Desktop\Proje_Paketi_v1_1;%(AdditionalLibraryDirectories) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;PioneerRobotAPI.lib;AriaDebugVC14.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/Nesne Tabanl\304\261 Programlama I - Proje.vcxproj.filters" "b/Nesne Tabanl\304\261 Programlama I - Proje/Nesne Tabanl\304\261 Programlama I - Proje.vcxproj.filters" new file mode 100644 index 0000000..8b12c02 --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/Nesne Tabanl\304\261 Programlama I - Proje.vcxproj.filters" @@ -0,0 +1,72 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/PioneerRobotInterface.cpp" "b/Nesne Tabanl\304\261 Programlama I - Proje/PioneerRobotInterface.cpp" new file mode 100644 index 0000000..b201482 --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/PioneerRobotInterface.cpp" @@ -0,0 +1,91 @@ +#include "PioneerRobotInterface.h" + + +//Interface Tamamlandý +PioneerRobotInterface::PioneerRobotInterface() +{ + setRobot(this); +} + +PioneerRobotInterface::PioneerRobotInterface(RangeSensor * sensor, Position * pos) +{ + setRobot(this); + this->rangeSensor = sensor; + this->position = pos; +} + + +void PioneerRobotInterface::update() +{ + position->setX(getX()); + position->setY(getY()); + position->setTh(getTh()); + setPosition(position); + float ranges[16]; + float min, max; + getSonarRange(ranges); + rangeSensor->updateSensor(ranges); + setSensor(rangeSensor); +} + +bool PioneerRobotInterface::open() +{ + bool status = connect(); + if (status == 1) + update(); + + return status; + +} + +void PioneerRobotInterface::move(float speed) +{ + moveRobot(speed); +} + +bool PioneerRobotInterface::close() +{ + return disconnect(); +} + +void PioneerRobotInterface::turn(RobotInterface::DIRECTION dir) +{ + switch (dir) + { + case RobotInterface::DIRECTION::left: + turnRobot(PioneerRobotAPI::DIRECTION::left); + break; + case RobotInterface::DIRECTION::right: + turnRobot(PioneerRobotAPI::DIRECTION::right); + break; + case RobotInterface::DIRECTION::forward: + turnRobot(PioneerRobotAPI::DIRECTION::forward); + break; + default: + break; + } +} + +void PioneerRobotInterface::stop() +{ + stopRobot(); +} + +void PioneerRobotInterface::updateRobot() +{ + position->setX(getX()); + position->setY(getY()); + position->setTh(getTh()); + setPosition(position); + float ranges[16]; + float min, max; + getSonarRange(ranges); + rangeSensor->updateSensor(ranges); + setSensor(rangeSensor); +} + + +PioneerRobotInterface::~PioneerRobotInterface() +{ + +} diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/PioneerRobotInterface.h" "b/Nesne Tabanl\304\261 Programlama I - Proje/PioneerRobotInterface.h" new file mode 100644 index 0000000..329c23f --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/PioneerRobotInterface.h" @@ -0,0 +1,22 @@ +#pragma once +#include "RobotInterface.h" +#include "PioneerRobotAPI.h" +#include "SonarSensor.h" +class PioneerRobotInterface : public RobotInterface , public PioneerRobotAPI +{ + RangeSensor *rangeSensor; + Position *position; +public: + PioneerRobotInterface(); + PioneerRobotInterface(RangeSensor *sensor, Position *pos); + void update(); + bool open(); + void move(float speed); + bool close(); + void turn(RobotInterface::DIRECTION dir); + void stop(); + void updateRobot(); + + ~PioneerRobotInterface(); +}; + diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/Position.cpp" "b/Nesne Tabanl\304\261 Programlama I - Proje/Position.cpp" new file mode 100644 index 0000000..51ae723 --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/Position.cpp" @@ -0,0 +1,90 @@ +/** +* @File Position.cpp +* @Date December, 2017 +* @Author Ozan Baki KESKIN (ozankeskin9774@gmail.com) +* +*/ +#include "Position.h" + + +/** +* \brief Constructor function of the Position class +* This function assings to parameters as default zero. +*/ +Position::Position() +{ + this->x = 0; + this->y = 0; + this->th = 0; +} +/** +* \brief getter function of the x position of the robot +* \return the x position of the robot +*/ +float Position::getX() +{ + return this -> x; +} + +/** +* \brief setter function of the x position of the robot +* \param x a float attribute +*/ +void Position::setX(float x) +{ + this -> x = x; +} +/** +* \brief getter function of the y position of the robot +* \return the y position of the robot +*/ +float Position::getY() +{ + return this -> y; +} +/** +* \brief setter function of the y position of the robot +* \param y a float attribute +*/ +void Position::setY(float y) +{ + this -> y = y; +} +/** +* \brief getter function of the orientation angle of the robot +* \return th +*/ +float Position::getTh() +{ + return this -> th; +} +/** +* \brief setter function of the orientation angle of the robot +* \param th a float attribute +*/ +void Position::setTh(float th) +{ + this->th = th; +} +/** +* \brief checks whether the positions refer to the same position +* \param pos is Position type object for checking Position's attributes +* \return false if the one of the positions is false, otherwise return true +*/ +bool Position::operator==(const Position & pos) +{ + if (this -> getX() != pos.x) + return false; + if (this -> getY() != pos.y) + return false; + if (this -> getTh() != pos.th) + return false; + return true; +} + +/** +* \brief Destructor function of the Position class +*/ +Position::~Position() +{ +} diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/Position.h" "b/Nesne Tabanl\304\261 Programlama I - Proje/Position.h" new file mode 100644 index 0000000..f5a6b39 --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/Position.h" @@ -0,0 +1,71 @@ +#pragma once +/** +* @File Position.h +* @Date December, 2017 +* @Author Ozan Baki KESKIN (ozankeskin9774@gmail.com) +* +* \brief Position Class +* \brief This class has keeping position of robot and has the task of managing information +*/ +class Position +{ + /** + * \brief x position of the robot attribute + */ + float x; + /** + * \brief y position of the robot attribute + */ + float y; + /** + * \brief th the orientation angle of the robot attribute + */ + float th; +public: + /** + * \brief Constructor function of the Position class + */ + Position(); + + /** + * \brief getter function of the x position of the robot + * \return the x position of the robot + */ + float getX(); + /** + * \brief setter function of the x position of the robot + * \param x a float attribute + */ + void setX(float x); + /** + * \brief getter function of the y position of the robot + * \return the y position of the robot + */ + float getY(); + /** + * \brief setter function of the y position of the robot + * \param y a float attribute + */ + void setY(float y); + /** + * \brief getter function of the orientation angle of the robot + * \return th + */ + float getTh(); + /** + * \brief setter function of the orientation angle of the robot + * \param th a float attribute + */ + void setTh(float th); + /** + * \brief checks whether the positions refer to the same position + * \param pos is Position type object for checking Position's attributes + * \return false if the one of the positions is false, otherwise return true + */ + bool operator==(const Position& pos); + /** + * \brief Destructor function of the Position class + */ + ~Position(); +}; + diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/RangeSensor.cpp" "b/Nesne Tabanl\304\261 Programlama I - Proje/RangeSensor.cpp" new file mode 100644 index 0000000..a1e257d --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/RangeSensor.cpp" @@ -0,0 +1,21 @@ +#include "RangeSensor.h" + + + +RangeSensor::RangeSensor() +{ + +} + + +void RangeSensor::setType(string type) +{ + this->type = type; +} + +RangeSensor::~RangeSensor() +{ +} +string RangeSensor::getType(){ + return this->type; +} \ No newline at end of file diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/RangeSensor.h" "b/Nesne Tabanl\304\261 Programlama I - Proje/RangeSensor.h" new file mode 100644 index 0000000..0a548df --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/RangeSensor.h" @@ -0,0 +1,19 @@ +#pragma once +#include +using namespace std; +//Generalization Specialization ilkelerine göre LaserSensor Sonar Sensor iliþkilerini alýr +class RangeSensor +{ + string type; +public: + RangeSensor(); + virtual void updateSensor(float ranges[]) = 0; + virtual float getMin() = 0; + virtual float getMax() = 0; + virtual float getRange(int index) = 0; + void setType(string type); + string getType(); + virtual float operator[](int i) = 0; + ~RangeSensor(); +}; + diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/RobotControl.cpp" "b/Nesne Tabanl\304\261 Programlama I - Proje/RobotControl.cpp" new file mode 100644 index 0000000..1efb944 --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/RobotControl.cpp" @@ -0,0 +1,91 @@ +#include "RobotControl.h" + + + +RobotControl::RobotControl() +{ + +} + +RobotControl::RobotControl(RobotInterface * robotInterface, Position * pos, RangeSensor * sensor) +{ + this->sensor.push_back(sensor); + this->robotInterface = robotInterface; + this->position = pos; + this->robotInterface->setPosition(pos); + this->robotInterface->setSensor(this->sensor.at(0)); +} +void RobotControl::safeMove(int speed) +{ + robotInterface->move(speed); +} + + +void RobotControl::turnLeft() +{ + robotInterface->turn(RobotInterface::DIRECTION::left); +} + +void RobotControl::turnRight() +{ + robotInterface->turn(RobotInterface::DIRECTION::right); +} + +void RobotControl::forward() +{ + robotInterface->turn(RobotInterface::DIRECTION::forward); +} + +void RobotControl::print() +{ + cout << "MyPose is (" << position->getX() << "," << position->getY() << "," << position->getTh() << ")" << endl; + cout << "Sonar ranges are [ "; + for (int counter = 0; counter < sensor.size(); counter++) + { + for (int i = 0; i < 16; i++) { + cout << sensor.at(counter)->getRange(i) << " "; + } + cout << "]" << endl; + } +} + +void RobotControl::moveDistance(float distance) +{ + robotInterface->move(distance); + Sleep(distance); + robotInterface->stop(); +} + +void RobotControl::closeWall() +{ + bool control_conflict = false; + + for (int sensCounter = 0; sensCounter < sensor.size(); sensCounter++) + { + robotInterface->update(); + if ((int)sensor.at(sensCounter)->getRange(3) < 100 || sensor.at(sensCounter)->getRange(4) < 100) + { + robotInterface->stop(); + control_conflict = true; + break; + } + }; + + while (control_conflict == false) + { + robotInterface->move(100); + for (int sensCounter = 0; sensCounter < sensor.size(); sensCounter++) + { + if ((int)sensor.at(sensCounter)->getRange(3) < 300 || (int)sensor.at(sensCounter)->getRange(4) < 300) + { + robotInterface->stop(); + control_conflict = true; + break; + } + } + } +} + +RobotControl::~RobotControl() +{ +} diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/RobotControl.h" "b/Nesne Tabanl\304\261 Programlama I - Proje/RobotControl.h" new file mode 100644 index 0000000..eaae46e --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/RobotControl.h" @@ -0,0 +1,81 @@ +/** +* @File RobotControl.h +* @Date December, 2017 +* @Author Yusuf Furkan Yücesoy (yusuffurkanyucesoy@gmail.com) +* +* \brief RobotControl Class +* \brief This class used in robot control +*/ +#pragma once +#include +#include +#include "RobotInterface.h" +#include "RangeSensor.h" +#include "SonarSensor.h" +#include "Position.h" +#include "PioneerRobotInterface.h" +using namespace std; +class RobotControl +{ + /** + * \brief sensor is RangeSensor type vector attiribute + */ + vector sensor; + /** + * \brief position attribute(from Position class using composition) + */ + Position *position; + /** + * \brief robotInterface attribute(from RobotInterface class using aggregation) + */ + RobotInterface *robotInterface; +public: + /** + * \brief Default constructor function of the Robot Control class + */ + RobotControl(); + /** + * \brief Constructor function of the Robot Control class + * This function assigns the given values to parameters + * \param robotInterface is RobotInterface type object + * \param pos is Position type object + * \param sensor is RangeSensor type object + */ + RobotControl(RobotInterface *robotInterface,Position *pos,RangeSensor * sensor); + /** + * \brief This function allows the progress of the robot at the desired speed. However, advance of robot stops if there are barriers. + * \param speed is an integer attribute + */ + void safeMove(int speed); + /** + * \brief This function turns the robot to the left. + */ + void turnLeft(); + /** + * \brief This function turns the robot to the right. + */ + void turnRight(); + /** + * \brief This function allows the robot to move in a forward direction + */ + void forward(); + /** + * \brief This function prints tthe robot's position and sensor values on the screeen in a certain format + */ + void print(); + /** + * \brief This function allows the robot to go as far as the given distance, then after the distance has passed stops the robot. + * \param distance is a float attribute + */ + void moveDistance(float distance); + /** + * \brief This function allows the robot to go straight and stops when a wall reaches a certain distance. + + */ + void closeWall(); + /** + * \brief Destrustor function of the RobotControl class. + */ + ~RobotControl(); +}; + diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/RobotInterface.cpp" "b/Nesne Tabanl\304\261 Programlama I - Proje/RobotInterface.cpp" new file mode 100644 index 0000000..6b2d7ba --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/RobotInterface.cpp" @@ -0,0 +1,20 @@ +#include "RobotInterface.h" + +RobotInterface::RobotInterface() +{ + +} + +void RobotInterface::setPosition(Position * pos) +{ + position = pos; +} + +void RobotInterface::setSensor(RangeSensor * sen) +{ + this->rangeSensor = sen; +} + +RobotInterface::~RobotInterface() +{ +} diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/RobotInterface.h" "b/Nesne Tabanl\304\261 Programlama I - Proje/RobotInterface.h" new file mode 100644 index 0000000..113470f --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/RobotInterface.h" @@ -0,0 +1,28 @@ +#pragma once +#include "Position.h" +#include "RangeSensor.h" + +class RobotInterface +{ + Position *position; + RangeSensor *rangeSensor; +public: + enum DIRECTION + { + left = -1, + forward = 0, + right = 1 + }; + RobotInterface(); + void setPosition(Position *pos); + void setSensor(RangeSensor *sen); + virtual void update() = 0; + virtual bool open() = 0; + virtual bool close() = 0; + virtual void move(float speed) = 0; + virtual void turn(DIRECTION dir) = 0; + virtual void stop() = 0; + ~RobotInterface(); + +}; + diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/SonarSensor.cpp" "b/Nesne Tabanl\304\261 Programlama I - Proje/SonarSensor.cpp" new file mode 100644 index 0000000..0d6b443 --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/SonarSensor.cpp" @@ -0,0 +1,69 @@ +#include "SonarSensor.h" + + + +SonarSensor::SonarSensor() +{ + this->type = "Sonar L131 Sensor"; + setType("Sonar L131 Sensor"); +} + +float SonarSensor::getRange(int index) +{ + return this -> ranges[index]; +} + +void SonarSensor::setRange(float range[]) +{ + for (int i = 0; i < 16; i++) + { + this -> ranges[i] = range[i]; + } +} + +float SonarSensor::getMax() +{ + + float maximumValue = this->ranges[0]; + for (int i = 1; i < 16; i++) + { + if (maximumValue < this->ranges[i]) + { + maximumValue = this->ranges[i]; + } + } + return maximumValue; +} + +float SonarSensor::getMin() +{ + float minimumValue = this->ranges[0]; + for (int i = 1; i < 16; i++) + { + if (minimumValue > this->ranges[i]) + { + minimumValue = this->ranges[i]; + } + } + return minimumValue; +} + +void SonarSensor::updateSensor(float ranges[]) +{ + for (int i = 0; i < 16; i++) + { + this->ranges[i] = ranges[i]; + } +} + +float SonarSensor::operator[](int i) +{ + return this->ranges[i]; +} + + + + +SonarSensor::~SonarSensor() +{ +} diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/SonarSensor.h" "b/Nesne Tabanl\304\261 Programlama I - Proje/SonarSensor.h" new file mode 100644 index 0000000..088a62c --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/SonarSensor.h" @@ -0,0 +1,17 @@ +#pragma once +#include "RangeSensor.h" +class SonarSensor : public RangeSensor +{ + float ranges[16]; + string type; +public: + SonarSensor(); + float getRange(int index); + void setRange(float range[]); + float getMax(); + float getMin(); + void updateSensor(float ranges[]); + float operator[](int i); + ~SonarSensor(); +}; + diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/robotApiTest.cpp" "b/Nesne Tabanl\304\261 Programlama I - Proje/robotApiTest.cpp" new file mode 100644 index 0000000..64532ae --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/robotApiTest.cpp" @@ -0,0 +1,39 @@ +#include "PioneerRobotAPI.h" +#include "PioneerRobotInterface.h" +#include "RobotControl.h" +#include +#include "Menu.h" +using namespace std; + +//Bize verilen PioneerRobotAPI sýnýfýný kendimize gore ozellestirelim. + +int main() { + Menu *menu = new Menu(); + /* + robotControl->safeMove(10000); + + robotControl -> turnLeft(); + Sleep(1000); + robotControl->print(); + + + + robotControl->forward(); + Sleep(1000); + robotControl->print(); + + + + robotControl->turnRight(); + Sleep(1000); + + + robotInterface -> stop(); + + cout << "Press any key to exit..."; + getchar(); + + robotInterface -> close();*/ + + +} \ No newline at end of file diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/LaserSensor.obj" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/LaserSensor.obj" new file mode 100644 index 0000000..ec9030a Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/LaserSensor.obj" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Menu.obj" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Menu.obj" new file mode 100644 index 0000000..db96bcb Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Menu.obj" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/CL.command.1.tlog" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/CL.command.1.tlog" new file mode 100644 index 0000000..c4b56d7 Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/CL.command.1.tlog" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/CL.read.1.tlog" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/CL.read.1.tlog" new file mode 100644 index 0000000..1f0e95c Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/CL.read.1.tlog" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/CL.write.1.tlog" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/CL.write.1.tlog" new file mode 100644 index 0000000..7e3f7a5 Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/CL.write.1.tlog" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/Nesne Tabanl\304\261 Programlama I - Proje.lastbuildstate" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/Nesne Tabanl\304\261 Programlama I - Proje.lastbuildstate" new file mode 100644 index 0000000..22a45e8 --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/Nesne Tabanl\304\261 Programlama I - Proje.lastbuildstate" @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1 +Debug|x64|C:\Users\Furkan\Desktop\Nesne Tabanlı Programlama I - Proje\| diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/link.command.1.tlog" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/link.command.1.tlog" new file mode 100644 index 0000000..e4a131a Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/link.command.1.tlog" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/link.read.1.tlog" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/link.read.1.tlog" new file mode 100644 index 0000000..a52c1e7 Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/link.read.1.tlog" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/link.write.1.tlog" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/link.write.1.tlog" new file mode 100644 index 0000000..42a77f4 Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Ta.70BF864F.tlog/link.write.1.tlog" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Tabanl\304\261 Programlama I - Proje.log" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Tabanl\304\261 Programlama I - Proje.log" new file mode 100644 index 0000000..6e12a8c --- /dev/null +++ "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Nesne Tabanl\304\261 Programlama I - Proje.log" @@ -0,0 +1,8 @@ + RobotControl.cpp + Menu.cpp + Generating Code... + Compiling... + robotApiTest.cpp + Generating Code... + Nesne Tabanlı Programlama I - Proje.vcxproj -> C:\Users\Furkan\Desktop\Nesne Tabanlı Programlama I - Proje\x64\Debug\Nesne Tabanlı Programlama I - Proje.exe + Nesne Tabanlı Programlama I - Proje.vcxproj -> C:\Users\Furkan\Desktop\Nesne Tabanlı Programlama I - Proje\x64\Debug\Nesne Tabanlı Programlama I - Proje.pdb (Partial PDB) diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/PioneerRobotInterface.obj" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/PioneerRobotInterface.obj" new file mode 100644 index 0000000..80dba55 Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/PioneerRobotInterface.obj" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Position.obj" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Position.obj" new file mode 100644 index 0000000..2a26695 Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/Position.obj" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/RangeSensor.obj" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/RangeSensor.obj" new file mode 100644 index 0000000..97af7c0 Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/RangeSensor.obj" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/RobotControl.obj" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/RobotControl.obj" new file mode 100644 index 0000000..0c53510 Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/RobotControl.obj" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/RobotInterface.obj" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/RobotInterface.obj" new file mode 100644 index 0000000..82f11e6 Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/RobotInterface.obj" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/SonarSensor.obj" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/SonarSensor.obj" new file mode 100644 index 0000000..d40c7e7 Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/SonarSensor.obj" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/robotApiTest.obj" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/robotApiTest.obj" new file mode 100644 index 0000000..6be6d1f Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/robotApiTest.obj" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/vc140.idb" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/vc140.idb" new file mode 100644 index 0000000..8172123 Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/vc140.idb" differ diff --git "a/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/vc140.pdb" "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/vc140.pdb" new file mode 100644 index 0000000..4f67e98 Binary files /dev/null and "b/Nesne Tabanl\304\261 Programlama I - Proje/x64/Debug/vc140.pdb" differ diff --git "a/x64/Debug/Nesne Tabanl\304\261 Programlama I - Proje.exe" "b/x64/Debug/Nesne Tabanl\304\261 Programlama I - Proje.exe" new file mode 100644 index 0000000..7cffb73 Binary files /dev/null and "b/x64/Debug/Nesne Tabanl\304\261 Programlama I - Proje.exe" differ diff --git "a/x64/Debug/Nesne Tabanl\304\261 Programlama I - Proje.ilk" "b/x64/Debug/Nesne Tabanl\304\261 Programlama I - Proje.ilk" new file mode 100644 index 0000000..6991d2e Binary files /dev/null and "b/x64/Debug/Nesne Tabanl\304\261 Programlama I - Proje.ilk" differ diff --git "a/x64/Debug/Nesne Tabanl\304\261 Programlama I - Proje.pdb" "b/x64/Debug/Nesne Tabanl\304\261 Programlama I - Proje.pdb" new file mode 100644 index 0000000..b3addcf Binary files /dev/null and "b/x64/Debug/Nesne Tabanl\304\261 Programlama I - Proje.pdb" differ