Skip to content

Commit 63d547b

Browse files
committed
Format examples and add Acrobot example
1 parent d8cfb84 commit 63d547b

File tree

16 files changed

+993
-990
lines changed

16 files changed

+993
-990
lines changed

examples/arduino/arduino_example.cpp

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#include "bitrl/boards/arduino/arduino_connector_usb_base.h"
22

3+
#include <chrono>
34
#include <iostream>
45
#include <string>
5-
#include <chrono>
66
#include <thread>
77

8-
98
/*
109
Arduino Code
1110
String incomingMessage = "";
@@ -33,35 +32,28 @@
3332
}
3433
*/
3534

36-
3735
namespace example
3836
{
39-
using bitrl::boards::arduino::ArduinoCMDBase;
40-
using bitrl::boards::arduino::ArduinoConnectorUSBBase;
37+
using bitrl::boards::arduino::ArduinoCMDBase;
38+
using bitrl::boards::arduino::ArduinoConnectorUSBBase;
4139

42-
struct ArduinoONCMD: public ArduinoCMDBase
43-
{
44-
virtual std::string get_cmd()const final;
45-
};
40+
struct ArduinoONCMD : public ArduinoCMDBase
41+
{
42+
virtual std::string get_cmd() const final;
43+
};
4644

47-
std::string ArduinoONCMD::get_cmd() const
48-
{
49-
return "ON";
50-
}
45+
std::string ArduinoONCMD::get_cmd() const { return "ON"; }
5146

52-
struct ArduinoOFFCMD: public ArduinoCMDBase
53-
{
54-
virtual std::string get_cmd()const final;
55-
};
56-
57-
std::string ArduinoOFFCMD::get_cmd() const
58-
{
59-
return "OFF";
60-
}
61-
}
47+
struct ArduinoOFFCMD : public ArduinoCMDBase
48+
{
49+
virtual std::string get_cmd() const final;
50+
};
6251

52+
std::string ArduinoOFFCMD::get_cmd() const { return "OFF"; }
53+
} // namespace example
6354

