turtlebot 2 kobuki base move forward - c++

I want to move the turtlebot.package name is "forward" Firstly i created package inside my catkin_ws
$ catkin_create_pkg forward std_msgs rospy roscpp actionlib tf geometry_msgs move_base_msgs
Then i edit CMakeList
add_executable(gg src/g.cpp) and target_link_libraries(gg, ${catkin_LIBRARIES})
Thirdly, i run these commands:
catkin_make
roscore
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:'pwd'
source ./devel/setup.bash
rosrun forward gg.cpp
gg.cpp:
#include <ros/ros.h>
#include <geometry_msgs/PoseWithCovarianceStamped.h>
#include <geometry_msgs/Twist.h>
#include <tf/transform_datatypes.h>
#include <stdio.h>
#include <math.h>
#include <tf/transform_listener.h>
#include <algorithm>
#include <geometry_msgs/PointStamped.h>
#include <std_msgs/Header.h>
#include <iostream>
int main(){
geometry_msgs::PointStamped p;
geometry_msgs::PointStamped p1;
p.header.stamp = ros::Time();
std::string frame1 = "/camera_depth_optical_frame";
p.header.frame_id = frame1.c_str();
p.point.x = 0;
p.point.y = 0;
p.point.z = 1; // 1 meter
// std::string frame = "map";
/*try
{
listener.transformPoint(frame,p,p1);
}catch(tf::TransformException& ex) { ROS_ERROR("exception while transforming..."); }
*/
// create message for move_base_simple/goal
geometry_msgs::PoseStamped msg;
msg.header.stamp = ros::Time();
std::string frame = "/map";
msg.header.frame_id = frame.c_str();
msg.pose.position = p1.point;
msg.pose.orientation = tf::createQuaternionMsgFromYaw(0.0);
//publisher.publish(msg);
}
errors:
[rosrun] Couldn't find executable named gg.cpp below /home/turtlebot/catkin_ws/src/forward
[rosrun] Found the following, but they're either not files,
[rosrun] or not executable:
[rosrun] /home/turtlebot/catkin_ws/src/forward/src/gg.cpp
what do you think about these errors?

You name your executable gg:
add_executable(gg src/g.cpp) and target_link_libraries(gg, ${catkin_LIBRARIES})
But try to run the target gg.cpp
rosrun forward gg.cpp
try
rosrun forward gg

Related

Clang CFE Compilation unable to read file

I'm trying to compile test files using the Clang Compiler FrontEnd with the following code:
#include <string>
#include <vector>
#include <memory>
#include <iostream>
#include <llvm/Support/Host.h>
#include <llvm/Support/Program.h>
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/VirtualFileSystem.h>
#include "clang/Basic/LLVM.h"
// #include <clang/Driver/ToolChain.h>
#include <clang/Driver/Driver.h>
#include <clang/Basic/Diagnostic.h>
#include <clang/Basic/DiagnosticIDs.h>
#include <clang/Basic/DiagnosticOptions.h>
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Driver/Compilation.h>
using namespace clang::driver;
using namespace clang;
std::string pwd = "/home/arch/Documents/CFE/Examples/Compile/";
std::string target_executable = pwd + "target";
int main()
{
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> DE(clang::CompilerInstance::createDiagnostics(new DiagnosticOptions));
llvm::ErrorOr<std::string> clangPath = llvm::sys::findProgramByName("clang++");
Driver D(StringRef(clangPath.get().c_str()), llvm::sys::getDefaultTargetTriple(), *DE, "clang LLVM compiler", InMemoryFileSystem);
// D.setCheckInputsExist(false);
std::vector<const char *> args;
args.push_back(clangPath.get().c_str());
args.push_back((target_executable + ".cpp").c_str());
args.push_back("-cl-std=clc++2021");
args.push_back(("-o " + target_executable + ".spv").c_str());
ArrayRef<const char *> compileArgs(args);
std::unique_ptr<Compilation> C(D.BuildCompilation(compileArgs));
assert(C > 0);
bool CallbackHasCalled = false;
C->setPostCallback(
[&](const Command &Cmd, int Ret)
{ std::cout << "postCallback return value: " << Ret << std::endl;
CallbackHasCalled = true; });
const JobList &Jobs = C->getJobs();
auto &CmdCompile = Jobs.getJobs().front();
const Command *FailingCmd = nullptr;
assert(C->ExecuteCommand(*CmdCompile, FailingCmd));
assert(FailingCmd);
}
With the following CMakeLists.txt:
cmake_minimum_required(VERSION 3.23)
project("CLANG_CFE")
find_package(Clang REQUIRED)
target_precompile_headers(clangBasic PUBLIC)
execute_process(COMMAND clang-config --libs OUTPUT_VARIABLE LLVM_LIBRARIES)
execute_process(COMMAND clang-config --cxx-flags OUTPUT_VARIABLE LLVM_CXX_FLAGS)
add_executable(compile_example main.cpp)
target_compile_options(compile_example PRIVATE ${LLVM_CXX_FLAGS})
set(CLANG_LIBS clangBasic clangDriver clangFrontend)
target_link_libraries(compile_example PRIVATE ${CLANG_LIBS} LLVMSupport)
The code compiles fine but fails to read the target_executable, resulting in the following error:
error: no such file or directory: 'P�ZUU'
Is this a read/write permission-error?
It turned out to be a problem with the usage of absolute paths, the method Driver::DiagnoseInputExistence automatically rejects the file path if it starts with "/".
Using a relative filepath solved this issue.

