From bd44af42c43ca819ef53e3aabbfb20c8c500d997 Mon Sep 17 00:00:00 2001 From: Vita Aeterna <75674735+VitaAetaerna@users.noreply.github.com> Date: Mon, 30 Jan 2023 09:43:46 +0100 Subject: [PATCH] Create TraffixLightArray --- TraffixLightArray | 201 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 TraffixLightArray diff --git a/TraffixLightArray b/TraffixLightArray new file mode 100644 index 0000000..186f794 --- /dev/null +++ b/TraffixLightArray @@ -0,0 +1,201 @@ +#include +#include +#include "rec/robotino/api2/all.h" +#include + +using namespace rec::robotino::api2; +using namespace std; +bool _run = true; + +class MyCom : public Com +{ +public: + MyCom() + : Com( "TrafficLight" ) + { + } + + void errorEvent( const char* errorString ) + { + std::cerr << "Error: " << errorString << std::endl; + } + + void connectedEvent() + { + std::cout << "Connected." << std::endl; + } + + void connectionClosedEvent() + { + std::cout << "Connection closed." << std::endl; + } + + void logEvent( const char* message, int level ) + { + std::cout << message << std::endl; + } +}; + +class MyBumper : public Bumper +{ +public: + MyBumper() + : bumped( false ) + { + } + + void bumperEvent( bool hasContact ) + { + bumped |= hasContact; + if (true == bumped){ + std::cout << "Bumper has " << ( hasContact ? "contact" : "no contact") << std::endl; + } + } + + bool bumped; +}; + +double x_distance = 0; +double y_distance = 0; +int phi_absolute = 0; +unsigned int sequence = 0; + + + +int digital_inputs[8] = {0,0,0,0,0,0,0,0}; +int digital_outputs[8] = {1,1,1,1,1,1,1,1}; + +class MyOdometry: public Odometry{ + void readingsEvent(double x,double y, double phi, float vx, float vy, float omega, unsigned int seq ){ + // cout << "X: " << x << " Y: " << y << " Richtung: " << phi << " Sequenz: " << seq << endl; + x_distance = x; + y_distance = y; + phi_absolute = phi; + sequence = seq; + } +}; + + + + +class MyDigitalInputArray: public DigitalInputArray{ + + void valuesChangedEvent(const int *value, unsigned int size){ + + for (int i=0; i 1 ) + { + hostname = argv[1]; + } + + + + //main program routine starts in here + try + { + //connect to your robotino (or try at least) + init( hostname ); + //drive (this contains a while loop) + while(true){ + myout.setValues(digital_outputs, 8); + for (int i=0; i<8; i++){ + digital_outputs[i] = ! digital_outputs[i]; + + } + rec::robotino::api2::msleep(1000); + } + //drive(); + //exit + + com.disconnectFromServer(); + + } + catch( const rec::robotino::api2::RobotinoException& e ) + { + std::cerr << "Com Error: " << e.what() << std::endl; + } + catch( const std::exception& e ) + { + std::cerr << "Error: " << e.what() << std::endl; + } + catch( ... ) + { + std::cerr << "Unknow Error" << std::endl; + } + + rec::robotino::api2::shutdown(); + +#ifdef WIN32 + std::cout << "Press any key to exit..." << std::endl; + rec::robotino::api2::waitForKey(); +#endif +}