Skip to content
Snippets Groups Projects
Commit cd34adc2 authored by odri's avatar odri
Browse files

Continue to test things

parent 492906d0
No related branches found
No related tags found
No related merge requests found
......@@ -66,14 +66,14 @@ class MpcWrapper {
void run_MPC_asynchronous(int k, MatrixN const& xref, MatrixN const& fsteps);
void create_MPC_asynchronous();
//static int check_memory();
// int check_memory();
private:
Params* params_;
MPC mpc_;
// shared_memory_object shm (boost::interprocess::create_only, "MySharedMemory", boost::interprocess::read_write);
// shared_memory_object shm (boost::interprocess::create_only, "SharedMemory", boost::interprocess::read_write);
// mapped_region region;
bi::managed_shared_memory segment;
......
......@@ -21,13 +21,13 @@ Controller::Controller()
xgoals(Vector12::Zero())
{
namespace bi = boost::interprocess;
bi::shared_memory_object::remove("MySharedMemory");
bi::shared_memory_object::remove("SharedMemory");
/*//Remove shared memory on construction and destruction
struct shm_remove
{
shm_remove() { bi::shared_memory_object::remove("MySharedMemory"); }
~shm_remove(){ bi::shared_memory_object::remove("MySharedMemory"); }
shm_remove() { bi::shared_memory_object::remove("SharedMemory"); }
~shm_remove(){ bi::shared_memory_object::remove("SharedMemory"); }
} remover;*/
}
......
#include "qrw/MpcWrapper.hpp"
// bi::managed_shared_memory MpcWrapper::segment = bi::managed_shared_memory(bi::open_or_create, "MySharedMemory", 5000);
// bi::managed_shared_memory MpcWrapper::segment = bi::managed_shared_memory(bi::open_or_create, "SharedMemory", 5000);
MpcWrapper::MpcWrapper()
: test(0),
last_available_result(Eigen::Matrix<double, 24, 2>::Zero()),
gait_past(Matrix14::Zero()),
gait_next(Matrix14::Zero()),
segment(bi::open_or_create, "MySharedMemory", 1000) {}
segment(bi::open_or_create, "SharedMemory", 1000) {}
/*int check_memory(bi::managed_shared_memory &segment)
int check_memory()
{
/
/*
//Open already created shared memory object.
shared_memory_object shm_parallel(open_only, "MySharedMemory", read_only);
shared_memory_object shm_parallel(open_only, "SharedMemory", read_only);
//Map the whole shared memory in this process
mapped_region region_parallel(shm_parallel, read_only);
......@@ -28,29 +28,30 @@ MpcWrapper::MpcWrapper()
printf("NO ERROR DETECTED\n");
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
return 0;/
return 0;
*/
printf("PASS\n");
std::pair<int*, std::size_t> test0 = segment.find<int>("shared_k");
std::pair<MatrixN*, std::size_t> test1 = segment.find<MatrixN>("shared_xref");
std::pair<MatrixN*, std::size_t> test2 = segment->find<MatrixN>("shared_fsteps");
while (true)
{
std::cout << "shared_k: " << std::endl << *(test0.first) << std::endl;
std::cout << "shared_xref: " << std::endl << *(test1.first) << std::endl;
std::cout << "shared_fsteps: " << std::endl << *(test2.first) << std::endl;
/int* test0 = segment.find_or_construct<int>("shared_k");
bi::managed_shared_memory segment_parallel(bi::open_only, "SharedMemory");
std::pair<int*, std::size_t> test0 = segment_parallel.find<int>("shared_k");
//std::pair<MatrixN*, std::size_t> test1 = segment_parallel.find<MatrixN>("shared_xref");
//std::pair<MatrixN*, std::size_t> test2 = segment_parallel.find<MatrixN>("shared_fsteps");
//while (true)
//{
// std::this_thread::sleep_for(std::chrono::milliseconds(500));
// std::cout << "shared_k: " << std::endl << *(test0.first) << std::endl;
//std::cout << "shared_xref: " << std::endl << *(test1.first) << std::endl;
//std::cout << "shared_fsteps: " << std::endl << *(test2.first) << std::endl;
/*int* test0 = segment.find_or_construct<int>("shared_k");
MatrixN* test1 = segment.find_or_construct<MatrixN>("shared_xref");
MatrixN* test2 = segment.find_or_construct<MatrixN>("shared_fsteps");
std::cout << "shared_k: " << std::endl << test0 << std::endl;
std::cout << "shared_xref: " << std::endl << test1 << std::endl;
std::cout << "shared_fsteps: " << std::endl << test2 << std::endl;/
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
std::cout << "shared_fsteps: " << std::endl << test2 << std::endl;*/
//}
return 0;
}*/
}
void MpcWrapper::initialize(Params& params) {
......@@ -62,20 +63,20 @@ void MpcWrapper::initialize(Params& params) {
last_available_result.col(0).tail(12) = (Vector3(0.0, 0.0, 8.0)).replicate<4, 1>();
// Initialization of the shared memory
// shared_k = segment.construct<int>("shared_k") ();
// shared_xref = segment.construct<MatrixN>("shared_xref") (12, params.gait.rows() + 1);
// shared_fsteps = segment.construct<MatrixN>("shared_fsteps") (params.gait.rows(), 12);
shared_k = segment.construct<int>("shared_k") (42);
/*shared_xref = segment.construct<MatrixN>("shared_xref") (12, params.gait.rows() + 1);
shared_fsteps = segment.construct<MatrixN>("shared_fsteps") (params.gait.rows(), 12);*/
// Initialization of shared memory
// Remove shared memory on construction and destruction
/*struct shm_remove
{
shm_remove() { shared_memory_object::remove("MySharedMemory"); }
~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
shm_remove() { shared_memory_object::remove("SharedMemory"); }
~shm_remove(){ shared_memory_object::remove("SharedMemory"); }
} remover;*/
// Create a shared memory object.
/*bi::shared_memory_object shm (bi::create_only, "MySharedMemory", bi::read_write);
/*bi::shared_memory_object shm (bi::create_only, "SharedMemory", bi::read_write);
// Set size
shm.truncate(500);
......@@ -86,9 +87,12 @@ void MpcWrapper::initialize(Params& params) {
// Write all the memory to 1
std::memset(region.get_address(), 1, region.get_size());*/
// std::thread checking_thread(check_memory, segment); // spawn new thread that calls check_memory()
std::thread checking_thread(check_memory); // spawn new thread that calls check_memory()
// checking_thread.join();
//std::pair<int*, std::size_t> test0 = segment.find<int>("shared_k");
// std::cout << "shared_k: " << std::endl << *(test0.first) << std::endl;
}
void MpcWrapper::solve(int k, MatrixN const& xref, MatrixN const& fsteps,
......@@ -96,11 +100,11 @@ void MpcWrapper::solve(int k, MatrixN const& xref, MatrixN const& fsteps,
std::cout << "Pass mpcWrapper" << std::endl;
std::cout << "SIZES" << std::endl;
/*std::cout << "SIZES" << std::endl;
std::cout << sizeof((int)5) << std::endl;
std::cout << sizeof(MatrixN::Zero(12, params_->gait.rows() + 1)) << std::endl;
std::cout << sizeof(MatrixN::Zero(params_->gait.rows(), 12)) << std::endl;
std::cout << params_->gait << std::endl;
std::cout << params_->gait << std::endl;*/
// std::thread checking_thread(check_memory); // spawn new thread that calls check_memory()
// checking_thread.join();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment