mirror of
https://gitee.com/cv_team/uestc-careye.git
synced 2024-11-29 18:28:42 +08:00
Add:新增一些内存溢出测试,模块联调测试
This commit is contained in:
parent
a11d5ec59c
commit
600d3ce6c8
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,4 +4,5 @@ data/
|
||||
.idea/
|
||||
.vs/
|
||||
cmake-build-*/
|
||||
3rdparty/grpc/third_party
|
||||
|
||||
|
5
cmake/rcLibrealsense2Cmake.cmake
Normal file
5
cmake/rcLibrealsense2Cmake.cmake
Normal file
@ -0,0 +1,5 @@
|
||||
message(STATUS "Find Librealsence2")
|
||||
find_package(realsense2 REQUIRED)
|
||||
message(STATUS realsense2_LIBRARY="${realsense2_LIBRARY}")
|
||||
message(STATUS realsense2_INCLUDE_DIRS="${realsense2_INCLUDE_DIR}")
|
||||
include_directories(${realsense2_INCLUDE_DIR})
|
@ -1,5 +1,5 @@
|
||||
set(Pistache_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/pistache/prefix/lib/cmake/pistache)
|
||||
message(STATUS "sssssssss${Pistache_DIR}")
|
||||
message(STATUS "Pistache_DIR=${Pistache_DIR}")
|
||||
find_package(Pistache REQUIRED)
|
||||
include_directories(${Pistache_INCLUDE_DIRS})
|
||||
message("${Pistache_LIBRARIES}/libpistache.a")
|
||||
message(STATUS Pistache_LIBRARIES="${Pistache_LIBRARIES}/libpistache.a")
|
@ -13,6 +13,7 @@ include(${ENV_CMAKE_FILES_PATH}/rcGlobalIncludeCmake.cmake)
|
||||
include(${ENV_CMAKE_FILES_PATH}/rcOpenGLCmake.cmake)
|
||||
include(${ENV_CMAKE_FILES_PATH}/rcOpenCVCmake.cmake)
|
||||
include(${ENV_CMAKE_FILES_PATH}/rcPistacheCmake.cmake)
|
||||
include(${ENV_CMAKE_FILES_PATH}/rcLibrealsense2Cmake.cmake)
|
||||
|
||||
include(${CMAKE_FILES_PATH}/rcSLAMRadarCmake.cmake)
|
||||
include(${CMAKE_FILES_PATH}/rcNetworkCmake.cmake)
|
||||
|
@ -40,7 +40,8 @@
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="col-md-6">
|
||||
<img src="https://static.runoob.com/images/mix/img_avatar.png" width="100%" height="100%">
|
||||
<p id="image_title">图像标题</p>
|
||||
<img id="image_stream" src="https://static.runoob.com/images/mix/img_avatar.png" width="100%" height="100%">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="row">
|
||||
@ -53,7 +54,8 @@
|
||||
</div>
|
||||
<div class="col-md-4 col-sm-4 col-xs-4">
|
||||
<div id="button_front" class="bs-example ">
|
||||
<button onclick="button_front_click()" type="button" class="btn btn-primary controller_button"
|
||||
<button onclick="button_front_click()" type="button"
|
||||
class="btn btn-primary controller_button"
|
||||
data-loading-text="Loading...">前进
|
||||
</button>
|
||||
</div>
|
||||
@ -69,21 +71,24 @@
|
||||
<div class="row">
|
||||
<div class="col-md-4 col-sm-4 col-xs-4">
|
||||
<div id="button_left" class="bs-example ">
|
||||
<button onclick="button_left_click()" type="button" class="btn btn-primary controller_button"
|
||||
<button onclick="button_left_click()" type="button"
|
||||
class="btn btn-primary controller_button"
|
||||
data-loading-text="Loading...">左转
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 col-sm-4 col-xs-4">
|
||||
<div id="button_stop" class="bs-example ">
|
||||
<button onclick="button_stop_click()" type="button" class="btn btn-primary controller_button"
|
||||
<button onclick="button_stop_click()" type="button"
|
||||
class="btn btn-primary controller_button"
|
||||
data-loading-text="Loading...">停止
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 col-sm-4 col-xs-4">
|
||||
<div id="button_right" class="bs-example">
|
||||
<button onclick="button_right_click()" type="button" class="btn btn-primary controller_button"
|
||||
<button onclick="button_right_click()" type="button"
|
||||
class="btn btn-primary controller_button"
|
||||
data-loading-text="Loading...">右转
|
||||
</button>
|
||||
</div>
|
||||
@ -92,21 +97,24 @@
|
||||
<div class="row">
|
||||
<div class="col-md-4 col-sm-4 col-xs-4">
|
||||
<div id="button_follow" class="bs-example ">
|
||||
<button onclick="button_follow_click()" type="button" class="btn btn-primary controller_button"
|
||||
<button onclick="button_follow_click()" type="button"
|
||||
class="btn btn-primary controller_button"
|
||||
data-loading-text="Loading...">跟随
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 col-sm-4 col-xs-4">
|
||||
<div id="button_line" class="bs-example ">
|
||||
<button onclick="button_line_click()" type="button" class="btn btn-primary controller_button"
|
||||
<button onclick="button_line_click()" type="button"
|
||||
class="btn btn-primary controller_button"
|
||||
data-loading-text="Loading...">寻线
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 col-sm-4 col-xs-4">
|
||||
<div id="button_control" class="bs-example">
|
||||
<button onclick="button_control_click()" type="button" class="btn btn-primary controller_button"
|
||||
<button onclick="button_control_click()" type="button"
|
||||
class="btn btn-primary controller_button"
|
||||
data-loading-text="Loading...">遥控
|
||||
</button>
|
||||
</div>
|
||||
@ -116,5 +124,20 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
setInterval("video()", 200);
|
||||
|
||||
function video() {
|
||||
$.ajax({
|
||||
url: '/video',
|
||||
async: true,
|
||||
dataType: "html",
|
||||
type: 'get',
|
||||
success: function (data) {
|
||||
$('#image_stream').attr("src","data:image/png;base64,"+data);
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -31,7 +31,6 @@ function button_follow_click() {
|
||||
}
|
||||
|
||||
function send_command(urlpath) {
|
||||
alert(urlpath);
|
||||
$.ajax({
|
||||
type : "GET",
|
||||
url : urlpath,
|
||||
@ -49,3 +48,4 @@ function button_line_click() {
|
||||
send_command('/move/line')
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,6 +5,7 @@ set(RC_FILES
|
||||
${RC_RTMP_FILES}
|
||||
${RC_MOVE_FILES}
|
||||
${RC_MAPPING_FILES}
|
||||
${RC_MESSAGE_FILES}
|
||||
${RC_GUI_FILES}
|
||||
${RC_CV_FILES}
|
||||
${RC_JSON_FILES}
|
||||
@ -24,6 +25,7 @@ target_link_libraries(${LIB_NAME} ${OpenCV_LIBS}
|
||||
stdc++
|
||||
m
|
||||
${MPI_CXX_LIBRARIES}
|
||||
${realsense2_LIBRARY}
|
||||
${Pistache_LIBRARIES}/libpistache.a
|
||||
)
|
||||
if (${WITH_TBB} STREQUAL "ON")
|
||||
|
@ -2,4 +2,8 @@ set(EXE_NAME RoboCar)
|
||||
set(RCMAIN_DIR ${PROJECT_SOURCE_DIR}/src/sources/rc_main)
|
||||
set(SOURCE_FILES ${RCMAIN_DIR}/main.cpp)
|
||||
add_executable(${EXE_NAME} ${SOURCE_FILES})
|
||||
target_link_libraries(${EXE_NAME} ${OpenCV_LIBS} rc pthread gflags)
|
||||
target_link_libraries(${EXE_NAME} ${OpenCV_LIBS} rc
|
||||
pthread
|
||||
gflags
|
||||
stdc++
|
||||
)
|
@ -29,6 +29,7 @@ if (RC_TEST)
|
||||
${GTK2_LIBRARIES}
|
||||
${GTKMM2_LIBRARIES}
|
||||
${Pistache_LIBRARIES}/libpistache.a
|
||||
${realsense2_LIBRARY}
|
||||
# GLEW
|
||||
GLU
|
||||
# gtkgl-2.0
|
||||
|
22
robot_client/src/include/rc_cv/MatConvert.h
Normal file
22
robot_client/src/include/rc_cv/MatConvert.h
Normal file
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/18.
|
||||
//
|
||||
|
||||
#ifndef UESTC_CAREYE_MATCONVERT_H
|
||||
#define UESTC_CAREYE_MATCONVERT_H
|
||||
|
||||
#include <string>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
std::string base64Decode(const char *Data, int DataByte);
|
||||
|
||||
|
||||
std::string base64Encode(const unsigned char *Data, int DataByte);
|
||||
|
||||
//imgType 包括png bmp jpg jpeg等opencv能够进行编码解码的文件
|
||||
std::string Mat2Base64(const cv::Mat &img, std::string imgType);
|
||||
|
||||
|
||||
cv::Mat Base2Mat(std::string &base64_data);
|
||||
|
||||
#endif //UESTC_CAREYE_MATCONVERT_H
|
@ -1,26 +1,4 @@
|
||||
/*
|
||||
Copyright (c) 2013 Ben Croston
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
/* Software PWM using threads */
|
||||
#ifndef ROBOCAR_RC_SOFT_PWM_GPIO_H
|
||||
namespace RC {
|
||||
namespace GPIO {
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#ifndef ROBOCAR_MAIN_H
|
||||
#define ROBOCAR_MAIN_H
|
||||
|
||||
#include <iostream>
|
||||
#include <rc_move/rcmove.h>
|
||||
#include "rc_param.h"
|
||||
|
@ -72,7 +72,7 @@ static void generateDefaultConfig(){
|
||||
// <port>1080</port>
|
||||
// </httpd>
|
||||
fswrite<<"httpd"<<"{";
|
||||
fswrite.write("port",1090);
|
||||
fswrite.write("port",9800);
|
||||
fswrite<<"}";
|
||||
|
||||
// <!--WEBSOCKER配置-->
|
||||
|
@ -6,17 +6,29 @@
|
||||
#define ROBOCAR_RC_BASE_MSG_H
|
||||
|
||||
#include <queue>
|
||||
#include <map>
|
||||
|
||||
namespace RC {
|
||||
namespace Message {
|
||||
|
||||
template<typename T>
|
||||
class BaseMessage {
|
||||
private:
|
||||
static std::queue<T> self_message_queue;
|
||||
public:
|
||||
T pop_message() {
|
||||
return self_message_queue.pop();
|
||||
std::queue <T> self_message_queue;
|
||||
int max_queue_size;
|
||||
public:
|
||||
BaseMessage(int max_queue_size) : max_queue_size(max_queue_size) {
|
||||
|
||||
};
|
||||
|
||||
void pop_message() {
|
||||
if(self_message_queue.size()!=0)
|
||||
self_message_queue.pop();
|
||||
}
|
||||
|
||||
void push_message(T &cell) {
|
||||
self_message_queue.push(cell);
|
||||
if(self_message_queue.size()>max_queue_size)
|
||||
pop_message();
|
||||
}
|
||||
|
||||
T front_message() {
|
||||
@ -32,7 +44,7 @@ namespace RC {
|
||||
}
|
||||
|
||||
void release_message() {
|
||||
while(self_message_queue.size()>0)
|
||||
while (self_message_queue.size() != 0)
|
||||
self_message_queue.pop();
|
||||
}
|
||||
};
|
||||
|
@ -5,14 +5,19 @@
|
||||
#ifndef ROBOCAR_EC_IMAGE_MSG_H
|
||||
#define ROBOCAR_EC_IMAGE_MSG_H
|
||||
|
||||
#include <rc_task/rc_message/rc_base_msg.hpp>
|
||||
#include <rc_message/rc_base_msg.hpp>
|
||||
#include <rc_task/rcTaskManager_DataStruct.h>
|
||||
#include <map>
|
||||
namespace RC{
|
||||
namespace Message{
|
||||
|
||||
class ImageMessage:public BaseMessage<std::map<int,ImagePackage>>{
|
||||
#include <string>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
namespace RC {
|
||||
namespace Message {
|
||||
class ImageMessage :
|
||||
public BaseMessage<std::string> {
|
||||
public:
|
||||
ImageMessage(int max_queue_size);
|
||||
static boost::mutex image_mutex;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
23
robot_client/src/include/rc_message/rc_move_msg.h
Normal file
23
robot_client/src/include/rc_message/rc_move_msg.h
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/6.
|
||||
//
|
||||
|
||||
#ifndef ROBOCAR_RC_MOVE_MSG_H
|
||||
#define ROBOCAR_RC_MOVE_MSG_H
|
||||
|
||||
#include <rc_message/rc_base_msg.hpp>
|
||||
#include <map>
|
||||
#include <rc_move/rcmove_data_struct.h>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
namespace RC {
|
||||
namespace Message {
|
||||
class MoveMessage : public BaseMessage<WHEEL_DATA> {
|
||||
public:
|
||||
explicit MoveMessage(int max_queue_size);
|
||||
static boost::mutex move_mutex;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //ROBOCAR_RC_MOVE_MSG_H
|
@ -7,12 +7,16 @@
|
||||
|
||||
#include <rc_message/rc_serial_msg.h>
|
||||
#include <rc_message/rc_image_msg.h>
|
||||
#include <rc_message/rc_net_work_msg.h>
|
||||
#include <rc_message/rc_move_msg.h>
|
||||
namespace RC{
|
||||
namespace Message{
|
||||
class MessageServer {
|
||||
public:
|
||||
static ImageMessage imageMessage;//图像消息
|
||||
static SerialMessage serialMessage;//串口消息
|
||||
static NetworkMessage networkMessage;//串口消息
|
||||
static MoveMessage moveMessage;//移动消息
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,15 @@
|
||||
#ifndef ROBOCAR_RC_NET_WORK_MSG_H
|
||||
#define ROBOCAR_RC_NET_WORK_MSG_H
|
||||
|
||||
namespace RC{
|
||||
namespace Message{
|
||||
class NetworkMessage: public {
|
||||
#include <rc_message/rc_base_msg.hpp>
|
||||
#include <map>
|
||||
#include <rc_network/rc_asny_tcp_client.h>
|
||||
|
||||
namespace RC {
|
||||
namespace Message {
|
||||
class NetworkMessage : public BaseMessage<std::map<int, std::string>> {
|
||||
public:
|
||||
NetworkMessage(int max_queue_size);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -8,17 +8,26 @@
|
||||
#include <rc_task/rcTaskManager_DataStruct.h>
|
||||
#include <rc_message/rc_base_msg.hpp>
|
||||
#include <map>
|
||||
namespace RC{
|
||||
namespace Message{
|
||||
class SerialMessage:public BaseMessage<std::map<int,Task::rc_SerialPackage>>{
|
||||
|
||||
namespace RC {
|
||||
namespace Message {
|
||||
|
||||
class SerialMessage : public BaseMessage<std::map < int, Task::rc_SerialPackage>> {
|
||||
private:
|
||||
bool is_init= false;
|
||||
bool is_init = false;
|
||||
static boost::mutex::scoped_lock read_write_lock;
|
||||
static std::map<int,Task::rc_SerialPackage> serial_message;
|
||||
public:
|
||||
void init(std::string device,int freq);
|
||||
int send(int head,int size,char* message);
|
||||
static std::map<int, Task::rc_SerialPackage> serial_message;
|
||||
|
||||
public:
|
||||
|
||||
SerialMessage(int max_queue_size);
|
||||
|
||||
void init(std::string device, int freq);
|
||||
|
||||
int send(int head, int size, char *message);
|
||||
|
||||
int run();
|
||||
|
||||
int recive();
|
||||
};
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ namespace RC {
|
||||
*/
|
||||
void command(char com, int speed_1, int speed_2, int speed_3);
|
||||
|
||||
void excute(WHEEL_DATA wheelData);
|
||||
|
||||
void wheel_1_forward(int speed);
|
||||
|
||||
void wheel_1_backward(int speed);
|
||||
|
@ -6,12 +6,15 @@
|
||||
#define ROBOCAR_RCMOVE_DATA_STRUCT_H
|
||||
//车轮控制数据
|
||||
typedef struct {
|
||||
unsigned short wheel_1_speed;
|
||||
unsigned short wheel_2_speed;
|
||||
unsigned short wheel_3_speed;
|
||||
unsigned short sum=0;//校验和
|
||||
bool weel_2_direction;
|
||||
bool weel_1_direction;
|
||||
bool weel_3_direction;
|
||||
int wheel_1_speed=0;
|
||||
int wheel_2_speed=0;
|
||||
int wheel_3_speed=0;
|
||||
int weel_1_direction=0;
|
||||
int weel_2_direction=0;
|
||||
int weel_3_direction=0;
|
||||
}WHEEL_DATA;
|
||||
enum {
|
||||
RC_MOVE_BACKWARD=0,
|
||||
RC_MOVE_FORWARD
|
||||
};
|
||||
#endif //ROBOCAR_RCMOVE_DATA_STRUCT_H
|
||||
|
47
robot_client/src/include/rc_network/rc_httpd_rest.h
Normal file
47
robot_client/src/include/rc_network/rc_httpd_rest.h
Normal file
@ -0,0 +1,47 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/18.
|
||||
//
|
||||
|
||||
#ifndef UESTC_CAREYE_RC_HTTPD_REST_H
|
||||
#define UESTC_CAREYE_RC_HTTPD_REST_H
|
||||
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <pistache/endpoint.h>
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
namespace RC{
|
||||
namespace Network{
|
||||
namespace Httpd{
|
||||
using namespace std;
|
||||
using namespace Pistache;
|
||||
class rcHttpdRest {
|
||||
public:
|
||||
explicit rcHttpdRest(int port);
|
||||
|
||||
void init(size_t thr ) ;
|
||||
|
||||
void start();
|
||||
|
||||
private:
|
||||
void setupRoutes();
|
||||
|
||||
void video(const Rest::Request &request, Http::ResponseWriter response);
|
||||
|
||||
void index(const Rest::Request &request, Http::ResponseWriter response) ;
|
||||
|
||||
void move(const Rest::Request &request, Http::ResponseWriter response);
|
||||
|
||||
void staticfile(const Rest::Request &request, Http::ResponseWriter response);
|
||||
|
||||
void doAuth(const Rest::Request &request, Http::ResponseWriter response) ;
|
||||
|
||||
std::shared_ptr<Http::Endpoint> httpEndpoint;
|
||||
Rest::Router router;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //UESTC_CAREYE_RC_HTTPD_REST_H
|
16
robot_client/src/include/rc_task/queue_sources_locks.h
Normal file
16
robot_client/src/include/rc_task/queue_sources_locks.h
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/18.
|
||||
//
|
||||
|
||||
#ifndef UESTC_CAREYE_QUEUE_SOURCES_LOCKS_H
|
||||
#define UESTC_CAREYE_QUEUE_SOURCES_LOCKS_H
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
namespace RC{
|
||||
namespace Task{
|
||||
namespace Lock{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //UESTC_CAREYE_QUEUE_SOURCES_LOCKS_H
|
113
robot_client/src/sources/rc_cv/MatConvert.cpp
Normal file
113
robot_client/src/sources/rc_cv/MatConvert.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/18.
|
||||
//
|
||||
|
||||
#include <rc_cv/MatConvert.h>
|
||||
#include <opencv2/imgcodecs/legacy/constants_c.h>
|
||||
using namespace cv;
|
||||
std::string base64Decode(const char *Data, int DataByte) {
|
||||
//解码表
|
||||
const char DecodeTable[] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
62, // '+'
|
||||
0, 0, 0,
|
||||
63, // '/'
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // '0'-'9'
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
0, 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, // 'A'-'Z'
|
||||
0, 0, 0, 0, 0, 0,
|
||||
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, // 'a'-'z'
|
||||
};
|
||||
std::string strDecode;
|
||||
int nValue;
|
||||
int i = 0;
|
||||
while (i < DataByte) {
|
||||
if (*Data != '\r' && *Data != '\n') {
|
||||
nValue = DecodeTable[*Data++] << 18;
|
||||
nValue += DecodeTable[*Data++] << 12;
|
||||
strDecode += (nValue & 0x00FF0000) >> 16;
|
||||
if (*Data != '=') {
|
||||
nValue += DecodeTable[*Data++] << 6;
|
||||
strDecode += (nValue & 0x0000FF00) >> 8;
|
||||
if (*Data != '=') {
|
||||
nValue += DecodeTable[*Data++];
|
||||
strDecode += nValue & 0x000000FF;
|
||||
}
|
||||
}
|
||||
i += 4;
|
||||
} else {
|
||||
Data++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return strDecode;
|
||||
}
|
||||
|
||||
|
||||
std::string base64Encode(const unsigned char *Data, int DataByte) {
|
||||
//编码表
|
||||
const char EncodeTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
//返回值
|
||||
std::string strEncode;
|
||||
unsigned char Tmp[4] = {0};
|
||||
int LineLength = 0;
|
||||
for (int i = 0; i < (int) (DataByte / 3); i++) {
|
||||
Tmp[1] = *Data++;
|
||||
Tmp[2] = *Data++;
|
||||
Tmp[3] = *Data++;
|
||||
strEncode += EncodeTable[Tmp[1] >> 2];
|
||||
strEncode += EncodeTable[((Tmp[1] << 4) | (Tmp[2] >> 4)) & 0x3F];
|
||||
strEncode += EncodeTable[((Tmp[2] << 2) | (Tmp[3] >> 6)) & 0x3F];
|
||||
strEncode += EncodeTable[Tmp[3] & 0x3F];
|
||||
if (LineLength += 4, LineLength == 76) {
|
||||
strEncode += "\r\n";
|
||||
LineLength = 0;
|
||||
}
|
||||
}
|
||||
//对剩余数据进行编码
|
||||
int Mod = DataByte % 3;
|
||||
if (Mod == 1) {
|
||||
Tmp[1] = *Data++;
|
||||
strEncode += EncodeTable[(Tmp[1] & 0xFC) >> 2];
|
||||
strEncode += EncodeTable[((Tmp[1] & 0x03) << 4)];
|
||||
strEncode += "==";
|
||||
} else if (Mod == 2) {
|
||||
Tmp[1] = *Data++;
|
||||
Tmp[2] = *Data++;
|
||||
strEncode += EncodeTable[(Tmp[1] & 0xFC) >> 2];
|
||||
strEncode += EncodeTable[((Tmp[1] & 0x03) << 4) | ((Tmp[2] & 0xF0) >> 4)];
|
||||
strEncode += EncodeTable[((Tmp[2] & 0x0F) << 2)];
|
||||
strEncode += "=";
|
||||
}
|
||||
|
||||
|
||||
return strEncode;
|
||||
}
|
||||
|
||||
//imgType 包括png bmp jpg jpeg等opencv能够进行编码解码的文件
|
||||
std::string Mat2Base64(const cv::Mat &img, std::string imgType) {
|
||||
//Mat转base64
|
||||
std::string img_data;
|
||||
std::vector <uchar> vecImg;
|
||||
std::vector<int> vecCompression_params;
|
||||
vecCompression_params.push_back(95);
|
||||
vecCompression_params.push_back(90);
|
||||
imgType = "." + imgType;
|
||||
cv::imencode(imgType, img, vecImg, vecCompression_params);
|
||||
img_data = base64Encode(vecImg.data(), vecImg.size());
|
||||
return img_data;
|
||||
}
|
||||
|
||||
|
||||
cv::Mat Base2Mat(std::string &base64_data) {
|
||||
cv::Mat img;
|
||||
std::string s_mat;
|
||||
s_mat = base64Decode(base64_data.data(), base64_data.size());
|
||||
std::vector<char> base64_img(s_mat.begin(), s_mat.end());
|
||||
img = cv::imdecode(base64_img, CV_LOAD_IMAGE_COLOR);
|
||||
return img;
|
||||
}
|
@ -3,6 +3,8 @@
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/pthread/mutex.hpp>
|
||||
|
||||
#define SYSFS_GPIO_EXPORT "/sys/class/gpio/export"
|
||||
#define SYSFS_GPIO_UNEXPORT "/sys/class/gpio/unexport"
|
||||
@ -14,8 +16,10 @@
|
||||
#define SYSFS_GPIO_RST_VAL_L "0"
|
||||
namespace RC {
|
||||
namespace GPIO {
|
||||
boost::mutex gpio_mutes;
|
||||
void pinMode(int gpio, int direction) {
|
||||
pinFree(gpio);
|
||||
boost::mutex::scoped_lock lock(gpio_mutes);
|
||||
int fd;
|
||||
//打开端口/sys/class/gpio# echo gpio > export
|
||||
fd = open(SYSFS_GPIO_EXPORT, O_WRONLY);
|
||||
@ -46,6 +50,7 @@ namespace RC {
|
||||
|
||||
void digitalWrite(int gpio, int value) {
|
||||
//设置端口数值/sys/class/gpio/gpio%d/value# echo value > value
|
||||
boost::mutex::scoped_lock lock(gpio_mutes);
|
||||
boost::format fmt(SYSFS_GPIO_RST_VAL);
|
||||
fmt % gpio;
|
||||
std::string targetString = fmt.str();
|
||||
@ -64,10 +69,9 @@ namespace RC {
|
||||
}
|
||||
|
||||
void pinFree(int gpio) {
|
||||
int fd;
|
||||
|
||||
boost::mutex::scoped_lock lock(gpio_mutes);
|
||||
//打开端口/sys/class/gpio# echo gpio > export
|
||||
fd = open(SYSFS_GPIO_UNEXPORT, O_WRONLY);
|
||||
int fd = open(SYSFS_GPIO_UNEXPORT, O_WRONLY);
|
||||
if (fd == -1) {
|
||||
return;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
//加载
|
||||
#define SYSFS_PWM_EXPORT "/sys/class/pwm/pwmchip0/export"
|
||||
//卸载
|
||||
@ -20,9 +20,10 @@
|
||||
|
||||
namespace RC {
|
||||
namespace GPIO {
|
||||
|
||||
boost::mutex pwm_mutes;
|
||||
void pwm_begin(unsigned int gpio) {
|
||||
pwm_free(gpio);
|
||||
boost::mutex::scoped_lock lock(pwm_mutes);
|
||||
int fd = open(SYSFS_PWM_EXPORT, O_WRONLY);
|
||||
if (fd == -1) {
|
||||
return;
|
||||
@ -33,6 +34,7 @@ namespace RC {
|
||||
}
|
||||
|
||||
void pwm_set_duty_cycle(unsigned int gpio, int dutycycle) {
|
||||
boost::mutex::scoped_lock lock(pwm_mutes);
|
||||
boost::format fmt(SYSFS_PWM_DUTYCYCLE);
|
||||
fmt % gpio;
|
||||
std::string targetString = fmt.str();
|
||||
@ -46,6 +48,7 @@ namespace RC {
|
||||
}
|
||||
|
||||
void pwm_set_frequency(unsigned int gpio, int freq) {
|
||||
boost::mutex::scoped_lock lock(pwm_mutes);
|
||||
boost::format fmt(SYSFS_PWM_PERIOD);
|
||||
fmt % gpio;
|
||||
std::string targetString = fmt.str();
|
||||
@ -59,6 +62,7 @@ namespace RC {
|
||||
}
|
||||
|
||||
void pwm_start(unsigned int gpio) {
|
||||
boost::mutex::scoped_lock lock(pwm_mutes);
|
||||
boost::format fmt(SYSFS_PWM_ENABLE);
|
||||
fmt % gpio;
|
||||
std::string targetString = fmt.str();
|
||||
@ -71,6 +75,7 @@ namespace RC {
|
||||
}
|
||||
|
||||
void pwm_stop(unsigned int gpio) {
|
||||
boost::mutex::scoped_lock lock(pwm_mutes);
|
||||
boost::format fmt(SYSFS_PWM_ENABLE);
|
||||
fmt % gpio;
|
||||
std::string targetString = fmt.str();
|
||||
@ -83,6 +88,7 @@ namespace RC {
|
||||
}
|
||||
|
||||
void pwm_free(unsigned int gpio) {
|
||||
boost::mutex::scoped_lock lock(pwm_mutes);
|
||||
int fd = open(SYSFS_PWM_UNEXPORT, O_WRONLY);
|
||||
if (fd == -1) {
|
||||
return;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <rc_main/mainn.h>
|
||||
#include <rc_main/main.h>
|
||||
#include <rc_task/rcTaskManager.h>
|
||||
#include "main.hpp"
|
||||
|
||||
|
9
robot_client/src/sources/rc_message/rc_base_msg.cpp
Normal file
9
robot_client/src/sources/rc_message/rc_base_msg.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
//
|
||||
// Created by PulsarV on 18-10-30.
|
||||
//
|
||||
|
||||
#include <rc_message/rc_base_msg.hpp>
|
||||
namespace RC{
|
||||
namespace Message{
|
||||
}
|
||||
}
|
@ -3,8 +3,16 @@
|
||||
//
|
||||
|
||||
#include <rc_message/rc_base_msg.hpp>
|
||||
namespace RC{
|
||||
namespace Message{
|
||||
#include <map>
|
||||
#include <rc_message/rc_image_msg.h>
|
||||
|
||||
|
||||
namespace RC {
|
||||
namespace Message {
|
||||
ImageMessage::ImageMessage(int max_queue_size):BaseMessage<std::string>(max_queue_size) {
|
||||
|
||||
}
|
||||
boost::mutex ImageMessage::image_mutex;
|
||||
|
||||
}
|
||||
}
|
15
robot_client/src/sources/rc_message/rc_move_msg.cpp
Normal file
15
robot_client/src/sources/rc_message/rc_move_msg.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/6.
|
||||
//
|
||||
|
||||
#include <rc_message/rc_move_msg.h>
|
||||
|
||||
namespace RC {
|
||||
namespace Message {
|
||||
MoveMessage::MoveMessage(int max_queue_size) : BaseMessage(max_queue_size) {
|
||||
|
||||
}
|
||||
boost::mutex MoveMessage::move_mutex;
|
||||
}
|
||||
}
|
||||
|
@ -3,3 +3,12 @@
|
||||
//
|
||||
|
||||
#include <rc_message/rc_net_work_msg.h>
|
||||
|
||||
namespace RC {
|
||||
namespace Message {
|
||||
NetworkMessage::NetworkMessage(int max_queue_size) : BaseMessage<std::map<int, std::string>>(max_queue_size) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,11 +3,31 @@
|
||||
//
|
||||
|
||||
#include <rc_message/rc_serial_msg.h>
|
||||
namespace RC{
|
||||
namespace Message{
|
||||
template <typename T> std::queue<T> BaseMessage<T>::self_message_queue;
|
||||
void SerialMessage::init(std::string device, int freq) {
|
||||
|
||||
}
|
||||
namespace RC {
|
||||
namespace Message {
|
||||
|
||||
SerialMessage::SerialMessage(int max_queue_size)
|
||||
: BaseMessage<std::map < int, Task::rc_SerialPackage>>
|
||||
(max_queue_size) {
|
||||
|
||||
}
|
||||
|
||||
void SerialMessage::init(std::string device, int freq) {
|
||||
|
||||
}
|
||||
|
||||
int SerialMessage::send(int head, int size, char *message) {
|
||||
|
||||
}
|
||||
|
||||
int SerialMessage::run() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SerialMessage::recive() {
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -5,8 +5,10 @@
|
||||
|
||||
namespace RC{
|
||||
namespace Message{
|
||||
class MessageServer{
|
||||
ImageMessage MessageServer::imageMessage(3);
|
||||
SerialMessage MessageServer::serialMessage(3);
|
||||
NetworkMessage MessageServer::networkMessage(3);
|
||||
MoveMessage MessageServer::moveMessage(3);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <rc_move/rcmove.h>
|
||||
#include <rc_gpio/c_gpio.h>
|
||||
#include <rc_gpio/soft_pwm.h>
|
||||
#include <base/slog.hpp>
|
||||
|
||||
namespace RC {
|
||||
void RobotCarMove::wheel_1_backward(int speed) {
|
||||
@ -87,4 +88,37 @@ namespace RC {
|
||||
void RobotCarMove::wheel_check(int times) {
|
||||
|
||||
}
|
||||
|
||||
bool flag = 0;
|
||||
|
||||
void RobotCarMove::excute(WHEEL_DATA wheelData) {
|
||||
slog::info << "wheel speed "
|
||||
<< wheelData.wheel_1_speed << " " << wheelData.weel_1_direction << " "
|
||||
<< wheelData.wheel_2_speed << " " << wheelData.weel_2_direction << " "
|
||||
<< wheelData.wheel_2_speed << " " << wheelData.weel_3_direction << " "
|
||||
<< slog::endl;
|
||||
// wheel_stop();
|
||||
// RC::GPIO::pwm_start(rcMoveDevice.pwm_1);
|
||||
// wheel_1_forward(3413333);
|
||||
// if (wheelData.wheel_1_speed == 0) {
|
||||
// if (wheelData.weel_1_direction == RC_MOVE_FORWARD) {
|
||||
//
|
||||
// } else
|
||||
//
|
||||
// }
|
||||
//
|
||||
// if (wheelData.wheel_2_speed == 0) {
|
||||
// if (wheelData.weel_2_direction == RC_MOVE_FORWARD) {
|
||||
// wheel_2_forward(3413333);
|
||||
// } else
|
||||
// wheel_2_backward(3413333);
|
||||
// }
|
||||
//
|
||||
// if (wheelData.wheel_3_speed == 0) {
|
||||
// if (wheelData.weel_3_direction == RC_MOVE_FORWARD) {
|
||||
// wheel_3_forward(3413333);
|
||||
// } else
|
||||
// wheel_3_backward(3413333);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -224,6 +224,7 @@ namespace RC {
|
||||
bool weel_1_direction, unsigned short wheel_1_speed,
|
||||
bool weel_2_direction, unsigned short wheel_2_speed,
|
||||
bool weel_3_direction, unsigned short wheel_3_speed) {
|
||||
|
||||
WHEEL_DATA wheelData;
|
||||
wheelData.weel_1_direction = weel_1_direction;
|
||||
wheelData.weel_2_direction = weel_2_direction;
|
||||
@ -231,12 +232,6 @@ namespace RC {
|
||||
wheelData.wheel_1_speed = wheel_1_speed;
|
||||
wheelData.wheel_2_speed = wheel_2_speed;
|
||||
wheelData.wheel_3_speed = wheel_3_speed;
|
||||
wheelData.sum += weel_1_direction;
|
||||
wheelData.sum += weel_2_direction;
|
||||
wheelData.sum += weel_3_direction;
|
||||
wheelData.sum += wheel_1_speed;
|
||||
wheelData.sum += wheel_2_speed;
|
||||
wheelData.sum += wheel_3_speed;
|
||||
char *buffer = new char[sizeof(WHEEL_DATA)];
|
||||
memcpy(buffer, &wheelData, sizeof(WHEEL_DATA));
|
||||
return buffer;
|
||||
|
125
robot_client/src/sources/rc_network/rc_httpd_rest.cpp
Normal file
125
robot_client/src/sources/rc_network/rc_httpd_rest.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/18.
|
||||
//
|
||||
|
||||
#include <rc_network/rc_httpd_rest.h>
|
||||
#include <base/slog.hpp>
|
||||
#include <iostream>
|
||||
#include <rc_message/rc_msg_server.h>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <rc_task/queue_sources_locks.h>
|
||||
#include <rc_move/rcmove.h>
|
||||
namespace RC {
|
||||
namespace Network {
|
||||
namespace Httpd {
|
||||
void printCookies(const Http::Request &req) {
|
||||
auto cookies = req.cookies();
|
||||
std::cout << "Cookies: [" << std::endl;
|
||||
const std::string indent(4, ' ');
|
||||
for (const auto &c: cookies) {
|
||||
std::cout << indent << c.name << " = " << c.value << std::endl;
|
||||
}
|
||||
std::cout << "]" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
rcHttpdRest::rcHttpdRest(int port) {
|
||||
Port serv_port(port);
|
||||
Address addr(Ipv4::any(), serv_port);
|
||||
httpEndpoint = std::make_shared<Http::Endpoint>(addr);
|
||||
|
||||
}
|
||||
|
||||
void rcHttpdRest::init(size_t thr) {
|
||||
auto opts = Http::Endpoint::options()
|
||||
.threads(static_cast<int>(thr));
|
||||
httpEndpoint->init(opts);
|
||||
setupRoutes();
|
||||
}
|
||||
|
||||
void rcHttpdRest::start() {
|
||||
httpEndpoint->setHandler(router.handler());
|
||||
httpEndpoint->serve();
|
||||
}
|
||||
|
||||
void rcHttpdRest::setupRoutes() {
|
||||
using namespace Rest;
|
||||
Routes::Get(router, "/", Routes::bind(&rcHttpdRest::index, this));
|
||||
Routes::Get(router, "/index", Routes::bind(&rcHttpdRest::index, this));
|
||||
Routes::Get(router, "/js/:filename", Routes::bind(&rcHttpdRest::staticfile, this));
|
||||
Routes::Get(router, "/css/:filename", Routes::bind(&rcHttpdRest::staticfile, this));
|
||||
Routes::Get(router, "/image/:filename", Routes::bind(&rcHttpdRest::staticfile, this));
|
||||
Routes::Get(router, "/move/:action", Routes::bind(&rcHttpdRest::move, this));
|
||||
Routes::Get(router, "/video", Routes::bind(&rcHttpdRest::video, this));
|
||||
|
||||
}
|
||||
|
||||
void rcHttpdRest::video(const Rest::Request &request, Http::ResponseWriter response) {
|
||||
time_t now = time(0);
|
||||
std::string local_date_time = ctime(&now);
|
||||
boost::mutex::scoped_lock lock(RC::Message::ImageMessage::image_mutex);
|
||||
std::string strRespon = Message::MessageServer::imageMessage.front_message();
|
||||
if (strRespon.size() == 0) {
|
||||
response.send(Http::Code::Ok, local_date_time);
|
||||
} else {
|
||||
response.send(Http::Code::Ok, strRespon);
|
||||
}
|
||||
}
|
||||
|
||||
void rcHttpdRest::index(const Rest::Request &request, Http::ResponseWriter response) {
|
||||
Http::serveFile(response, "html/index.html");
|
||||
}
|
||||
|
||||
void rcHttpdRest::move(const Rest::Request &request, Http::ResponseWriter response) {
|
||||
std::string action = request.param(":action").as<std::string>();
|
||||
slog::info << action << slog::endl;
|
||||
WHEEL_DATA wheelData = {0, 0, 0, 1, 1, 1};
|
||||
if (action == "ac") {
|
||||
wheelData = {3413333, 3413333, 3413333, 1, 1, 1};
|
||||
}
|
||||
if (action == "cw") {
|
||||
wheelData = {3413333, 3413333, 3413333, 0, 0, 0};
|
||||
}
|
||||
if (action == "front") {
|
||||
wheelData = {3413333, 3413333, 0, 0, 1, 1};
|
||||
}
|
||||
if (action == "back") {
|
||||
wheelData = {3413333, 3413333, 3413333, 1, 0, 1};
|
||||
}
|
||||
boost::mutex::scoped_lock lock(RC::Message::MoveMessage::move_mutex);
|
||||
|
||||
RC::Message::MessageServer::moveMessage.push_message(wheelData);
|
||||
response.send(Http::Code::Ok, action);
|
||||
}
|
||||
|
||||
void rcHttpdRest::staticfile(const Rest::Request &request, Http::ResponseWriter response) {
|
||||
std::string res_path = "html/";
|
||||
std::string filename = request.param(":filename").as<std::string>();
|
||||
std::string file_ext_name = filename.substr(filename.find_last_of('.') + 1);
|
||||
|
||||
if (file_ext_name == "js") {
|
||||
response.headers().add<Http::Header::ContentType>(MIME(Application, Javascript));
|
||||
res_path = res_path + "js/" + filename;
|
||||
}
|
||||
if (file_ext_name == "css") {
|
||||
response.headers().add<Http::Header::ContentType>(MIME(Text, Css));
|
||||
res_path = res_path + "css/" + filename;
|
||||
}
|
||||
if (file_ext_name == "png" || file_ext_name == "gif" || file_ext_name == "jpeg") {
|
||||
response.headers().add<Http::Header::ContentType>(MIME(Image, Jpeg));
|
||||
res_path = res_path + "image/" + filename;
|
||||
}
|
||||
slog::wget << res_path << slog::endl;
|
||||
Http::serveFile(response, res_path);
|
||||
}
|
||||
|
||||
void rcHttpdRest::doAuth(const Rest::Request &request, Http::ResponseWriter response) {
|
||||
response.headers().add<Http::Header::ContentType>(MIME(Text, EventStream));
|
||||
printCookies(request);
|
||||
response.cookies().add(Http::Cookie("lang", "zh-cn"));
|
||||
response.cookies().add(Http::Cookie("application", "RoboCar"));
|
||||
response.send(Http::Code::Ok);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,12 +6,52 @@
|
||||
#include <iostream>
|
||||
#include <base/slog.hpp>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <librealsense2/rs.hpp>
|
||||
#include <rc_message/rc_msg_server.h>
|
||||
#include <rc_cv/MatConvert.h>
|
||||
|
||||
#define WIDTH 320
|
||||
#define HEIGHT 240
|
||||
#define FPS 30
|
||||
|
||||
|
||||
namespace RC {
|
||||
namespace Task {
|
||||
void run_cv_task(rc_DeviceInfo rcDeviceInfo){
|
||||
using namespace cv;
|
||||
slog::info << "视觉设备启动中" << slog::endl;
|
||||
slog::info << "视觉设备启动完成" << slog::endl;
|
||||
rs2::context ctx;
|
||||
|
||||
slog::info << "当前SDK版本 - " << RS2_API_VERSION_STR << slog::endl;
|
||||
int res_number=ctx.query_devices().size();
|
||||
|
||||
slog::info << "当前深度摄像头连接数 " << res_number << " RealSense devices connected" << slog::endl;
|
||||
|
||||
|
||||
rs2::pipeline pipe;
|
||||
//创建一个以非默认配置的配置用来配置管道
|
||||
rs2::config cfg;
|
||||
cfg.enable_stream(RS2_STREAM_COLOR, WIDTH, HEIGHT, RS2_FORMAT_BGR8, FPS);//向配置添加所需的流
|
||||
cfg.enable_stream(RS2_STREAM_DEPTH, WIDTH, HEIGHT, RS2_FORMAT_Z16,FPS);
|
||||
pipe.start(cfg);
|
||||
while (true) {
|
||||
boost::mutex::scoped_lock lock(RC::Message::ImageMessage::image_mutex);
|
||||
rs2::frameset frames = pipe.wait_for_frames();
|
||||
rs2::depth_frame depth = frames.get_depth_frame();
|
||||
rs2::frame color = frames.get_color_frame();
|
||||
|
||||
Mat depth_image(Size(WIDTH, HEIGHT), CV_16U, (void *) depth.get_data(), Mat::AUTO_STEP);
|
||||
Mat color_image(Size(WIDTH, HEIGHT), CV_8UC3, (void *) color.get_data(), Mat::AUTO_STEP);
|
||||
std::string strRespon = Mat2Base64(color_image, "bmp");
|
||||
Message::MessageServer::imageMessage.push_message(strRespon);
|
||||
// cv::imshow("depth_image", depth_image);
|
||||
// cv::imshow("color_image", color_image);
|
||||
// if (waitKey(100) == 'q')break;
|
||||
|
||||
float dist_to_center = depth.get_distance(WIDTH / 2, HEIGHT / 2);
|
||||
|
||||
// slog::info << "The camera is facing an object " << dist_to_center << " meters away \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,12 +9,25 @@
|
||||
#include <iostream>
|
||||
#include <rc_gpio/c_gpio.h>
|
||||
#include <rc_gpio/soft_pwm.h>
|
||||
namespace RC{
|
||||
namespace Task{
|
||||
#include <rc_message/rc_msg_server.h>
|
||||
#include <rc_task/queue_sources_locks.h>
|
||||
namespace RC {
|
||||
namespace Task {
|
||||
void run_move_task(rc_MoveDevice rcMoveDevice) {
|
||||
using namespace RC::Message;
|
||||
slog::info << "制动任务启动中" << slog::endl;
|
||||
RobotCarMove robot;
|
||||
robot.init(rcMoveDevice);
|
||||
while (true) {
|
||||
boost::mutex::scoped_lock lock(MoveMessage::move_mutex);
|
||||
if (MessageServer::moveMessage.size_message() != 0) {
|
||||
WHEEL_DATA wheelData = MessageServer::moveMessage.front_message();
|
||||
robot.excute(wheelData);
|
||||
// TODO:这个POP要不要存在争议
|
||||
MessageServer::moveMessage.pop_message();
|
||||
sleep(0.01);
|
||||
}
|
||||
}
|
||||
// robot.start();
|
||||
slog::info << "制动任务启动完成" << slog::endl;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
// Created by PulsarV on 18-5-14.
|
||||
//
|
||||
#include <rc_task/rcTaskManager.h>
|
||||
#include <rc_log/rclog.h>
|
||||
#include <zconf.h>
|
||||
#include <rc_network/rc_asny_tcp_client.h>
|
||||
#include <base/slog.hpp>
|
||||
@ -108,8 +107,8 @@ namespace RC {
|
||||
slog::info << ">>>启动远程辅助计算模块" << slog::endl;
|
||||
slog::info << "远程IP:" << remote_address << slog::endl;
|
||||
slog::info << "远程端口号:" << remote_port << slog::endl;
|
||||
rc_Thread robot_network_control_module(boost::bind(run_network_task, server_info));
|
||||
this->RobotServer.insert(rc_ThreadUnion("robot_network_control_module", &robot_network_control_module));
|
||||
// rc_Thread robot_network_control_module(boost::bind(run_network_task, server_info));
|
||||
// this->RobotServer.insert(rc_ThreadUnion("robot_network_control_module", &robot_network_control_module));
|
||||
|
||||
// robot_cv_control_model.join();
|
||||
// robot_network_control_model.join();
|
||||
|
@ -4,11 +4,22 @@
|
||||
#include <rc_task/rcWebStream.h>
|
||||
#include <iostream>
|
||||
#include <base/slog.hpp>
|
||||
#include <rc_network/rc_httpd_rest.h>
|
||||
|
||||
namespace RC {
|
||||
namespace Task {
|
||||
void run_httpd_task(rc_ServerInfo rcServerInfo){
|
||||
using namespace RC::Network::Httpd;
|
||||
|
||||
slog::info << "WEB任务启动中" << slog::endl;
|
||||
slog::info << "WEB任务启动完成" << slog::endl;
|
||||
int thr = 4;
|
||||
|
||||
slog::info << "CPU核心数 = " << hardware_concurrency() << slog::endl;
|
||||
slog::info << "HTTP服务线程 " << thr << " 个" << slog::endl;
|
||||
rcHttpdRest rcHttpdRest(rcServerInfo.httpd_port);
|
||||
|
||||
rcHttpdRest.init(thr);
|
||||
rcHttpdRest.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,28 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/15.
|
||||
//
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
//芯片复位引脚: P1_16
|
||||
#define SYSFS_PWM_EXPORT "/sys/class/pwm/pwmchip0/export"
|
||||
#define SYSFS_GPIO_RST_PIN_VAL "48"
|
||||
#define SYSFS_GPIO_RST_DIR "/sys/class/pwm/pwmchip0/pwm0/period"
|
||||
#define SYSFS_GPIO_RST_DIR_VAL "OUT"
|
||||
#define SYSFS_GPIO_RST_VAL "/sys/class/gpio/gpio48/value"
|
||||
#define SYSFS_GPIO_RST_VAL_H "1"
|
||||
#define SYSFS_GPIO_RST_VAL_L "0"
|
||||
int main(int argc,char** argv){
|
||||
int fd;
|
||||
|
||||
//打开端口/sys/class/gpio# echo 48 > export
|
||||
fd = open(SYSFS_GPIO_EXPORT, O_WRONLY);
|
||||
if(fd == -1)
|
||||
{
|
||||
printf("ERR: Radio hard reset pin open error.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
write(fd, SYSFS_GPIO_RST_PIN_VAL ,sizeof(SYSFS_GPIO_RST_PIN_VAL));
|
||||
close(fd);
|
||||
return 0;
|
||||
#include <rc_move/rcmove.h>
|
||||
#include <rc_task/rcTaskManager_DataStruct.h>
|
||||
#include <iostream>
|
||||
#include <base/slog.hpp>
|
||||
int main(int argc, char **argv) {
|
||||
//初始化测试
|
||||
RC::Task::rc_MoveDevice rcMoveDevice;
|
||||
rcMoveDevice.gpio_1 = 402;
|
||||
rcMoveDevice.gpio_2 = 405;
|
||||
rcMoveDevice.gpio_3 = 431;
|
||||
rcMoveDevice.pwm_1 = 1;
|
||||
rcMoveDevice.pwm_2 = 3;
|
||||
rcMoveDevice.pwm_3 = 0;
|
||||
slog::info << "初始化引脚" << slog::endl;
|
||||
slog::info << "gpio1: " << rcMoveDevice.gpio_1 << " pwm1: " << rcMoveDevice.pwm_1 << slog::endl;
|
||||
slog::info << "gpio2: " << rcMoveDevice.gpio_2 << " pwm2: " << rcMoveDevice.pwm_2 << slog::endl;
|
||||
slog::info << "gpio3: " << rcMoveDevice.gpio_3 << " pwm3: " << rcMoveDevice.pwm_3 << slog::endl;
|
||||
|
||||
RC::RobotCarMove robotCarMove;
|
||||
robotCarMove.init(rcMoveDevice);
|
||||
|
||||
slog::info << "退出" << slog::endl;
|
||||
return 1;
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/18.
|
||||
//
|
||||
#include <librealsense2/rs.hpp>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#define WIDTH 640
|
||||
#define HEIGHT 480
|
||||
#define FPS 30
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
rs2::context ctx;
|
||||
|
||||
std::cout << "hello from librealsense - " << RS2_API_VERSION_STR << std::endl;
|
||||
std::cout << "You have " << ctx.query_devices().size() << " RealSense devices connected" << std::endl;
|
||||
|
||||
|
||||
rs2::pipeline pipe;
|
||||
|
||||
rs2::config cfg;//创建一个以非默认配置的配置用来配置管道
|
||||
//Add desired streams to configuration
|
||||
cfg.enable_stream(RS2_STREAM_COLOR, WIDTH, HEIGHT, RS2_FORMAT_BGR8, FPS);//向配置添加所需的流
|
||||
cfg.enable_stream(RS2_STREAM_DEPTH, WIDTH, HEIGHT, RS2_FORMAT_Z16,FPS);
|
||||
pipe.start(cfg);
|
||||
|
||||
while (true) {
|
||||
rs2::frameset frames = pipe.wait_for_frames();
|
||||
|
||||
rs2::depth_frame depth = frames.get_depth_frame();
|
||||
rs2::frame color = frames.get_color_frame();
|
||||
|
||||
|
||||
Mat depth_image(Size(WIDTH, HEIGHT), CV_16U, (void *) depth.get_data(), Mat::AUTO_STEP);
|
||||
Mat depth_image_8U;
|
||||
depth_image.convertTo(depth_image_8U,CV_8UC3);
|
||||
// Mat im_color;
|
||||
// applyColorMap(depth_image_8U, im_color, COLORMAP_JET);
|
||||
|
||||
Mat color_image(Size(WIDTH, HEIGHT), CV_8UC3, (void *) color.get_data(), Mat::AUTO_STEP);
|
||||
|
||||
|
||||
cv::imshow("depth_image", depth_image);
|
||||
cv::imshow("color_image", color_image);
|
||||
if (waitKey(100) == 'q')break;
|
||||
|
||||
float dist_to_center = depth.get_distance(WIDTH / 2, HEIGHT / 2);
|
||||
|
||||
std::cout << "The camera is facing an object " << dist_to_center << " meters away \n";
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/19.
|
||||
//
|
||||
#include <rc_task/rcTaskManager.h>
|
||||
#include <rc_log/rclog.h>
|
||||
#include <zconf.h>
|
||||
#include <rc_network/rc_asny_tcp_client.h>
|
||||
#include <base/slog.hpp>
|
||||
#include <rc_task/rcMoveTask.h>
|
||||
#include <rc_task/rcRadarTask.h>
|
||||
#include <rc_task/rcNetworkTask.h>
|
||||
#include <rc_task/rcGyroTask.h>
|
||||
#include <rc_task/rcCVTask.h>
|
||||
#include <rc_task/rcWebStream.h>
|
||||
using namespace RC::Task;
|
||||
int main(int argc,char **argv){
|
||||
rc_DeviceInfo rcDeviceInfo;
|
||||
rcDeviceInfo.serial_port = "/dev/ttyS5";
|
||||
rcDeviceInfo.camera_index = 1;
|
||||
rcDeviceInfo.mapping = "./map.bin";
|
||||
rc_Thread robot_cv_control_module(boost::bind(run_cv_task, rcDeviceInfo));
|
||||
robot_cv_control_module.join();
|
||||
// sleep(10);
|
||||
return 0;
|
||||
}
|
@ -1,25 +1,9 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/16.
|
||||
//
|
||||
#include <pistache/endpoint.h>
|
||||
#include <pistache/http.h>
|
||||
#include <rc_network/rc_httpd.h>
|
||||
|
||||
using namespace Pistache;
|
||||
|
||||
struct HelloHandler : public Http::Handler {
|
||||
HTTP_PROTOTYPE(HelloHandler)
|
||||
void onRequest(const Http::Request&, Http::ResponseWriter writer) override{
|
||||
writer.send(Http::Code::Ok, "Hello, World!");
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Http::listenAndServe<HelloHandler>(Pistache::Address("*:9080"));
|
||||
return 0;
|
||||
}
|
||||
//int main(int argc, char **argv) {
|
||||
// RC::Network::Httpd::HttpdServer httpdServer;
|
||||
// httpdServer.start_server(9800);
|
||||
// return 1;
|
||||
//}
|
||||
int main(int argc, char **argv) {
|
||||
RC::Network::Httpd::HttpdServer httpdServer;
|
||||
httpdServer.start_server(9800);
|
||||
return 1;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/19.
|
||||
//
|
||||
int main(int argc,char **argv){
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/19.
|
||||
//
|
||||
int main(int argc,char **argv){
|
||||
|
||||
return 0;
|
||||
}
|
20
robot_client/src/sources/rc_test/rc_module_test_pistache.cpp
Normal file
20
robot_client/src/sources/rc_test/rc_module_test_pistache.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/16.
|
||||
//
|
||||
|
||||
|
||||
#include <pistache/endpoint.h>
|
||||
|
||||
using namespace Pistache;
|
||||
|
||||
struct HelloHandler : public Http::Handler {
|
||||
HTTP_PROTOTYPE(HelloHandler)
|
||||
void onRequest(const Http::Request&, Http::ResponseWriter writer) override{
|
||||
writer.send(Http::Code::Ok, "Hello, World!");
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Http::listenAndServe<HelloHandler>(Pistache::Address("*:9800"));
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#include <rc_network/rc_httpd_rest.h>
|
||||
using namespace RC::Network::Httpd;
|
||||
using namespace std;
|
||||
int main(int argc, char *argv[]) {
|
||||
int thr = 4;
|
||||
|
||||
|
||||
cout << "CPU核心数 = " << hardware_concurrency() << endl;
|
||||
cout << "Using " << thr << " threads" << endl;
|
||||
|
||||
rcHttpdRest rcHttpdRest(9800);
|
||||
|
||||
rcHttpdRest.init(thr);
|
||||
rcHttpdRest.start();
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
//
|
||||
// Created by Pulsar on 2020/5/17.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include <linux/input.h>
|
||||
int main(int argc,char **argv) {
|
||||
int buttons_fd;
|
||||
int key_value, i = 0, count;
|
||||
struct input_event ev_key;
|
||||
buttons_fd = open("/dev/input/event2", O_RDWR);
|
||||
if (buttons_fd < 0) {
|
||||
perror("open device buttons");
|
||||
exit(1);
|
||||
}
|
||||
for (;;) {
|
||||
count = read(buttons_fd, &ev_key, sizeof(struct input_event));
|
||||
for (i = 0; i < (int) count / sizeof(struct input_event); i++)
|
||||
if (EV_KEY == ev_key.type)
|
||||
printf("type:%d,code:%d,value:%d\n", ev_key.type, ev_key.code - 1, ev_key.value);
|
||||
if (EV_SYN == ev_key.type)
|
||||
printf("syn event\n\n");
|
||||
}
|
||||
close(buttons_fd);
|
||||
return 0;
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
//
|
||||
// Created by PulsarV on 18-5-14.
|
||||
//
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <rc_cv/rcCV.h>
|
||||
#include <vlc/vlc.h>
|
||||
#include <zconf.h>
|
||||
int main(){
|
||||
libvlc_instance_t *vlc;
|
||||
const char *url;
|
||||
const char *sout = "#transcode{vcodec=h264,vb=0,scale=0,acodec=mpga,ab=128,channels=2,samplerate=44100}:http{mux=ffmpeg{mux=flv},dst=:5555/test}";
|
||||
|
||||
const char *media_name = "Lei's test";
|
||||
|
||||
url = "/home/norse/WorkSpace/Robocar/test_data/All_Night.mp4";
|
||||
// url = "screen://";
|
||||
|
||||
|
||||
vlc = libvlc_new(0, NULL);
|
||||
// libvlc_media_new_location(vlc,url);
|
||||
libvlc_vlm_add_broadcast(vlc, media_name, url, sout, 0, NULL, true, false);
|
||||
libvlc_vlm_play_media(vlc, media_name);
|
||||
|
||||
sleep(30000);
|
||||
|
||||
libvlc_vlm_stop_media(vlc, media_name);
|
||||
libvlc_vlm_release(vlc);
|
||||
// cv::VideoCapture cap;
|
||||
// cap.open(0);
|
||||
// if (cap.isOpened()) {
|
||||
// while (true) {
|
||||
// cv::Mat frame, output;
|
||||
// cap >> frame;
|
||||
// RC::CV::detectLine(frame, &output);
|
||||
// cv::imshow("output", output);
|
||||
// if (cv::waitKey(100) == 'q')break;
|
||||
// }
|
||||
// }
|
||||
// cv::destroyAllWindows();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user