64-
int main() {
55+
int main()
56+
{
6557

6658
using namespace example;
6759

@@ -72,11 +64,13 @@ int main() {
7264
ArduinoOFFCMD off_cmd;
7365

7466
std::string user_input;
75-
while (true) {
67+
while (true)
68+
{
7669
std::cout << "Enter command ON/OFF or e (to exit): ";
7770
std::getline(std::cin, user_input);
7871

79-
if (user_input == "e") {
72+
if (user_input == "e")
73+
{
8074
connector.send_cmd(off_cmd);
8175
break;
8276
}

examples/arduino_wifi/arduino_wifi_example.cpp

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
// Created by alex on 7/5/25.
33
//
44

5-
#include "bitrl/boards/arduino/arduino_connector_wifi_base.h"
5+
#include "bitrl/boards/arduino/arduino_connector_wifi_base.h"
66
#include <iostream>
77

8-
#include <thread>
98
#include <chrono>
10-
9+
#include <thread>
1110

1211
/**
1312
* // Code for Arduino
@@ -91,65 +90,59 @@ void loop() {
9190
*/
9291
namespace example
9392
{
94-
using bitrl::boards::arduino::ArduinoCMDBase;
95-
using bitrl::boards::arduino::ArduinoConnectorWIFIBase;
93+
using bitrl::boards::arduino::ArduinoCMDBase;
94+
using bitrl::boards::arduino::ArduinoConnectorWIFIBase;
9695

97-
struct ArduinoONCMD: public ArduinoCMDBase
98-
{
99-
virtual std::string get_cmd()const final;
100-
};
96+
struct ArduinoONCMD : public ArduinoCMDBase
97+
{
98+
virtual std::string get_cmd() const final;
99+
};
101100

102-
std::string ArduinoONCMD::get_cmd() const
103-
{
104-
return "ON";
105-
}
101+
std::string ArduinoONCMD::get_cmd() const { return "ON"; }
106102

107-
struct ArduinoOFFCMD: public ArduinoCMDBase
108-
{
109-
virtual std::string get_cmd()const final;
110-
};
103+
struct ArduinoOFFCMD : public ArduinoCMDBase
104+
{
105+
virtual std::string get_cmd() const final;
106+
};
111107

112-
std::string ArduinoOFFCMD::get_cmd() const
113-
{
114-
return "OFF";
115-
}
116-
}
108+
std::string ArduinoOFFCMD::get_cmd() const { return "OFF"; }
109+
} // namespace example
117110

118-
int main() {
111+
int main()
112+
{
119113

114+
using namespace example;
120115

121-
using namespace example;
116+
ArduinoConnectorWIFIBase connector("http://192.168.0.70:8005");
117+
ArduinoONCMD on_cmd;
118+
ArduinoOFFCMD off_cmd;
122119

123-
ArduinoConnectorWIFIBase connector("http://192.168.0.70:8005");
124-
ArduinoONCMD on_cmd;
125-
ArduinoOFFCMD off_cmd;
120+
std::string user_input;
121+
while (true)
122+
{
123+
std::cout << "Enter command ON/OFF or e (to exit): ";
124+
std::getline(std::cin, user_input);
126125

127-
std::string user_input;
128-
while (true)
129-
{
130-
std::cout << "Enter command ON/OFF or e (to exit): ";
131-
std::getline(std::cin, user_input);
126+
if (user_input == "e")
127+
{
128+
connector.send_cmd(off_cmd);
129+
break;
130+
}
132131

133-
if (user_input == "e") {
134-
connector.send_cmd(off_cmd);
135-
break;
136-
}
132+
if (user_input == "ON")
133+
{
134+
auto response = connector.send_cmd(on_cmd);
135+
std::cout << "Arduino response: " << response << std::endl;
136+
}
137137

138-
if (user_input == "ON")
139-
{
140-
auto response = connector.send_cmd(on_cmd);
141-
std::cout<<"Arduino response: "<<response<<std::endl;
142-
}
138+
if (user_input == "OFF")
139+
{
140+
auto response = connector.send_cmd(off_cmd);
141+
std::cout << "Arduino response: " << response << std::endl;
142+
}
143143

144-
if (user_input == "OFF")
145-
{
146-
auto response = connector.send_cmd(off_cmd);
147-
std::cout<<"Arduino response: "<<response<<std::endl;
144+
std::this_thread::sleep_for(std::chrono::seconds(1));
148145
}
149146

150-
std::this_thread::sleep_for(std::chrono::seconds(1));
151-
}
152-
153147
return 0;
154148
}
155-

examples/box2d/box2d_example.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
#include "bitrl/envs/gymnasium/box2d/lunar_lander_env.h"
66
#include "bitrl/network/rest_rl_env_client.h"
77

8+
#include <iostream>
89
#include <unordered_map>
910
#include <vector>
10-
#include <iostream>
1111

1212
#include "../../src/bitrl/sensors/ekf_sensor_fusion.h"
1313

1414
namespace box2d_example
1515
{
16-
using namespace bitrl;
17-
const std::string SERVER_URL = "http://0.0.0.0:8001/api";
18-
using bitrl::real_t;
19-
using bitrl::envs::gymnasium::LunarLanderDiscreteEnv;
20-
using bitrl::envs::gymnasium::LunarLanderContinuousEnv;
21-
}
16+
using namespace bitrl;
17+
const std::string SERVER_URL = "http://0.0.0.0:8001/api";
18+
using bitrl::real_t;
19+
using bitrl::envs::gymnasium::LunarLanderContinuousEnv;
20+
using bitrl::envs::gymnasium::LunarLanderDiscreteEnv;
21+
} // namespace box2d_example
2222

2323
int main()
2424
{
@@ -32,7 +32,6 @@ int main()
3232
options["gravity"] = std::any(static_cast<bitrl::real_t>(-9.86));
3333
options["turbulence_power"] = std::any(static_cast<bitrl::real_t>(1.5));
3434

35-
3635
/*{
3736
std::cout<<"Working with LunarLanderDiscreteEnv..."<<std::endl;
3837
LunarLanderDiscreteEnv env(server);
@@ -56,28 +55,24 @@ int main()
5655
copy.close();
5756
}*/
5857
{
59-
std::cout<<"Working with LunarLanderContinuousEnv..."<<std::endl;
58+
std::cout << "Working with LunarLanderContinuousEnv..." << std::endl;
6059

6160
LunarLanderContinuousEnv env(server);
6261

6362
std::unordered_map<std::string, std::any> reset_options;
6463
env.make("v3", options, reset_options);
6564

66-
std::cout<<"Is environment created? "<<env.is_created()<<std::endl;
67-
std::cout<<"Is environment alive? "<<env.is_alive()<<std::endl;
68-
std::cout<<"Action space size "<<env.n_actions()<<std::endl;
69-
std::cout<<"Environment URI: "<<server.get_uri(env.env_name())<<std::endl;
65+
std::cout << "Is environment created? " << env.is_created() << std::endl;
66+
std::cout << "Is environment alive? " << env.is_alive() << std::endl;
67+
std::cout << "Action space size " << env.n_actions() << std::endl;
68+
std::cout << "Environment URI: " << server.get_uri(env.env_name()) << std::endl;
7069

7170
auto time_step = env.reset();
72-
std::cout<<"Time step: "<<time_step<<std::endl;
71+
std::cout << "Time step: " << time_step << std::endl;
7372

7473
std::vector<real_t> action = {0.8, 0.9};
7574
time_step = env.step(action);
76-
std::cout<<"Time step: "<<time_step<<std::endl;
75+
std::cout << "Time step: " << time_step << std::endl;
7776
env.close();
78-
7977
}
80-
8178
}
82-
83-

0 commit comments

Comments
 (0)