-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from inverted-ai/drive_with_pedestrian_updates
python client tests for drive with pedestrians, cpp client agent attribute bug fixes
- Loading branch information
Showing
17 changed files
with
383 additions
and
59 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <cstdlib> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <string> | ||
#include <vector> | ||
#include <opencv2/highgui.hpp> | ||
#include <opencv2/imgcodecs.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
|
||
#include "../invertedai/api.h" | ||
|
||
using tcp = net::ip::tcp; // from <boost/asio/ip/tcp.hpp> | ||
using json = nlohmann::json; // from <json.hpp> | ||
|
||
int main(int argc, char **argv) { | ||
// Set up drive scenarios from initialize | ||
const char* tests[] = | ||
{ | ||
"examples/initialize_body.json", | ||
"examples/initialize_with_states_and_attributes.json", | ||
"examples/initialize_sampling_with_types.json" | ||
}; | ||
|
||
try { | ||
const int timestep = std::stoi(argv[1]); | ||
const std::string api_key(argv[2]); | ||
|
||
net::io_context ioc; | ||
ssl::context ctx(ssl::context::tlsv12_client); | ||
// configure connection setting | ||
invertedai::Session session(ioc, ctx); | ||
session.set_api_key(api_key); | ||
session.connect(); | ||
int i = 0; | ||
for (const char *test : tests) { | ||
invertedai::InitializeRequest init_req(invertedai::read_file(test)); | ||
invertedai::InitializeResponse init_res = invertedai::initialize(init_req, &session); | ||
auto image = cv::imdecode(init_res.birdview(), cv::IMREAD_COLOR); | ||
cv::cvtColor(image, image, cv::COLOR_BGR2RGB); | ||
int frame_width = image.rows; | ||
int frame_height = image.cols; | ||
std::string drive_video_name = "drive_test_" + std::to_string(i) + ".avi"; | ||
cv::VideoWriter video( | ||
drive_video_name, | ||
cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), | ||
10, | ||
cv::Size(frame_width, frame_height) | ||
); | ||
i += 1; | ||
invertedai::DriveRequest drive_req(invertedai::read_file("examples/drive_body.json")); | ||
drive_req.set_location(init_req.location()); | ||
drive_req.update(init_res); | ||
|
||
for (int t = 0; t < timestep; t++) { | ||
// step the simulation by driving the agents | ||
invertedai::DriveResponse drive_res = invertedai::drive(drive_req, &session); | ||
// use opencv to decode and save the bird's eye view image of the | ||
// simulation | ||
auto image = cv::imdecode(drive_res.birdview(), cv::IMREAD_COLOR); | ||
cv::cvtColor(image, image, cv::COLOR_BGR2RGB); | ||
video.write(image); | ||
drive_req.update(drive_res); | ||
std::cout << "Remaining iterations: " << timestep - t << std::endl; | ||
} | ||
video.release(); | ||
} | ||
} catch (std::exception const &e) { | ||
std::cerr << "Error: " << e.what() << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
return EXIT_SUCCESS; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
{ | ||
"location": "iai:ubc_roundabout", | ||
"location": "carla:Town03", | ||
"num_agents_to_spawn": 10, | ||
"states_history": null, | ||
"agent_attributes": null, | ||
"traffic_light_state_history": null, | ||
"get_birdview": false, | ||
"get_infractions": false, | ||
"get_birdview": true, | ||
"get_infractions": true, | ||
"random_seed": null, | ||
"location_of_interest": null | ||
} |
17 changes: 17 additions & 0 deletions
17
invertedai_cpp/examples/initialize_sampling_with_types.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"location": "carla:Town04", | ||
"num_agents_to_spawn": 10, | ||
"states_history": null, | ||
"agent_attributes": [ | ||
["car"], | ||
["pedestrian"], | ||
[], | ||
["pedestrian"], | ||
["pedestrian"] | ||
], | ||
"traffic_light_state_history": null, | ||
"get_birdview": true, | ||
"get_infractions": true, | ||
"random_seed": null, | ||
"location_of_interest": null | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <cstdlib> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <string> | ||
#include <vector> | ||
#include <opencv2/highgui.hpp> | ||
#include <opencv2/imgcodecs.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
|
||
#include "../invertedai/api.h" | ||
|
||
using tcp = net::ip::tcp; // from <boost/asio/ip/tcp.hpp> | ||
using json = nlohmann::json; // from <json.hpp> | ||
|
||
int main(int argc, char **argv) { | ||
// list of test scenarios to run | ||
const char* tests[] = | ||
{ | ||
"examples/initialize_body.json", | ||
"examples/initialize_with_states_and_attributes.json", | ||
"examples/initialize_sampling_with_types.json" | ||
}; | ||
|
||
try { | ||
const std::string api_key(argv[1]); | ||
|
||
net::io_context ioc; | ||
ssl::context ctx(ssl::context::tlsv12_client); | ||
// configure connection setting | ||
invertedai::Session session(ioc, ctx); | ||
session.set_api_key(api_key); | ||
session.connect(); | ||
int i = 0; | ||
for (const char *test : tests) { | ||
invertedai::InitializeRequest init_req(invertedai::read_file(test)); | ||
invertedai::InitializeResponse init_res = invertedai::initialize(init_req, &session); | ||
auto image = cv::imdecode(init_res.birdview(), cv::IMREAD_COLOR); | ||
cv::cvtColor(image, image, cv::COLOR_BGR2RGB); | ||
std::string img_name = "initialize_test_" + std::to_string(i) + ".png"; | ||
cv::imwrite(img_name, image); | ||
i += 1; | ||
} | ||
} catch (std::exception const &e) { | ||
std::cerr << "Error: " << e.what() << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
return EXIT_SUCCESS; | ||
} |
81 changes: 81 additions & 0 deletions
81
invertedai_cpp/examples/initialize_with_states_and_attributes.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"location": "canada:ubc_roundabout", | ||
"num_agents_to_spawn": 10, | ||
"states_history": [ | ||
[ | ||
[ | ||
-11.38, | ||
25.95, | ||
-1.09, | ||
9.42 | ||
], | ||
[ | ||
48.3, | ||
13.65, | ||
0.11, | ||
0.95 | ||
], | ||
[ | ||
-5.81, | ||
-37.0, | ||
0.15, | ||
0.47 | ||
], | ||
[ | ||
-11.75, | ||
24.38, | ||
-2.29, | ||
0.98 | ||
], | ||
[ | ||
36.69, | ||
6.91, | ||
-3.07, | ||
6.18 | ||
] | ||
] | ||
], | ||
"agent_attributes": [ | ||
[ | ||
5.15, | ||
2.43, | ||
1.96, | ||
"car" | ||
], | ||
[ | ||
1.2, | ||
1.51, | ||
null, | ||
"pedestrian" | ||
], | ||
[ | ||
5.11, | ||
2.17, | ||
1.94, | ||
"car" | ||
], | ||
[ | ||
1.16, | ||
1.41, | ||
null, | ||
"pedestrian" | ||
], | ||
[ | ||
5.18, | ||
2.22, | ||
1.97, | ||
"car" | ||
], | ||
[ | ||
|
||
], | ||
[ | ||
"pedestrian" | ||
] | ||
], | ||
"traffic_light_state_history": null, | ||
"get_birdview": true, | ||
"get_infractions": true, | ||
"random_seed": null, | ||
"location_of_interest": null | ||
} |
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
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
Oops, something went wrong.