File: test.cpp

package info (click to toggle)
mrpt 1%3A2.5.8%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 87,448 kB
  • sloc: cpp: 551,662; ansic: 38,702; xml: 3,914; python: 2,547; sh: 404; makefile: 237
file content (74 lines) | stat: -rw-r--r-- 2,142 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* +------------------------------------------------------------------------+
   |                     Mobile Robot Programming Toolkit (MRPT)            |
   |                          https://www.mrpt.org/                         |
   |                                                                        |
   | Copyright (c) 2005-2023, Individual contributors, see AUTHORS file     |
   | See: https://www.mrpt.org/Authors - All rights reserved.               |
   | Released under BSD License. See: https://www.mrpt.org/License          |
   +------------------------------------------------------------------------+ */

/*
   This example was contributed by Adrien Barral - Robopec (France)
*/

#include <mrpt/gui.h>
#include <mrpt/hwdrivers/CLMS100eth.h>
#include <mrpt/opengl/CPlanarLaserScan.h>  // [mrpt-maps]

#include <chrono>
#include <iostream>
#include <thread>

using namespace mrpt;
using namespace mrpt::obs;
using namespace mrpt::opengl;
using namespace mrpt::hwdrivers;
using namespace mrpt::gui;
using namespace std;

int main(int argc, char* argv[])
{
	if (argc < 3)
	{
		cout << "Usage : " << argv[0] << " <IP> <port> " << endl;
		return 0;
	}

	CLMS100Eth laser(string(argv[1]), atoi(argv[2]));
	laser.turnOn();

	bool isOutObs, hardwareError;
	CObservation2DRangeScan outObs;
	laser.doProcessSimple(isOutObs, outObs, hardwareError);

	CDisplayWindow3D win3D("Scan", 200, 200);

	COpenGLScene::Ptr ptr_scene = win3D.get3DSceneAndLock();

	opengl::CPlanarLaserScan::Ptr obj = opengl::CPlanarLaserScan::Create();
	obj->clear();
	obj->setColor(0, 0, 1);
	obj->setName("scan_LMS100");
	obj->setScan(outObs);
	ptr_scene->insert(obj);

	win3D.unlockAccess3DScene();
	win3D.forceRepaint();

	while (win3D.isOpen())
	{
		laser.doProcessSimple(isOutObs, outObs, hardwareError);

		ptr_scene = win3D.get3DSceneAndLock();
		opengl::CPlanarLaserScan::Ptr obj =
			std::dynamic_pointer_cast<opengl::CPlanarLaserScan>(
				ptr_scene->getByName("scan_LMS100"));
		obj->clear();
		obj->setScan(outObs);
		win3D.unlockAccess3DScene();
		win3D.forceRepaint();
		std::this_thread::sleep_for(20ms);
	}
	win3D.waitForKey();
	return 0;
}