Using OMPL with Drake - drake

I am trying to work with ompl on drake and am having issues with using the ompl headers in drake. I installed ompl using the default installation path and made the following changes in drake:
Added the following to the workspace:
new_local_repository(
name = "ompl",
path = "/usr/local/include/ompl-1.5/ompl",
build_file = "ompl.BUILD",
)
ompl.BUILD:
cc_library(
name = "ompl",
hdrs = glob(["**"]),
includes = ["include"],
visibility = ["//visibility:public"],
linkstatic = 1,
)
In my repository's BUILD.bazel:
drake_cc_binary(
name = "ompl_ex",
srcs = ["src/ompl_ex.cc"],
data = [],
test_rule_args = ["--target_realtime_rate=0.0"],
deps = [
"#gflags",
"#ompl//:ompl",
],
)
ompl_ex.cc
#include <memory>
#include <limits.h>
#include <unistd.h>
#include <fstream>
#include <string>
#include <gflags/gflags.h>
#include <iostream>
#include <ompl/config.h>
#include <vector>
namespace drake {
namespace ompl {
int DoMain(){
std::cout<<"the function is working"<<std::endl;
return 0;
}
} // namespace examples
} // namespace drake
int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
return drake::ompl::DoMain();
}
The error I get:
infinite_horizon_ltl/src/ompl_ex.cc:10:10: fatal error: ompl/config.h: No such file or directory
#include <ompl/config.h>
I use spot libraries similarly and they seem to be working fine. Not sure what I am getting wrong in the case of OMPL. I checked on drakes git issues and found that there was an attempt at integration but the branch is deleted now, and the solution proposed does not seem to be working on my system.

I have found that it is easiest to work with drake as an external library in a cmake project. This works quite well with ompl. Here's a quick example which imports both drake and ompl as external libraries and solves a simple planning problem.
https://github.com/DexaiRobotics/drake-torch/tree/master/examples/drake-ompl
The output and video were made using the dexai2/drake-torch/cpu-nightly-ros docker which is available here: https://hub.docker.com/r/dexai2/drake-torch/tags
As an aside, depending on which version of Ubuntu you use, you may need change your gcc version - e.g. you need gcc-9 and g++-9 specified in the CMakeLists.txt for Ubuntu 20.04 and gcc-7 and g++-7 on 18.04. See notes here: https://drake.mit.edu/developers.html#id10

Related

Visual Studio 2017 Error - language feature 'nested-namespace-definition' requires compiler flag '/std:c++17'

