ROS programming: move forward turtlebot - c++

I want to move the turtlebot.
Firstly i created package inside my catkin_ws
$ catkin_create_pkg /..package_name../ std_msgs rospy roscpp actionlib tf geometry_msgs move_base_msgs
Then i edit CMakeList
add_executable(myProgram src/main.cpp) and target_link_libraries(<executabletargetname>, ${catkin_LIBRARIES})
Thirdly, i run this command:
catkin_make
after compile:
[100%] Building CXX object ileri/CMakeFiles/gg.dir/src/gg.cpp.o
/home/turtlebot/catkin_ws/src/ileri/src/gg.cpp:18:2: error: ‘p’ does
not name a type /home/turtlebot/catkin_ws/src/ileri/src/gg.cpp:28:2:
error: expected unqualified-id before ‘try’
/home/turtlebot/catkin_ws/src/ileri/src/gg.cpp:31:3: error: expected
unqualified-id before ‘catch’ make[2]: *
[ileri/CMakeFiles/gg.dir/src/gg.cpp.o] Error 1 make[1]: *
[ileri/CMakeFiles/gg.dir/all] Error 2
.cpp :
`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);`
What do you think about these errors?
Are there problems about include? If you think so, which includes should i add this code?

In C++, statements go inside functions. It appears that your statement p.header.stamp = ros::Time(); appears outside a function.
Your program should also contain a int main() { } function. Try moving the statements inside the { }.

Related

How to properly configure meson / ninja / qt creator for recent c++ version?