Why does Ubuntu throw an I/O error randomly?

I have got a PC/104 (its OS is Ubuntu 16.04 with kernel 4.19.89 xenomai3) that is connected to two motors via two CAN adapters. Few days back, I wrote some simple code to open my PC/104's CAN ports using the libpcanfd library.
My project folder observes the following hierarchy:
io_error_debug
build
include (empty)
src
CMakeLists.txt
main.cpp
CMakeLists.txt
CMakeLists.txt at /root:
cmake_minimum_required(VERSION 2.6)
project(io_error_debug)
include_directories(${PROJECT_SOURCE_DIR}/include) # add before adding subdirectory
add_subdirectory (src)
add_executable(io_error_debug src/main.cpp)
target_link_libraries(io_error_debug /usr/lib/libpcanfd.so # pcan
"-Wl,--no-as-needed -Wl,#/usr/xenomai/lib/cobalt.wrappers -Wl,#/usr/xenomai /lib/modechk.wrappers /usr/xenomai/lib/xenomai/bootstrap-pic.o -L/usr/xenomai/lib -lcobalt -lmodechk -lpthread -lrt"
)
CMakeLists.txt under /src:
aux_source_directory(. SRC_LIST)
main.cpp:
#include <sys/time.h>
#include <lcm/lcm_coretypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <inttypes.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <pthread.h>
#include <errno.h>
#include <sys/syscall.h>
#include <pcanfd.h>
#include <libpcanfd.h>
#include <cmath>
#include <iostream>
int main(int argc, char *argv[]){
int fd;
fd = pcanfd_open("/dev/pcan0", OFD_BITRATE | PCANFD_INIT_STD_MSG_ONLY | OFD_NONBLOCKING, 1000000);
if (fd < 0)
{
printf("Open operation failed with err %d on port no. %s\n",fd, "/dev/pcan0");
exit(1);
}else{
printf("Open succeeded with return value %d on port no. %s\n",fd, "/dev/pcan0");
}
}
The code compiles and executes well when the motors are switched on. However, when I switch off the motors and switch them on again, I get the following error after executing my code:
Open operation failed with err -5 on port no. /dev/pcan0
Furthermore, dmesg shows these suspicious error lines when I run my code:
[16900.914132] pcan: set_normal_mode(CAN1) failed (err -5)
[16900.914162] pcan: can't open device hardware itself (err -5)!
The documentation states that -5 is an errno error. Therefore, I looked for the value -5 in this errno errors' list and I found out that it isI/O error. Interestingly, when I switch off the PC/104 and execute my code, the program runs well. Nevertheless, when I repeat the aforementioned operation (i.e., switching off and on the motors) I will encounter the same error. I do not understand what is happening.