Using MS Visual studio I created a solution containing 2 projects called MainProject and CalcProject
MainProject is a console app that references CalcProject and only contains main() in a .cpp file
CalProject is a library and contains a few header files with the following:
Nml.h contains the following:
#include <cstdint>
#include " Ftr.h"
#include " Mtr.h"
namespace CalcProject::measure
{
class Mtr;
class Ftr;
class Nml
{
public:
...
Ftr.h contains the following:
#include <cstdint>
#include " Mtr.h"
#include " Nml.h"
namespace CalcProject::measure
{
class Mtr;
class Nml;
class Ftr
{
...
Mtr.h contains the following:
#include " Ftr.h"
#include " Nml.h"
namespace CalcProject::measure
{
class Ftr;
class Nml;
class Mtr
{
...
MainProject.cpp contains the following:
#include "pch.h"
#include "Ftr.h"
#include <iostream>
#include <string>
using namespace CalcProject::measure;
int main()
{
When I build the solution I receive the following error
Error C2429 language feature 'nested-namespace-definition' requires compiler flag '/std:c++17' MainProject
I tried to resolve this by specifying /std:c++17 in the C++ Language standard in the project properties but the error persists.
How can I fix this? Please advise on a possible solution. I am a beginner and this is my first C++ project using multiple header and cpp files to create a library.

Using Clang to get AST

I would like to use Clang to get to its AST to get some information about the variables and methods in a particular source file. However, I do not want to use the LibTooling facilities. I would like to, by hand, to write to code that would call the methods to parse the .cpp and then get the tree. I can not find any resources that tell me how to do this. Can anybody help?
If your goal is to learn how to drive Clang components to work with the compilation database, configure the compiler instance, and so on, then the Clang source code is a resource. Perhaps the source for the ClangTool::buildASTs() method would be a good place to start: see Tooling.cpp in the lib/Tooling/ directory of the source tree.
If your goal is to do an analysis that LibTooling doesn't support, and you just want to get the AST with minimal fuss, then either ClangTool::buildASTs or clang::tooling::buildASTFromCode might be of service. The ClangTool approach would be better if you need the compilation database to express compiler options, include paths, and so on. buildASTFromCode is fine if you have a standalone bit of code for lightweight tests. Here's an example of the ClangTool approach:
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/CommandLine.h"
#include <memory>
#include <vector>
static llvm::cl::OptionCategory MyOpts("Ignored");
int main(int argc, const char ** argv)
{
using namespace clang;
using namespace clang::tooling;
CommonOptionsParser opt_prs(argc, argv, MyOpts);
ClangTool tool(opt_prs.getCompilations(), opt_prs.getSourcePathList());
using ast_vec_t = std::vector<std::unique_ptr<ASTUnit>>;
ast_vec_t asts;
tool.buildASTs(asts);
// now you the AST for each translation unit
...
Here's an example of buildASTFromCode:
#include "clang/Frontend/ASTUnit.h"
#include "clang/Tooling/Tooling.h"
...
std::string code = "struct A{public: int i;}; void f(A & a}{}";
std::unique_ptr<clang::ASTUnit> ast(clang::tooling::buildASTFromCode(code));
// now you have the AST for the code snippet
clang::ASTContext * pctx = &(ast->getASTContext());
clang::TranslationUnitDecl * decl = pctx->getTranslationUnitDecl();
...

Opencv linking libraries

i have installed opencv 3.1.0 and i want to compile following program:
#include <stdio.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
int main(void){
return 0;
}
but it returns error:undefined reference to cvRound and so on in header file types_c.h.
I know it must be a linking problem but the only libraries i can link are:
opencv_world310.lib, opencv_world310d.lib
I have already tried to link these but that doesn't solve the problem.
I m using a GNU GCC Compiler and dynamic libraries a link with mingw32-g++.exe.
According to some research in the internet i need to link libraries like:
`opencv_calib3d249d.lib`
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_nonfree249d.lib
opencv_objdetect249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib`
but those are not in my lib directory!

fatal error LNK1104: cannot open file 'opencv_calib3d246.dll'

I'm trying to run visual c++ with OpenCV. I have linked the OpenCV to Visual studio 2012. when I tried to run the code, it's giving me an error;
LINK : fatal error LNK1104: cannot open file 'opencv_calib2d246.dll'
Here's what I was trying to do:
#include "stdafx.h"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\core\core.hpp"
#include<iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if(argc !=2)
{
cout <<"usage: display_image ImageToLoadAndDisplay"<<endl;
return -1;
}
Mat image;
image=imread(argv[1],CV_LOAD_IMAGE_UNCHANGED);
if(! image.data)
{
cout<<"couldn't open or find the image"<<endl;
return -1;
}
namedWindow("Display Window",WINDOW_AUTOSIZE);
imshow("Display Window",image);
waitKey(0);
return 0;
}
I have included all the libraries. I'm using OpenCV 2.4.6, on windows 7 32 bit system.
Anything more I have to add, or do I have to initialize it in the program?
Update
The path for OpenCV in my hard disk :E:\opencv\opencv. Path in the system environment variable: %OPENCV_DIR%\x86\vc11\bin;, where I have created a new variable as OPENCV_DIR and have given the path as E:\opencv\opencv\build. And in linker\command line
/OUT:"E:\VS2012 Projects\cvtest\Debug\cvtest.exe" /MANIFEST /NXCOMPAT /PDB:"E:\VS2012 Projects\cvtest\Debug\cvtest.pdb" /DYNAMICBASE "opencv_calib3d248.lib" "opencv_calib3d248d.lib" "opencv_contrib248.lib" "opencv_contrib248d.lib" "opencv_core248.lib" "opencv_core248d.lib" "opencv_features2d248.lib" "opencv_features2d248d.lib" "opencv_flann248.lib" "opencv_flann248d.lib" "opencv_gpu248.lib" "opencv_gpu248d.lib" "opencv_highgui248.lib" "opencv_highgui248d.lib" "opencv_imgproc248.lib" "opencv_imgproc248d.lib" "opencv_legacy248.lib" "opencv_legacy248d.lib" "opencv_ml248.lib" "opencv_ml248d.lib" "opencv_nonfree248.lib" "opencv_nonfree248d.lib" "opencv_objdetect248.lib" "opencv_objdetect248d.lib" "opencv_ocl248.lib" "opencv_ocl248d.lib" "opencv_photo248.lib" "opencv_photo248d.lib" "opencv_stitching248.lib" "opencv_stitching248d.lib" "opencv_superres248.lib" "opencv_superres248d.lib" "opencv_ts248.lib" "opencv_ts248d.lib" "opencv_video248.lib" "opencv_video248d.lib" "opencv_videostab248.lib" "opencv_videostab248d.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X86 /INCREMENTAL /PGD:"E:\VS2012 Projects\cvtest\Debug\cvtest.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\cvtest.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1
Now I'm not able to load image. No fatal errors and nothing. It is considering the if statement and not loading anything.
Any suggestions?
You need to set up more than just your linker dependencies and it is very likely you have missed a step.
I would suggest following this tutorial as it will get you setup completely.

Error with OpenCV code - Invalid address specified to RtlFreeHeap

I have the following code, which runs fine:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
using namespace std;
using namespace cv;
void main() {
bool running = true;
cv::OrbFeatureDetector OrbDetector;
while (running) {
IplImage *newFrame = cvLoadImage("x1.jpg");
IplImage *newFrameBW = cvCreateImage(cvGetSize(newFrame), newFrame->depth, 1);
cvConvertImage(newFrame, newFrameBW);
vector<KeyPoint> KeyPoints;
}
}
However, adding the line:
OrbDetector.detect(newFrameBW, KeyPoints);
to the while loop results in the following error:
HEAP[Example 4.exe]: Invalid address specified to RtlFreeHeap( 006B0000, 02474D20 )
Example 4.exe has triggered a breakpoint.
I am sure there is nothing wrong with the code, as I have just seen it run successfully on someone elses machine. Is there anything non code related that could be causing this?
The problem is that the OpenCV version you are using does not deal OK with MCVS 2012. Is not a problem of code, as I had a similar one that include vectors and didn't work.
Take a look to this tutorial that will show you how to rebuild the OpenCV library and your code will work pretty well ;)
Here is the link:
http://answers.opencv.org/question/6495/visual-studio-2012-and-rtlfreeheap-error/

Resources