I have tried to run a code which uses smart pointers recently. As the title says, I use Ninja (version 1.10.2), Meson (0.57.2) and Qt Creator 4.14.2.
I have the following meson.build :
project('RayTracerDemo',
'cpp',
version: '0.0.0',
default_options: [
'c_std=c2x',
'cpp_std=c++20',
'warning_level=3',
'optimization=3',
'werror=true'
]
)
includeDir = include_directories([])
sources = files([
'main.cpp'
])
headers = files([])
raytracer_exe = executable(
'RayTracerDemo',
sources: sources + headers,
include_directories: includeDir,
dependencies: []
)
But I still get the following error :
/~/programs/RayTracerDemo/main.cpp:189: error: ‘make_unique’ is not a member of ‘std’
../main.cpp: In function ‘void render(const std::vector<Sphere>&)’:
../main.cpp:189:52: error: ‘make_unique’ is not a member of ‘std’
189 | threads[height * width + width] = std::make_unique<std::thread>([&]() -> void
| ^~~~~~~~~~~
../main.cpp:189:52: note: ‘std::make_unique’ is only available from C++14 onwards
for the following lines :
threads[height * width + width] = std::make_unique<std::thread>([&]() -> void
{
float xx = (2 * ((x + 0.5) * invWidth) - 1) * angle * aspectratio;
float yy = (1 - 2 * ((y + 0.5) * invHeight)) * angle;
Vec3f raydir(xx, yy, -1);
raydir.normalize();
*pixel = trace(Vec3f(0), raydir, spheres, 0);
});
threads being a vector declared like so:
std::vector<std::unique_ptr<std::thread>> threads(height * width);
Qt Creator documentation says that some features aren't supported using Meson here, but this does not include compiler version issues.
It looks that everything is OK with meson options, you just forgot to add < memory> header (yes, error message is a bit confusing):
#include <memory>
...
Also, it could be due to setting c_std option for C++ compiler, since this option is for C compiler.
It's also possible that build directory is not (re)configured properly. To check currently configured options and flags you can with:
$ meson configure <build dir>
And to reconfigure:
$ meson setup --reconfigure <build dir>
BTW (it't nor related to question), this looks strange:
threads[height * width + width] =
as it overlaps the vector, shouldn't it be ? :
threads[invHeight * width + invWidth] =
TL;DR
This basic code :
#include <iostream>
#include <memory>
int main()
{
std::cout << "Hello World!" << std::endl;
std::unique_ptr<int> a = std::make_unique<int>();
return 0;
}
will not work. Compiler tells me C++ 14 or plus is required to use make_unique. The issue is that I already put "project('ThreadPool', 'cpp', default_options : ['cpp_std=c++17'])" in the meson.build file, but for some reason this file is just not taken in account by Qt Creator : checking what are the build settings, the C++ version chosen is C++11.

Error : Warning message:In system(cmd) : 'make' not found

I am working with R and C++. I am trying to include C++ in R , I have the following code:
install.packages('inline')
install.packages('Rcpp')
install.packages('rstan')
library('inline')
library('Rcpp')
library('rstan')
### # start with pure C/C++ function and assign the source code to
### # a variable which we call here includesrc
includesrc <- '
int fibonacci(const int x){
if (x == 0) return(0);
if (x == 1) return(1);
return fibonacci(x-1) + fibonacci(x-2);
}'
### # define the body of the C/C++ program
fibCppBody <- '
int x = Rcpp::as<int>(xs);
return Rcpp::wrap( fibonacci(x) );'
### # pass the above C/C++ function as an argument
### # to cxxfunction()
fibRcpp <- inline::cxxfunction(sig = signature(xs = "int"),
plugin = "Rcpp",
incl = includesrc,
body = fibCppBody)
sapply(1:10, fibRcpp, USE.NAMES = FALSE)
I ran this code which is supposed to include C++ code in R function , it is supposed to run (it is an example from here but it's not working for me.
And I got this error:
Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) :
Warning message:In system(cmd) : 'make' not found
Any idea? Thanks

Tkd widget not finding row and column options

I am trying to create a simple GUI application using tkd package and following code:
// modified from: https://github.com/nomad-software/tkd
import tkd.tkdapplication;
class Application : TkdApplication {
auto labellist = ["First", "Second", "Third", "Fourth", "Fifth", "Sixth", ];
override protected void initInterface() {
int ncol =0;
auto frame = new Frame(2, ReliefStyle.groove);
frame.pack(10);
foreach(lab; labellist){
auto label = new Label(frame, lab);
label.grid(row=nrow, column=0);
auto entry = new Entry(frame);
entry.grid(row=nrow, column=1);
nrow += 1;
}
auto exitButton = new Button(frame, "Exit").setCommand(&this.exitCommand).pack(10);
}
private void exitCommand(CommandArgs args) {
this.exit();
}
}
void main(string[] args){
auto app = new Application();
app.run();
}
However, it is giving following error:
$ dub run
Performing "debug" build using /usr/bin/dmd for x86_64.
x11 1.0.21: target for configuration "tcltk-import" is up to date.
tcltk 8.6.5: target for configuration "library" is up to date.
tkd 1.1.12: target for configuration "library" is up to date.
tkdgui ~master: building configuration "application"...
source/app.d(15,15): Error: undefined identifier row
source/app.d(15,25): Error: undefined identifier column
source/app.d(17,15): Error: undefined identifier row
source/app.d(17,25): Error: undefined identifier column
source/app.d(18,4): Error: undefined identifier nrow
/usr/bin/dmd failed with exit code 1.
Details about grid are mentioned here. Row and column are valid options to be entered.
Where is the problem and how can it be solved.
There are two issues in your code. Here's the first:
label.grid(row=nrow, column=0);
^^^^ ^^^^^^^
D does not support named parameters, which you're attempting to use. Instead you will need to use positional parameters:
label.grid(0, nrow);
FWIW, there are some proposals to add named parameters to D, but none are in the language as of now.
The second issue is nrow is not defined anywhere. Judging by the existence of ncol and the fact it's used nowhere, it seems you changed the code from dealing with columns to dealing with rows and did not change the name of ncol to nrow.

Exposing Rcpp modules

I am having some trouble working through the examples inside:
http://dirk.eddelbuettel.com/code/rcpp/Rcpp-modules.pdf
Specifically, section 2.2 where the author goes to expose a C++ class in RCPP and making it available to call in R.
I copied the code in to a new RCPP file and sourced it with no problem but got an error when I ran the following in R:
require(Rcpp)
require(inline)
unif_module <- Module( "unif_module", getDynLib(fx_unif ) )
The error:
Error in getDynLib(fx_unif) :
error in evaluating the argument 'x' in selecting a method for function 'getDynLib': Error: object 'fx_unif' not found
I then went though the other parts of the document where getDynLib is used and found that none of them initialized the arguments passed in to getDynLib. My question is what is fx_unif?
Thanks,
Update:
So following another example within the paper i tried:
inc = '
class Uniform {
public:
Uniform(double min_, double max_) : min(min_), max(max_) {}
NumericVector draw(int n) const {
RNGScope scope;
return runif( n, min, max );
}
double min, max;
};
double uniformRange( Uniform* w) {
return w->max - w->min;
}
RCPP_MODULE(unif_module) {
class_<Uniform>( "Uniform" )
.constructor<double,double>()
.field( "min", &Uniform::min )
.field( "max", &Uniform::max )
.method( "draw", &Uniform::draw )
.method( "range", &uniformRange )
;
}
'
fx_unif = cxxfunction(signature(), plugin="Rcpp", include=inc)
error:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! Warning message:
running command 'make -f "C:/PROGRA~1/R/R-32~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-32~1.2/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="filef4028245a6f.dll" WIN=64 TCLBIN=64 OBJECTS="filef4028245a6f.o"' had status 127
In addition: Warning message:
running command 'C:/PROGRA~1/R/R-32~1.2/bin/x64/R CMD SHLIB filef4028245a6f.cpp 2> filef4028245a6f.cpp.err.txt' had status 1

How can I fix the bug in ACADO Toolkit when using OnlineData variables?

As exposed in this topic in ACADO forum, there is a bug when you try to use OnlineData variables. In my case I am using C++ code instead of MATLAB interface and have 7 OnlineData variables. In the topic mentioned before they propose using the function SetNOD but using C++ I can't call the function. I cannot access the official forum in sourcefourge because they have some problems and I would appreciate your help.
The abbreviated code is:
include
define N 20 //Time intervals -- 51 states
int main{
USING_NAMESPACE_ACADO
//Variables
DifferentialState x, y, z, dx, dy, dz, roll, pitch, yaw, droll, dpitch, dyaw;
Control u1, u2, u3, u4;
OnlineData yaw0, obsx, obsy, obsz, obsrx, obsry, obsrz;
. . .
//Create Optimal Control Problem object
OCP ocp(t_start, t_end, N); //50 number of discretization intervals
//Fixing the bug
//Alternatives I tried
ocp.SetNOD(7);//Error A
//ocp.ModelContainer.SetNOD(7);//Error B
//Objective Function
ocp.minimizeLSQ(Q, h);
ocp.minimizeLSQEndTerm(QN, hN);
/* Constraints */
//Model constraint
ocp.setModel( f );
/* Export OCP */
OCPexport mpc( ocp );
...
if (mpc.exportCode( "path_qp_export_oases" ) != SUCCESSFUL_RETURN)
exit( EXIT_FAILURE );
return 0;
}
Error A:
/.../path_qp_generated_oases.cpp: In function ‘int main()’:
/.../path_qp_generated_oases.cpp:321:9: error: ‘class ACADO::OCP’ has no member named ‘SetNOD’
ocp.SetNOD(7);
make[2]: [.../CMakeFiles/my_examples_path_qp_generated_oases.dir/my_examples/path_qp_generated_oases.cpp.o] Error 1
make1: .../CMakeFiles/my_examples_path_qp_generated_oases.dir/all] Error 2
make: [all] Error 2
Error B:
/.../path_qp_generated_oases.cpp: In function ‘int main()’:
/.../path_qp_generated_oases.cpp:320:10: error: invalid use of ‘ACADO::ModelContainer::ModelContainer’
ocp.ModelContainer.SetNOD(7);
make2: [examples/CMakeFiles/my_examples_path_qp_generated_oases.dir/my_examples/path_qp_generated_oases.cpp.o] Error 1
make1:[examples/CMakeFiles/my_examples_path_qp_generated_oases.dir/all] Error 2
make: all Error 2
I am using the version of acado-master downloaded today:
Branch: master
Commit: 2cde3c748856ca16a4460e05149c1e5de362526f
Remote: acado/acado
Also have the same problem with acado-stable downloaded today:
~/ACADOtoolkit$ git rev-parse HEAD
e0cc4b058e1dc60c4e57f306dc7c7db41a582451
Thank you very much!!
I had the same problem.
There is currently a bug in ACADO Toolkit where it sometimes mis-counts or completely ignores the OnlineData variables that you use to define your problem.
The method is setNOD() with a lower-case "s".
Here's some example code which may help other people...
.
First make sure you install the latest ACADO source from github.
Define your non-linear optimization problem for ACADO like shown in the documentation:
DifferentialState x;
DifferentialState y;
Control u;
DifferentialEquation f;
f << dot(x) == 1.0*u;
f << dot(y) == 2.0*u;
OnlineData d0;
OnlineData d1;
OnlineData d2;
etc.
OCP ocp(0.0, steps*Ts, steps);
ocp.minimizeLSQ(W, h);
ocp.minimizeLSQEndTerm(W, h);
ocp.setModel(f);
ocp.setNOD(3);
OCPexport mpc(ocp);
You have to manually count your number of OnlineData and put that number into setNOD().
Then compile, generate the code, etc. like described in the documentation.
Now you can search through the code in the export directory to find these OnlineData variables that were previously ignored:
grep -R "od\[" *
Also note the test.c program won't set these variables.
In your own code, you will need to set their value.
If you have 3 OnlineData, you set them to be the same for each step along the control horizon like this:
for (int i = 0; i < (N + 1); ++i)
{
acadoVariables.od[i * NOD + 0] = 1.0;
acadoVariables.od[i * NOD + 1] = 9.0;
acadoVariables.od[i * NOD + 2] = 5.0;
}
Hope this helps!