gusimplewhiteboard
NXT_Two_Touch_Status.hpp
Go to the documentation of this file.
1#ifndef NXT_Two_Touch_Status_DEFINED
2#define NXT_Two_Touch_Status_DEFINED
3
4#include <cstdlib>
5#include <stdlib.h>
6#include <cstring>
7#include <sstream>
8#include <gu_util.h>
9#include "gusimplewhiteboard.h"
10#include "wb_buttons_status.h"
11
12namespace guWhiteboard {
18 public:
21
22#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
24 NXT_Two_Touch_Status(const std::string &name) {
25 from_string(name);
26 }
27
29 std::string description() {
30 std::ostringstream ss;
31 for (int b= LEFT_BUTTON ; b <NUMBER_OF_NXT_BUTTONS; b++)
32 { wb_button aButton =touch_sensors(b);
33 ss << static_cast<int>(aButton.is_pressed()) << ",";
34 }
35 return ss.str();
36 }
37
39 void from_string (std::string str) {
40 using namespace std;
41 wb_button &l = touch_sensors(LEFT_BUTTON);
42 wb_button &r = touch_sensors(RIGHT_BUTTON);
43 l.set_is_pressed(false);
44 r.set_is_pressed(false);
45 vector<string> elements = components_of_string_separated(str, ',', true);
46
47 if (elements.size() == 0) return; // nothin in the string ESCAPE
48
49 // ONE ELEMNET
50 if (0!=atoi(elements[0].c_str() )) l.set_is_pressed(true);
51 if (elements.size() < 2) return; // only one lement in the string =>ESCAPE
52 if (0!=atoi(elements[1].c_str() )) r.set_is_pressed(true);
53 }
54#endif
57 bool temp = true;
58 for (int b= LEFT_BUTTON ; b <NUMBER_OF_NXT_BUTTONS; b++)
59 { wb_button aButton =touch_sensors(b);
60 wb_button otherButton =s.touch_sensors(b);
61 if (aButton.is_pressed()!= otherButton.is_pressed() )
62 return false;
63 }
64 return temp;
65 }
66
67 };
68}
69#endif //NXT_Two_Touch_Status_DEFINED
Class for controlling differential robots Defines whiteboard message.
bool operator==(const NXT_Two_Touch_Status &s)
override equality operator so we can compare instances
NXT_Two_Touch_Status()
Designated constructor.
void from_string(std::string str)
string conversion
std::string description()
get message description
NXT_Two_Touch_Status(const std::string &name)
String constructor.
/file APM_Interface.h
/file wb_button.h
Definition: wb_button.h:18
An Array of buttons for talking with an NXT.
@ RIGHT_BUTTON
@ LEFT_BUTTON
@ NUMBER_OF_NXT_BUTTONS