I am using this open source software for working with Sick Lidar Devices:
https://github.com/rhuitl/sicktoolbox/tree/master/trunk/c%2B%2B/drivers/lms5xx/sicklms5xx
and this documentation which provides information on the data:
https://www.sick.com/media/docs/7/27/927/Technical_information_Telegram_Listing_Ranging_sensors_LMS1xx_LMS5xx_TiM5xx_NAV310_LD_OEM15xx_LD_LRS36xx_en_IM0045927.PDF
I am trying to use the C++ implementation to parse already written files in the "CoLa B" format from SickLMS5xx, mentioned in said documentation. However, this toolbox appears to have been written to deal with the device directly, and not files that are outputted from it (like what I am working with).
It appears I can use the functions in the SickLMS5xxMessage (ParseMessage() etc.) to achieve what I want. I made a main method to interract with this class (and it's SickMessage() superclass) like so:
#include <iostream>
#include <fstream>
#include <boost/thread/thread.hpp>
#include "SickLMS5xxMessage.cc"
void run() {
SickLMS5xxMessage msg(uint8_t * const telegramFileBuffer[]);
std::ifstream telegramFile("MMS21_01");
if(telegramFile.is_open()) {
uint8_t telegramFileBuffer[msg.GetMessageLength()];
for(int i = 0; i < msg.GetMessageLength(); ++i) {
telegramFile >> telegramFileBuffer[i];
}
}
msg.Print();
}
int main (int argc, char** argv) {
run();
return (0);
}
But it doesn't appear to work properly, as it cannot recognise the GetMessageLength() and Print() functions from SickLMS5xxMessage, and gives me an unresolved method error?
Maybe it's an error with my C++ coding (because I come from a Java background and so C++ is still relatively new to me).
Any help will be appreciated though, thank you :)
Related
I've been a C++ developer since it arrived. All was on windows, and I haven't touched it in about 6 years.
Now I'm trying to get an old code-base working using VS Code on my Mac. I'm using clang++ with c++17.
This problem is vexing; I've seen many other posts with the same issue, but the problem always seemed to be something in the code.
Note: this code worked fine with C++11 on Windows.
To simplify, I copied the code to execute right at the top of main. Here is is:
ifstream file("assets/textures/blocks.txt", ios::in);
if( file.is_open() ) {
string s;
getline(file, s); // <-- This line causes the error.
cout << s << endl;
}
As this code worked elsewhere, I assume I've got a setup or environment problem and am looking for hints towards what to check on.
Thank you for any help!
An update:
Thank you. I paired the program down and tried a few things. Here's the deal:
If I leave all my files to be compiled, but replace main.cpp with the below code, the cout line generates the same exception.
If I cull all the unused files, the code works.
Something in some other file is somehow breaking the stream code. I'm clueless.
#include <iostream>
#include <istream>
using namespace std;
int main() // int argc, char** argv)
{
cout << "Hello World" << endl;
}
I should add: this is a GLFW 3D game engine app. It does not subclass or interact with any stream in any way other than the most basic file read/write operations.
Hi I am new to C++ and Code::Block
I am trying to make a simple code to test it, using strings.
when I compile the code there is no problem, but when I try to debug it, Code::Block gives me the following warning:
Cannot open file:
File:../../../../../src/gcc-4.9.2/libgcc/unwind-sjlj.c
Info: "Multiple information windows with the same message have been
supressed."
Image of the error FYI:
Part of the code that gives me an error.
inside main function
#include <iostream>
#include <string>
int main ()
{
std::mystring("What's wrong with strings");
return 0;
}
I realise that this error only occurs when I try to debug a string or a file containing a string.
Any help would be appreciated.
some other information that might help:
Code::Block 16.01
Compiler MinGW gcc4.9.2
Windows 7 Professional 32 bits SP1
First of all, to use strings you must include the file header string. And the name of the type string is..std::string, not std::mystring.
#include <string>
int main(int argc, char** argv)
{
std::string mystring("Nothing's wrong with strings");
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
string mystring = "Whats wrong with my string";
return 0;
}
If you write it in the following way, it should work.
It's safer to define strings like I showed it. It will be also easier for you if you add using namespace std in the beginning of every program if you are new to C++.
I've developed a C++ program which calculates a set of coordinates (x, y) within a loop. Every iteration I want to send the coordinate to Matlab for further processing, at a speed of about 25 times per second. I have a Matlab function that then takes this coordinate and uses it in real time; however, I haven't found an effective way of sending variables quickly from C++ to Matlab.
I've tried using the Matlab engine here: Passing Variable from C++ to Matlab (Workspace), except I want this variable to be used in the existing Matlab session and not simply run Matlab commands through C++.
I've also tried writing the C++ coordinate to a binary file and then reading this file in Matlab - this method is very fast but I'm having problems with the timing between both languages. Setting the Matlab code to an infinite loop reading the binary file, whilst running the C++ program writing the coordinate to the file, means that Matlab reads in a very strange order (ie. Matlab reads 15, 200, 70, 12 when I write the i values to file). I suspect this is due to poor timing between each program trying to open and either read or write the file.
C++:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
#include <iostream>
#include <math.h>
#include <fstream>
#include <stdio.h>
#include <Windows.h>
using namespace cv;
using namespace std;
int main()
{
int a = 0
for (int i = 0; i < 100000; ++i)
{
a = i;
std::ofstream ofile("foobar.bin", std::ios::binary);
ofile.write((char*) &a, sizeof(int));
ofile.close();
}
return 0;
}
Matlab:
A = fopen('foobar.bin');
fread(A)
fclose(A);
Is there a way to quickly and accurately send data between C++ and Matlab by writing to binary OR some other method which I can implement?
Thank you very much!
I cannot provide code samples because it has been a few years since I did this, but I know that you can use a create a COM object and interface it with matlab. Here is the link describing how to interface a COM object with matlab. http://www.mathworks.com/help/matlab/using-com-objects-in-matlab.html
I'm trying to use the Magick++ API (part of ImageMagick) for c++ and I've been looking around a while now and haven't seen that much documentation or examples on google. There's a lot of good documentation about it, but I can't find anything on how to use the ping() (not networking ping) function to return the size information of an image inside a c++ program. I've tried to make a blob object and use it like I've seen in the error.
I've seen a lot of the same general manual like:
http://web.mit.edu/graphics/share/ImageMagick/www/Magick++/Image.html#Image%20Attributes which is the same as http://www.imagemagick.org/Magick++/Image.html
I was looking at ping under "Image Manipulation Methods" and saw that it took a const Blob &blob_ as input. I tried doing the following, though I'm not really sure what I'm doing with ping(). I've got a lot of other stuff working, just can't figure this out.
#include <Magick++.h>
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
InitializeMagick(*argv);
Image master("horse.jpg");
Image second = master;
// tried creating a blob (Binary Large OBject) per the error
Blob blob;
master.write ( &blob);
cout << blob.ping(&blob) << endl;
// also tried
// cout << master.ping() << endl;
// cout << master.ping( &blob) << endl;
return 0
}
I can't even find much in the way of examples for Magick++ stuff or ping.
test3.cpp:15:26: note: candidates are:
In file included from /usr/include/ImageMagick/Magick++.h:10:0,
from test3.cpp:1:
/usr/include/ImageMagick/Magick++/Image.h:501:21: note: void Magick::Image::ping(const string&)
void ping ( const std::string &imageSpec_ );
^
/usr/include/ImageMagick/Magick++/Image.h:501:21: note: candidate expects 1 argument, 0 provided
/usr/include/ImageMagick/Magick++/Image.h:507:21: note: void Magick::Image::ping(const Magick::Blob&)
void ping ( const Blob &blob_ );
^
/usr/include/ImageMagick/Magick++/Image.h:507:21: note: candidate expects 1 argument, 0 provided
So I guess ping returns void which it didn't say in the manual. I'm not even sure how I'd get values from it. Should I just take a look at the source code? Does anyone know where I could find more reading on this? Or is anyone familiar with Magick++. I'm sorry for being so clueless but google just isn't turning up much in the way of results for me about this.
Any help would be much appreciated!
The return type of ping is 'void' because it almost does the same as read. The ping method reads all the meta-data from the image but stops processing the image as soon as the part that contains the 'pixel data' is reached. You cannot read the 'pixel data' but you can get the columns() and rows() after the image has been 'pinged'. This information is also available in the documentation of Magick++ that can be found here: http://www.imagemagick.org/Magick++/Image.html.
Below is an example of how you can use the ping method:
#include <Magick++.h>
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
InitializeMagick(*argv);
Image master;
master.ping("horse.jpg");
cout << master.columns() << "x" << master.rows() << endl;
return 0;
}
I have just started to use classes in C++. As a first object-oriented project, I want to program a character creator for a Pen and Paper game.
I have created the class structure including inheritance.
This is an example class:
#include "Characters.cpp"
#include "Fighter.cpp"
#include "Dwarf.cpp"
class FighterDwarf : public Characters, public Fighter, public Dwarf {
public:
string test = "Hello, I am a fighter dwarf!";
void testPrint() {
cout << test << endl;
}
FighterDwarf() {
}
};
And here is main:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
FighterDwarf fighterDwarf;
fighterDwarf.testPrint();
return 0;
}
In case it is not obvious, they are in two different files/Items. I don't think it is important but they are also in two different folders.
The problem is that I get the error message "Error: identifier "FighterDwarf" is undefined.
It is most likely a beginner mistake. I would guess that I must somehow declare "FighterDwarf" in the main file before I can create an instance of the class. If this is the case, I don't know how to do that with classes.
By they way, I know that there are a lot of people out there not liking multiple inheritance but I have chosen to use C++ and not Java because of that very feature.
SOLVED:
If I want to do everything in a single file, I need to do that in the header. Which I will, as some of the classes have some more code which I don't want to rewrite right now. Furthermore, I find it easier tow work with one file than two, at least at the beginning where I have more important things to mind. But I will split the classes up into two in my very next program. By the way, why is it so important to split classes up? Isn't it easier to work with one class?
It has nothing to do with classes. Your main.cpp file simply needs to #include the header file which declares and/or defines your FighterDwarf class.