Error while trying to build stasm minimal

I do not have experience on C++. And I have to use stasm for face detection. I'm traying to build the minimal example. On page 4 of this tutorial is possible to know what is necessary to make it work. But I'm these two errors:
g++ -Wno-deprecated -o teste minimal.cpp `pkg-config opencv --cflags --libs` -I/home/caaarlos/workspace/StasmDesbravando/stasm
In file included from minimal.cpp:46:0:
/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/pinstart.cpp: In function ‘void stasm::CopyPoint(stasm::Shape&, const Shape&, int, int)’:
/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/pinstart.cpp:138:13: error: redefinition of ‘void stasm::CopyPoint(stasm::Shape&, const Shape&, int, int)’
static void CopyPoint( // copy a point from oldshape to shape
^
In file included from minimal.cpp:37:0:
/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/convshape.cpp:9:13: error: ‘void stasm::CopyPoint(stasm::Shape&, const Shape&, int, int)’ previously defined here
static void CopyPoint( // copy a point from oldshape to shape
This is my code:
// minimal.cpp: Display the landmarks of a face in an image.
// This demonstrates stasm_search_single.
#include <stdio.h>
#include <stdlib.h>
#include "opencv/highgui.h"
#include <opencv/cv.h>
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/stasm_lib.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/asm.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/atface.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/basedesc.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/classicdesc.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/convshape.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/err.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/eyedet.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/eyedist.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/faceroi.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/hat.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/hatdesc.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/landmarks.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/landtab_muct77.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/misc.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/pinstart.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/print.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/shape17.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/shapehacks.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/shapemod.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/startshape.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/stasm.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/stasm_landmarks.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/stasm_lib.h"
//#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/stasm_lib_ext.h"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/asm.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/classicdesc.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/convshape.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/err.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/eyedet.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/eyedist.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/faceroi.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/hat.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/hatdesc.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/landmarks.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/misc.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/pinstart.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/print.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/shape17.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/shapehacks.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/shapemod.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/startshape.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/stasm.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/stasm_lib.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/MOD_1/facedet.h"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/MOD_1/initasm.h"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/MOD_1/initasm.cpp"
#include "/home/caaarlos/Documentos/TCC/stasm4.1.0/stasm/MOD_1/facedet.cpp"
using namespace cv;
using namespace std;
int main()
{
static const char* const path = "../data/testface.jpg";
cv::Mat_<unsigned char> img(cv::imread(path, CV_LOAD_IMAGE_GRAYSCALE));
if (!img.data)
{
printf("Cannot load %s\n", path);
exit(1);
}
int foundface;
float landmarks[2 * stasm_NLANDMARKS]; // x,y coords (note the 2)
if (!stasm_search_single(&foundface, landmarks,
(const char*)img.data, img.cols, img.rows, path, "../data"))
{
printf("Error in stasm_search_single: %s\n", stasm_lasterr());
exit(1);
}
if (!foundface)
printf("No face found in %s\n", path);
else
{
// draw the landmarks on the image as white dots (image is monochrome)
stasm_force_points_into_image(landmarks, img.cols, img.rows);
for (int i = 0; i < stasm_NLANDMARKS; i++)
img(cvRound(landmarks[i*2+1]), cvRound(landmarks[i*2])) = 255;
}
cv::imwrite("minimal.bmp", img);
cv::imshow("stasm minimal", img);
cv::waitKey();
return 0;
}
I'm compiling my code in thi way:
g++ -Wno-deprecated -o teste minimal.cpp `pkg-config opencv --cflags --libs` -I/home/caaarlos/workspace/StasmDesbravando/stasm
What am I doing wrong? Can someone help me?
Thanks.
I've found a solution for this problem. If somebody has a problem like mine, you should enter on this site and use the CMakeList.txt and CMake to build Stasm. If you get any error you can try the intructions provides o the readme.

OpenCV FeatureDetector is not initialized

I am trying to create a class where I shall find KeyPoints in an image. However, I get a ridiculous error I cannot figure out how to solve.
The problem is now that
this->detector
is zero, so it is for some reason not initialized properly. I have searched on google but I haven't found anything.
My headerfile looks as follows
/*
* FindKeyPoints.h
*
* Created on: Jan 21, 2015
* Author: erikbylow
*/
#ifndef FINDKEYPOINTS_H_
#define FINDKEYPOINTS_H_
#include <vector>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv/cxcore.h>
using namespace std;
class FindKeyPoints {
private:
// Create vector of KeyPoints to store the detected keypoint in
vector<cv::KeyPoint> keyPointsOld;
vector<cv::KeyPoint> keyPointsNew;
// Threshold for similarity
const int THRESHOLD = 10;
// Instance(?) DescriptionExtractor and descriptor
cv::Ptr<cv::DescriptorExtractor> descriptionExtractor;
cv::Ptr<cv::FeatureDetector> detector;
public:
FindKeyPoints(const string &METHOD);
virtual ~FindKeyPoints();
void detectKeypoints(cv::Mat& imgNew, cv::Mat& imgOld);
};
#endif /* FINDKEYPOINTS_H_ */
And constructor looks as
FindKeyPoints::FindKeyPoints(const string &METHOD) {
cout<<METHOD<<endl;
cv::initModule_features2d();
this->detector = cv::FeatureDetector::create("SURF");
//this->descriptionExtractor = cv::DescriptorExtractor::create(METHOD);
}
and a function I will use looks as:
// Input: The new image and the old image. Find Keypoints and extract the descriptors.
void FindKeyPoints::detectKeypoints(cv::Mat& imgNew,
cv::Mat& imgOld) {
if (this->detector == 0){
cout<<"Hej"<<endl;
}
// this->detector->detect(imgNew, keyPointsNew);
// this->detector->detect(imgOld, keyPointsOld);
}
I use cmake and (part of) my CMakeLists.txt looks like:
TARGET_LINK_LIBRARIES(${PROJECT_NAME} groundtruth ${OpenCV_LIBS} ${QT_LIBRARIES}
${QGLViewer_LIBRARIES} ${OPENGL_gl_LIBRARY} GL
glut)
Can it be that
${OpenCV_LIBS}
does not include libopencv_nonfree.so ?
Regards
I suspect the error is that I had only included
opencv2/nonfree/features2d.hpp
and not also
opencv2/nonfree/nonfree.hpp.

embedding python in c++

I created a VCL Application in c++, borland. In my project there is a file where I have implemented embedded python in the methods defined in the same(my application contains a button which calls the method in which embedded python is implemented). when I compile, my build is successful. but when I run my application, and click on the button it shows the run time error : "Access violation at address 1E091375 in module 'PYTHON25.DLL'. Read of address 00000004" . please help.
I have never used Python before.
my program:
#pragma hdrstop
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "Python.h"
#include "Unit1.h"
#include "Unit2.h"
#pragma link "python25_bcpp.lib"
//---------------------------------------------------------------------------
#pragma package(smart_init)
bool callHelloWorld(int intVal)
{
char fName[] = "Hello"; //file name
char cFunc[] = "hello"; //method name
char *pfName, *pcFunc;
PyObject *pName, *pModule, *pDict, *pFunc ;
pfName = fName;
pcFunc = cFunc;
Py_Initialize();
pName = PyString_FromString(pfName);
pModule = PyImport_Import(pName);
pDict = PyModule_GetDict(pModule);
pFunc = PyDict_GetItemString(pDict, pcFunc);
if (PyCallable_Check(pFunc))
{
PyObject_CallObject(pFunc, NULL);
} else
{
PyErr_Print();
}
// Py_DECREF(pModule);
// Py_DECREF(pName);
Py_Finalize();
return 0;
}
Check the return values of PyImport_Import (is the module in the search path?) and PyDict_GetItemString.
If that doesn't help put some trace messages in your app to see where it crashes.
This works for me:
Just delete Py_Finalize()
I read in another site that Py_Finalize has some problems in specific cases such as threading.