Skip to content
Extraits de code Groupes Projets
Valider b6db3c83 rédigé par Diego de Bernard de Fauconval's avatar Diego de Bernard de Fauconval
Parcourir les fichiers

ajout lib sdk

parent c3db3ad5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 1040 ajouts et 0 suppression
#include "../rplidar_sdk/sdk/sdk/include/rplidar.h"
#include "../rplidar_sdk/sdk/sdk/include/rplidar_driver.h"
......@@ -18,6 +18,9 @@ spi : compile_spi
encoder : compile_encoder
sudo ./encoder
lidar : compile_lidar
sudo ./LIDAR
# compilations
compile_switch :
g++ -o switch switch.cpp -lwiringPi
......@@ -37,6 +40,9 @@ compile_spi :
compile_encoder :
g++ -o encoder encoder.cpp -l wiringPi
compile_lidar :
g++ -o LIDAR LIDAR.cpp -l wiringPi
.PHONY : clean
clean :
rm -rf switch motor led i2c uart spi encoder
.vs
*.sdf
sdk/obj
**/ipch
Copyright (c) 2009 - 2014 RoboPeak Team (http://www.robopeak.com)
Copyright (c) 2014 - 2018 Shanghai Slamtec Co., Ltd. (http://www.slamtec.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Slamtec RPLIDAR Public SDK for C++
==================================
Introduction
------------
Slamtec RPLIDAR(https://www.slamtec.com/lidar/a3) series is a set of high-performance and low-cost LIDAR(https://en.wikipedia.org/wiki/Lidar) sensors, which is the perfect sensor of 2D SLAM, 3D reconstruction, multi-touch, and safety applications.
This is the public SDK of RPLIDAR products in C++, and open-sourced under GPLv3 license.
If you are using ROS (Robot Operating System), please use our open-source ROS node directly: https://github.com/slamtec/rplidar_ros .
If you are just evaluating RPLIDAR, you can use Slamtec RoboStudio(https://www.slamtec.com/robostudio) (currently only support Windows) to do the evaulation.
License
-------
The SDK itself is licensed under BSD 2-clause license.
The demo applications are licensed under GPLv3 license.
Release Notes
-------------
* [v1.12.0](https://github.com/slamtec/rplidar_sdk/blob/master/docs/ReleaseNote.v1.12.0.md)
* [v1.11.0](https://github.com/slamtec/rplidar_sdk/blob/master/docs/ReleaseNote.v1.11.0.md)
* [v1.10.0](https://github.com/slamtec/rplidar_sdk/blob/master/docs/ReleaseNote.v1.10.0.md)
* [v1.9.1](https://github.com/slamtec/rplidar_sdk/blob/master/docs/ReleaseNote.v1.9.1.md)
* [v1.9.0](https://github.com/slamtec/rplidar_sdk/blob/master/docs/ReleaseNote.v1.9.0.md)
* [v1.8.1](https://github.com/slamtec/rplidar_sdk/blob/master/docs/ReleaseNote.v1.8.1.md)
* [v1.8.0](https://github.com/slamtec/rplidar_sdk/blob/master/docs/ReleaseNote.v1.8.0.md)
Supported Platforms
-------------------
RPLIDAR SDK supports Windows, macOS and Linux by using Visual Studio 2010 projects and Makefile.
| LIDAR Model \ Platform | Windows | macOS | Linux |
| ---------------------- | ------- | ----- | ------|
| A1 | Yes | Yes | Yes |
| A2 | Yes | Yes | Yes |
| A3 | Yes | Yes | Yes |
Quick Start
-----------
### On Windows
If you have Microsoft Visual Studio 2010 installed, just open sdk/workspaces/vc10/sdk_and_demo.sln, and compile. It contains the library as well as some demo applications.
### On macOS and Linux
Please make sure you have make and g++ installed, and then just invoke make in the root directory, you can get the compiled result at `output/$PLATFORM/$SCHEME`, such as `output/Linux/Release`.
make
The Makefile compiles Release build by default, and you can also use `make DEBUG=1` to compile Debug builds.
Cross Compile
-------------
The Makefile system used by RPLIDAR public SDK support cross compiling.
The following command can be used to cross compile the SDK for `arm-linux-gnueabihf` targets:
CROSS_COMPILE_PREFIX=arm-linux-gnueabihf ./cross_compile.sh
Demo Applications
-----------------
RPLIDAR public SDK includes some simple demos to do fast evaulation:
### ultra_simple
This demo application simply connects to an RPLIDAR device and outputs the scan data to the console.
ultra_simple <serial_port_device>
For instance:
ultra_simple \\.\COM11 # on Windows
ultra_simple /dev/ttyUSB0
> Note: Usually you need root privilege to access tty devices under Linux. To eliminate this limitation, please add `KERNEL=="ttyUSB*", MODE="0666"` to the configuration of udev, and reboot.
### simple_grabber
This application demonstrates the process of getting RPLIDAR’s serial number, firmware version and healthy status after connecting the PC and RPLIDAR. Then the demo application grabs two round of scan data and shows the range data as histogram in the command line mode.
### frame_grabber (Legacy)
This demo application can show real-time laser scans in the GUI and is only available on Windows platform.
We have stopped the development of this demo application, please use Slamtec RoboStudio (https://www.slamtec.com/robostudio) instead.
SDK Usage
---------
> For detailed documents of RPLIDAR SDK, please refer to our user manual: https://download.slamtec.com/api/download/rplidar-sdk-manual/1.0?lang=en
### Include Header
#include <rplidar.h>
Usually you only need to include this file to get all functions of RPLIDAR SDK.
### SDK Initialization and Termination
There are two static interfaces to create and dispose RPLIDAR driver instance. Each RPLIDAR driver instance can only be used to communicate with one RPLIDAR device. You can freely allocate arbitrary number of RPLIDAR driver instances to communicate with multiple RPLIDAR devices concurrently.
/// Create an RPLIDAR Driver Instance
/// This interface should be invoked first before any other operations
///
/// \param drivertype the connection type used by the driver.
static RPlidarDriver * RPlidarDriver::CreateDriver(_u32 drivertype = DRIVER_TYPE_SERIALPORT);
/// Dispose the RPLIDAR Driver Instance specified by the drv parameter
/// Applications should invoke this interface when the driver instance is no longer used in order to free memory
static void RPlidarDriver::DisposeDriver(RPlidarDriver * drv);
For example:
#include <rplidar.h>
int main(int argc, char* argv)
{
RPlidarDriver* lidar = RPlidarDriver::CreateDriver();
// TODO
RPlidarDriver::DisposeDriver(lidar);
}
### Connect to RPLIDAR
After creating an RPlidarDriver instance, you can use `connect()` method to connect to a serial port:
u_result res = lidar->connect("/dev/ttyUSB0", 115200);
if (IS_OK(res))
{
// TODO
lidar->disconnect();
}
else
{
fprintf(stderr, "Failed to connect to LIDAR %08x\r\n", res);
}
### Start spinning motor
The LIDAR is not spinning by default. Method `startMotor()` is used to start this motor.
> For RPLIDAR A1 series, this method will enable DTR signal to make the motor rotate; for A2 and A3 serieses, the method will make the accessory board to output a PWM signal to MOTOR_PWM pin.
lidar->startMotor();
// TODO
lidar->stopMotor();
### Start scan
Slamtec RPLIDAR support different scan modes for compatibility and performance. Since RPLIDAR SDK 1.6.0, a new API `getAllSupportedScanModes()` has been added to the SDK.
std::vector<RplidarScanMode> scanModes;
lidar->getAllSupportedScanModes(scanModes);
You can pick a scan mode from this list like this:
lidar->startScanExpress(false, scanModes[0].id);
Or you can just use the typical scan mode of RPLIDAR like this:
RplidarScanMode scanMode;
lidar->startScan(false, true, 0, &scanMode);
### Grab scan data
When the RPLIDAR is scanning, you can use `grabScanData()` and `grabScanDataHq()` API to fetch one frame of scan. The difference between `grabScanData()` and `grabScanDataHq()` is the latter one support distances farther than 16.383m, which is required for RPLIDAR A2M6-R4 and RPLIDAR A3 series.
> The `grabScanDataHq()` API is backward compatible with old LIDAR models and old firmwares. So we recommend always using this API, and use `grabScanData()` only for compatibility.
rplidar_response_measurement_node_hq_t nodes[8192];
size_t nodeCount = sizeof(nodes)/sizeof(rplidar_response_measurement_node_hq_t);
res = lidar->grabScanDataHq(nodes, nodeCount);
if (IS_FAIL(res))
{
// failed to get scan data
}
### Defination of data structure `rplidar_response_measurement_node_hq_t`
The defination of `rplidar_response_measurement_node_hq_t` is:
#if defined(_WIN32)
#pragma pack(1)
#endif
typedef struct rplidar_response_measurement_node_hq_t {
_u16 angle_z_q14;
_u32 dist_mm_q2;
_u8 quality;
_u8 flag;
} __attribute__((packed)) rplidar_response_measurement_node_hq_t;
#if defined(_WIN32)
#pragma pack()
#endif
The definiton of each fields are:
| Field | Data Type | Comments |
| ----------- | --------- | -----------------------------------------------------|
| angle_z_q14 | u16_z_q14 | It is a fix-point angle desciption in z presentation |
| dist_mm_q2 | u32_q2 | Distance in millimeter of fixed point values |
| quality | u8 | Measurement quality (0 ~ 255) |
| flag | u8 | Flags, current only one bit used: `RPLIDAR_RESP_MEASUREMENT_SYNCBIT` |
For example:
float angle_in_degrees = node.angle_z_q14 * 90.f / (1 << 14);
float distance_in_meters = node.dist_mm_q2 / 1000.f / (1 << 2);
Contact Slamtec
---------------
If you have any extra questions, please feel free to contact us at our support email:
support AT slamtec DOT com
\ No newline at end of file
RPLIDAR Public SDK v1.10.0 Release Note
======================================
- [new feature] support Rplidar S1
RPLIDAR Public SDK v1.11.0 Release Note
======================================
- [new feature] support 256000 baudrate on macOS
- [improvement] better support for S1 in framegrabber
- [improvement] default tty device is set to /dev/tty.SLAB_USBtoUART instead of /dev/ttyUSB0
RPLIDAR Public SDK v1.12.0 Release Note
======================================
- [new feature] support to set spin speed for S1 in rplidar_driver and framegrabber
- [improvement] use grabScanDataHq instead of grabScanData in ultra_simple
\ No newline at end of file
RPLIDAR Public SDK v1.8.0 Release Note
======================================
- [new feature] support baudrate 57600
- [bugfix] TCP channel doesn't work
- [improvement] Print warning messages when deprecated APIs are called
RPLIDAR Public SDK v1.8.1 Release Note
======================================
- [new feature] support baudrate 1382400
- [improvement] imporve angular accuracy for ultra capsuled scan points
RPLIDAR Public SDK v1.9.0 Release Note
======================================
- [new feature] support HQ scan response
RPLIDAR Public SDK v1.9.1 Release Note
======================================
- [improvement] updated license declarations of RPLIDAR Public SDK
#/*
# * RPLIDAR SDK
# *
# * Copyright (c) 2009 - 2014 RoboPeak Team
# * http://www.robopeak.com
# * Copyright (c) 2014 - 2018 Shanghai Slamtec Co., Ltd.
# * http://www.slamtec.com
# *
# */
#/*
# * Redistribution and use in source and binary forms, with or without
# * modification, are permitted provided that the following conditions are met:
# *
# * 1. Redistributions of source code must retain the above copyright notice,
# * this list of conditions and the following disclaimer.
# *
# * 2. Redistributions in binary form must reproduce the above copyright notice,
# * this list of conditions and the following disclaimer in the documentation
# * and/or other materials provided with the distribution.
# *
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# *
# */
HOME_TREE := .
MAKE_TARGETS := sdk app
include $(HOME_TREE)/mak_def.inc
all: make_subs
include $(HOME_TREE)/mak_common.inc
clean: make_subs
#/*
# * Copyright (C) 2014 RoboPeak
# * Copyright (C) 2014 - 2019 Shanghai Slamtec Co., Ltd.
# *
# * This program is free software: you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation, either version 3 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program. If not, see <http://www.gnu.org/licenses/>.
# *
# */
#
HOME_TREE := ../
MAKE_TARGETS := simple_grabber ultra_simple
include $(HOME_TREE)/mak_def.inc
all: make_subs
include $(HOME_TREE)/mak_common.inc
clean: make_subs
/*
* RPLIDAR
* Win32 Demo Application
*
* Copyright (c) 2009 - 2014 RoboPeak Team
* http://www.robopeak.com
* Copyright (c) 2014 - 2019 Shanghai Slamtec Co., Ltd.
* http://www.slamtec.com
*
*/
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// aboutdlg.cpp : implementation of the CAboutDlg class
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "aboutdlg.h"
LRESULT CAboutDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CenterWindow(GetParent());
return TRUE;
}
LRESULT CAboutDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
EndDialog(wID);
return 0;
}
/*
* RPLIDAR
* Win32 Demo Application
*
* Copyright (c) 2009 - 2014 RoboPeak Team
* http://www.robopeak.com
* Copyright (c) 2014 - 2019 Shanghai Slamtec Co., Ltd.
* http://www.slamtec.com
*
*/
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// aboutdlg.h : interface of the CAboutDlg class
//
/////////////////////////////////////////////////////////////////////////////
#pragma once
class CAboutDlg : public CDialogImpl<CAboutDlg>
{
public:
enum { IDD = IDD_ABOUTBOX };
BEGIN_MSG_MAP(CAboutDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(IDOK, OnCloseCmd)
COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)
END_MSG_MAP()
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
};
/*
* RPLIDAR
* Win32 Demo Application
*
* Copyright (c) 2016 - 2018 Shanghai Slamtec Co., Ltd.
* http://www.slamtec.com
*
*/
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// FreqSetDlg.cpp : implementation of the CFreqSetDlg class
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "drvlogic\lidarmgr.h"
#include "FreqSetDlg.h"
CFreqSetDlg::CFreqSetDlg()
{
}
LRESULT CFreqSetDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CenterWindow(GetParent());
this->DoDataExchange();
m_sld_freq.SetRange(0,MAX_MOTOR_PWM);
m_sld_freq.SetTicFreq(1);
m_sld_freq.SetPos(DEFAULT_MOTOR_PWM);
CString str;
str.Format("%d", DEFAULT_MOTOR_PWM);
m_edt_freq.SetWindowTextA(str);
return TRUE;
}
LRESULT CFreqSetDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
char data[10];
m_edt_freq.GetWindowTextA(data,_countof(data));
_u16 pwm = atoi(data);
if (pwm >= MAX_MOTOR_PWM) {
pwm = MAX_MOTOR_PWM;
CString str;
str.Format("%d", pwm);
m_edt_freq.SetWindowTextA(str);
}
m_sld_freq.SetPos(pwm);
bool isTof;
LidarMgr::GetInstance().lidar_drv->checkIfTofLidar(isTof);
if (isTof) {
_u16 rpm = pwm;
LidarMgr::GetInstance().lidar_drv->setLidarSpinSpeed(pwm);
}else{
LidarMgr::GetInstance().lidar_drv->setMotorPWM(pwm);
}
return 0;
}
LRESULT CFreqSetDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
EndDialog(wID);
return 0;
}
void CFreqSetDlg::OnHScroll(UINT nSBCode, LPARAM /*lParam*/, CScrollBar pScrollBar)
{
if (pScrollBar.m_hWnd == m_sld_freq.m_hWnd)
{
int realPos = m_sld_freq.GetPos();
CString str;
str.Format("%d", realPos);
m_edt_freq.SetWindowTextA(str);
LidarMgr::GetInstance().lidar_drv->setMotorPWM(realPos);
}
}
/*
* RPLIDAR
* Win32 Demo Application
*
* Copyright (c) 2016 - 2018 Shanghai Slamtec Co., Ltd.
* http://www.slamtec.com
*
*/
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// FreqSetDlg.h : interface of the CFreqSetDlg class
//
/////////////////////////////////////////////////////////////////////////////
#pragma once
class CFreqSetDlg : public CDialogImpl<CFreqSetDlg>,
public CWinDataExchange<CFreqSetDlg>
{
public:
CFreqSetDlg();
enum { IDD = IDD_DLG_SETFREQ };
BEGIN_MSG_MAP(CFreqSetDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(IDOK, OnOK)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
MSG_WM_HSCROLL(OnHScroll)
END_MSG_MAP()
BEGIN_DDX_MAP(CFreqSetDlg)
DDX_CONTROL_HANDLE(IDC_SLIDER_FREQ, m_sld_freq)
DDX_CONTROL_HANDLE(IDC_EDIT_FREQ, m_edt_freq)
END_DDX_MAP();
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
void OnHScroll(UINT nSBCode, LPARAM /*lParam*/, CScrollBar pScrollBar);
CTrackBarCtrl m_sld_freq;
CEdit m_edt_freq;
protected:
public:
LRESULT OnBnClickedOk(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// VisualFC AppWizard will insert additional declarations immediately before the previous line.
/*
* RPLIDAR
* Win32 Demo Application
*
* Copyright (c) 2009 - 2014 RoboPeak Team
* http://www.robopeak.com
* Copyright (c) 2014 - 2019 Shanghai Slamtec Co., Ltd.
* http://www.slamtec.com
*
*/
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// MainFrm.cpp : implmentation of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "aboutdlg.h"
#include "scanView.h"
#include "MainFrm.h"
#include "FreqSetDlg.h"
const int REFRESEH_TIMER = 0x800;
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
//intercept dynamic created menu item msg firstly
if(pMsg->wParam >= scanModeMenuRecBegin_ && pMsg->wParam < scanModeMenuRecBegin_ + modeVec_.size())
{
scanModeSelect(pMsg->wParam);
}
if(CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg))
return TRUE;
if (m_hWndClient == m_scanview.m_hWnd){
return m_scanview.PreTranslateMessage(pMsg);
} else {
return FALSE;
}
}
BOOL CMainFrame::OnIdle()
{
UIUpdateToolBar();
return FALSE;
}
LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// create command bar window
HWND hWndCmdBar = m_CmdBar.Create(m_hWnd, rcDefault, NULL, ATL_SIMPLE_CMDBAR_PANE_STYLE);
// attach menu
m_CmdBar.AttachMenu(GetMenu());
// load command bar images
m_CmdBar.LoadImages(IDR_MAINFRAME);
// remove old menu
SetMenu(NULL);
HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, IDR_MAINFRAME, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);
CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
AddSimpleReBarBand(hWndCmdBar);
AddSimpleReBarBand(hWndToolBar, NULL, TRUE);
CreateSimpleStatusBar();
m_hWndClient =m_scanview.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
UIAddToolBar(hWndToolBar);
UISetCheck(ID_VIEW_TOOLBAR, 1);
UISetCheck(ID_VIEW_STATUS_BAR, 1);
// register object for message filtering and idle updates
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->AddMessageFilter(this);
pLoop->AddIdleHandler(this);
workingMode = WORKING_MODE_IDLE;
LidarMgr::GetInstance().lidar_drv->getDeviceInfo(devInfo);
//get scan mode information
modeVec_.clear();
LidarMgr::GetInstance().lidar_drv->getAllSupportedScanModes(modeVec_);
_u16 typicalMode;
LidarMgr::GetInstance().lidar_drv->getTypicalScanMode(typicalMode);
scanModeSubMenu_.CreateMenu();
scanModeMenuRecBegin_ = 2001;
std::vector<RplidarScanMode>::iterator modeIter = modeVec_.begin();
int index = 0;
for(; modeIter != modeVec_.end(); modeIter++)
{
scanModeSubMenu_.AppendMenuA(MF_STRING, scanModeMenuRecBegin_ + index, modeIter->scan_mode);
index++;
}
m_CmdBar.GetMenu().GetSubMenu(2).InsertMenuA(SCANMODE_SUB, MF_POPUP | MF_BYPOSITION, (UINT)scanModeSubMenu_.m_hMenu, "Scan Mode");
usingScanMode_ = typicalMode;
updateControlStatus();
LidarMgr::GetInstance().lidar_drv->checkMotorCtrlSupport(support_motor_ctrl);
// setup timer
this->SetTimer(REFRESEH_TIMER, 1000/30);
checkDeviceHealth();
UISetCheck(ID_CMD_STOP, 1);
forcescan = 0;
UISetCheck(ID_OPTION_EXPRESSMODE, TRUE);
return 0;
}
LRESULT CMainFrame::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
LidarMgr::GetInstance().lidar_drv->stopMotor();
// unregister message filtering and idle updates
this->KillTimer(REFRESEH_TIMER);
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->RemoveMessageFilter(this);
pLoop->RemoveIdleHandler(this);
bHandled = FALSE;
return 1;
}
void CMainFrame::scanModeSelect(int mode)
{
if((unsigned int)mode >= scanModeMenuRecBegin_ && (unsigned int)mode < scanModeMenuRecBegin_ + modeVec_.size())
{
usingScanMode_ = mode - scanModeMenuRecBegin_;
onSwitchMode(WORKING_MODE_SCAN);
}
}
LRESULT CMainFrame::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
PostMessage(WM_CLOSE);
return 0;
}
LRESULT CMainFrame::OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
// TODO: add code to initialize document
return 0;
}
LRESULT CMainFrame::OnViewToolBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
static BOOL bVisible = TRUE; // initially visible
bVisible = !bVisible;
CReBarCtrl rebar = m_hWndToolBar;
int nBandIndex = rebar.IdToIndex(ATL_IDW_BAND_FIRST + 1); // toolbar is 2nd added band
rebar.ShowBand(nBandIndex, bVisible);
UISetCheck(ID_VIEW_TOOLBAR, bVisible);
UpdateLayout();
return 0;
}
LRESULT CMainFrame::OnViewStatusBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
BOOL bVisible = !::IsWindowVisible(m_hWndStatusBar);
::ShowWindow(m_hWndStatusBar, bVisible ? SW_SHOWNOACTIVATE : SW_HIDE);
UISetCheck(ID_VIEW_STATUS_BAR, bVisible);
UpdateLayout();
return 0;
}
LRESULT CMainFrame::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CAboutDlg dlg;
dlg.DoModal();
return 0;
}
void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
switch (workingMode)
{
case WORKING_MODE_SCAN:
onRefreshScanData();
break;
}
}
LRESULT CMainFrame::OnCmdReset(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
if (MessageBox("The device will reboot.", "Are you sure?",
MB_OKCANCEL|MB_ICONQUESTION) != IDOK) {
return 0;
}
onSwitchMode(WORKING_MODE_IDLE);
LidarMgr::GetInstance().lidar_drv->reset();
return 0;
}
LRESULT CMainFrame::OnCmdStop(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
onSwitchMode(WORKING_MODE_IDLE);
m_scanview.stopScan();
return 0;
}
LRESULT CMainFrame::OnCmdScan(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
onSwitchMode(WORKING_MODE_SCAN);
return 0;
}
LRESULT CMainFrame::OnOptForcescan(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
forcescan=!forcescan;
UISetCheck(ID_OPT_FORCESCAN, forcescan?1:0);
return 0;
}
LRESULT CMainFrame::OnFileDumpdata(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
switch (workingMode) {
case WORKING_MODE_SCAN:
{
//capture the snapshot
std::vector<scanDot> snapshot = m_scanview.getScanList();
//prompt
CFileDialog dlg(FALSE);
if (dlg.DoModal()==IDOK) {
FILE * outputfile = fopen(dlg.m_szFileName, "w");
fprintf(outputfile, "#RPLIDAR SCAN DATA\n#COUNT=%d\n#Angule\tDistance\tQuality\n",snapshot.size());
for (int pos = 0; pos < (int)snapshot.size(); ++pos) {
fprintf(outputfile, "%.4f %.1f %d\n", snapshot[pos].angle, snapshot[pos].dist, snapshot[pos].quality);
}
fclose(outputfile);
}
}
break;
}
return 0;
}
void CMainFrame::onRefreshScanData()
{
rplidar_response_measurement_node_hq_t nodes[8192];
size_t cnt = _countof(nodes);
RPlidarDriver * lidar_drv = LidarMgr::GetInstance().lidar_drv;
if (IS_OK(lidar_drv->grabScanDataHq(nodes, cnt, 0)))
{
float sampleDurationRefresh = modeVec_[usingScanMode_].us_per_sample;
m_scanview.setScanData(nodes, cnt, sampleDurationRefresh);
}
}
void CMainFrame::updateControlStatus()
{
//update menu item scan mode text
char menuText[100];
sprintf(menuText, "%s%s", "Scan mode: ", modeVec_[usingScanMode_].scan_mode);
CString strTmp(menuText);
LPCTSTR lp = (LPCTSTR)strTmp;
m_CmdBar.GetMenu().GetSubMenu(2).ModifyMenuA(SCANMODE_SUB, MF_BYPOSITION, (UINT)scanModeSubMenu_.m_hMenu, lp);
scanModeSubMenu_.CheckMenuRadioItem(0, modeVec_.size()-1,usingScanMode_,MF_BYPOSITION);
//determine if menu items are usable
switch (workingMode)
{
case WORKING_MODE_IDLE:
m_CmdBar.GetMenu().GetSubMenu(2).EnableMenuItem(SCANMODE_SUB, MF_BYPOSITION | MF_ENABLED);
break;
case WORKING_MODE_SCAN:
m_CmdBar.GetMenu().GetSubMenu(2).EnableMenuItem(SCANMODE_SUB, MF_BYPOSITION | MF_DISABLED);
break;
}
onUpdateTitle();
}
void CMainFrame::onUpdateTitle()
{
char titleMsg[200];
const char * workingmodeDesc;
char deviceDesc[10];
switch (workingMode) {
case WORKING_MODE_IDLE:
workingmodeDesc = "IDLE";
break;
case WORKING_MODE_SCAN:
workingmodeDesc = "SCAN";
break;
default:
assert(!"should not come here");
}
if((devInfo.model>>4)>RPLIDAR_T_SERIES_MINUM_MAJOR_ID){
sprintf(deviceDesc,"T%d",(devInfo.model>>4)-RPLIDAR_T_SERIES_MINUM_MAJOR_ID) ;
}else if((devInfo.model>>4)>RPLIDAR_S_SERIES_MINUM_MAJOR_ID){
sprintf(deviceDesc,"S%d",(devInfo.model>>4)-RPLIDAR_S_SERIES_MINUM_MAJOR_ID) ;
}else{
sprintf(deviceDesc,"A%d",devInfo.model>>4) ;
}
sprintf(titleMsg, "[%s] Model: %sM%d(%d) FW: %d.%02d HW: %d Serial: "
, workingmodeDesc
, deviceDesc
, devInfo.model&0xf
, devInfo.model
, devInfo.firmware_version>>8
, devInfo.firmware_version & 0xFF, devInfo.hardware_version);
for (int pos = 0, startpos = strlen(titleMsg); pos < sizeof(devInfo.serialnum); ++pos)
{
sprintf(&titleMsg[startpos], "%02X", devInfo.serialnum[pos]);
startpos+=2;
}
this->SetWindowTextA(titleMsg);
}
void CMainFrame::onSwitchMode(int newMode)
{
// switch mode
if (newMode == workingMode) return;
switch (newMode) {
case WORKING_MODE_IDLE:
{
// stop the previous operation
LidarMgr::GetInstance().lidar_drv->stopMotor();
LidarMgr::GetInstance().lidar_drv->stop();
UISetCheck(ID_CMD_STOP, 1);
UISetCheck(ID_CMD_GRAB_PEAK, 0);
UISetCheck(ID_CMD_GRAB_FRAME, 0);
UISetCheck(ID_CMD_SCAN, 0);
UISetCheck(ID_CMD_GRABFRAMENONEDIFF, 0);
LidarMgr::GetInstance().lidar_drv->clearNetSerialRxCache();
}
break;
case WORKING_MODE_SCAN:
{
CWindow hwnd = m_hWndClient;
hwnd.ShowWindow(SW_HIDE);
m_hWndClient = m_scanview;
m_scanview.ShowWindow(SW_SHOW);
checkDeviceHealth();
LidarMgr::GetInstance().lidar_drv->startMotor();
LidarMgr::GetInstance().lidar_drv->startScanExpress(forcescan, usingScanMode_);
UISetCheck(ID_CMD_STOP, 0);
UISetCheck(ID_CMD_GRAB_PEAK, 0);
UISetCheck(ID_CMD_GRAB_FRAME, 0);
UISetCheck(ID_CMD_SCAN, 1);
UISetCheck(ID_CMD_GRABFRAMENONEDIFF, 0);
}
break;
default:
assert(!"unsupported mode");
}
UpdateLayout();
workingMode = newMode;
updateControlStatus();
}
void CMainFrame::checkDeviceHealth()
{
int errorcode;
if (!LidarMgr::GetInstance().checkDeviceHealth(&errorcode)){
char msg[200];
sprintf(msg, "The device is in unhealthy status.\n"
"You need to reset it.\n"
"Errorcode: 0x%08x", errorcode);
MessageBox(msg, "Warning", MB_OK);
}
}
LRESULT CMainFrame::OnSetFreq(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if (!support_motor_ctrl) {
MessageBox("The device is not supported to set frequency.\n", "Warning", MB_OK);
} else {
CFreqSetDlg dlg;
dlg.DoModal();
}
return 0;
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter