一、c++上位机与WiFi小车通讯
来源:互联网 发布:我知女人心阮琦 编辑:程序博客网 时间:2024/05/16 00:41
基于51单片机WiFi视频机器小车c++上位机开发
1、首先,单片机、WiFi模块组装完毕后,请确保电脑可以连接小车的WiFi信号。
2、建立c++ CRL项目。
3、配置opencv2.4X,
4、项目连接小车的WiFi视频地址,IP地址和端口
const string cameraAddress = "http://192.168.1.1:8080/?action=stream&type=.mjpg";
System::String^ controlip = "192.168.1.1";
System::String^ port = "2001";
System::String^ controlip = "192.168.1.1";
System::String^ port = "2001";
5、获取小车视频并转化为opencv
vcap.open(cameraAddress);
Mat frame;
vcap.read(frame);
6、与小车进行通讯并发送指令
IPAddress^ ips = IPAddress::Parse(controlip);
IPEndPoint^ ipe = gcnew IPEndPoint(ips, Convert::ToInt32(port));
Socket^ c = gcnew Socket(ipe->AddressFamily, SocketType::Stream, ProtocolType::Tcp);
c->Connect(ipe);
IPEndPoint^ ipe = gcnew IPEndPoint(ips, Convert::ToInt32(port));
Socket^ c = gcnew Socket(ipe->AddressFamily, SocketType::Stream, ProtocolType::Tcp);
c->Connect(ipe);
array<Byte>^ up = { 0xFF, 0x00, 0x02, 0x00, 0xFF };//向前
array<Byte>^ rcode = gcnew array<Byte>(100);
下面是源码:
// 小车追球test2.cpp: 主项目文件。
#include "stdafx.h"
#include "stdafx.h"
#include "opencv2/opencv.hpp"
//#include "conio.h"
//#include "cv.h"
#include "highgui.h"
//#include "cxcore.h"
#include "iostream"
#include "Windows.h"
#include "Xinput.h"
#using <System.dll>
using namespace System;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Text;
using namespace cv;
using namespace std;
CvCapture* capture = 0;
IplImage* image;
void Hough(IplImage*);
//int style = 0;//小车当前状态:1为停止,2位前进,3位后退,4位左转,5为右转
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
cvNamedWindow("camera", CV_WINDOW_AUTOSIZE);
cvMoveWindow("camera", 0, 0);
const string cameraAddress = "http://192.168.1.1:8080/?action=stream&type=.mjpg";
System::String^ controlip = "192.168.1.1";
System::String^ port = "2001";
VideoCapture vcap;
Mat frame;
if (!vcap.open(cameraAddress))
{
Console::WriteLine(L"ERRER");
return -1;
}
IPAddress^ ips = IPAddress::Parse(controlip);
IPEndPoint^ ipe = gcnew IPEndPoint(ips, Convert::ToInt32(port));
Socket^ c = gcnew Socket(ipe->AddressFamily, SocketType::Stream, ProtocolType::Tcp);
c->Connect(ipe);
array<Byte>^ stop = { 0xFF, 0x00, 0x00, 0x00, 0xFF };//停止
array<Byte>^ up = { 0xFF, 0x00, 0x02, 0x00, 0xFF };//向前
array<Byte>^ down = { 0xFF, 0x00, 0x01, 0x00, 0xFF };//向后
array<Byte>^ left = { 0xFF, 0x00, 0x03, 0x00, 0xFF };//左转
array<Byte>^ right = { 0xFF, 0x00, 0x04, 0x00, 0xFF };//右转
array<Byte>^ left_speed = { 0xFF, 0x02, 0x01, 0x09, 0xFF };//左侧速度为7
array<Byte>^ right_speed = { 0xFF, 0x02, 0x02, 0x04, 0xFF };//右侧速度为7
array<Byte>^ rcode = gcnew array<Byte>(100);
int i = 0;
while (c->Connected)
{
cvWaitKey(10);
vcap.read(frame);
//方向测试----------------------------------------------------------------------------------------------------------------------
i++;
if (i>100)
{
c->Send(stop, stop->Length, SocketFlags::None);//发送指令
}
else{
c->Send(up, up->Length, SocketFlags::None);//发送指令
}
//--------------------------------------------------------------------------------------------------------------------------------
imshow("camera", frame);
}
cvDestroyWindow("camera");
c->Close();
return 0;
}
#include "stdafx.h"
#include "stdafx.h"
#include "opencv2/opencv.hpp"
//#include "conio.h"
//#include "cv.h"
#include "highgui.h"
//#include "cxcore.h"
#include "iostream"
#include "Windows.h"
#include "Xinput.h"
#using <System.dll>
using namespace System;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Text;
using namespace cv;
using namespace std;
CvCapture* capture = 0;
IplImage* image;
void Hough(IplImage*);
//int style = 0;//小车当前状态:1为停止,2位前进,3位后退,4位左转,5为右转
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
cvNamedWindow("camera", CV_WINDOW_AUTOSIZE);
cvMoveWindow("camera", 0, 0);
const string cameraAddress = "http://192.168.1.1:8080/?action=stream&type=.mjpg";
System::String^ controlip = "192.168.1.1";
System::String^ port = "2001";
VideoCapture vcap;
Mat frame;
if (!vcap.open(cameraAddress))
{
Console::WriteLine(L"ERRER");
return -1;
}
IPAddress^ ips = IPAddress::Parse(controlip);
IPEndPoint^ ipe = gcnew IPEndPoint(ips, Convert::ToInt32(port));
Socket^ c = gcnew Socket(ipe->AddressFamily, SocketType::Stream, ProtocolType::Tcp);
c->Connect(ipe);
array<Byte>^ stop = { 0xFF, 0x00, 0x00, 0x00, 0xFF };//停止
array<Byte>^ up = { 0xFF, 0x00, 0x02, 0x00, 0xFF };//向前
array<Byte>^ down = { 0xFF, 0x00, 0x01, 0x00, 0xFF };//向后
array<Byte>^ left = { 0xFF, 0x00, 0x03, 0x00, 0xFF };//左转
array<Byte>^ right = { 0xFF, 0x00, 0x04, 0x00, 0xFF };//右转
array<Byte>^ left_speed = { 0xFF, 0x02, 0x01, 0x09, 0xFF };//左侧速度为7
array<Byte>^ right_speed = { 0xFF, 0x02, 0x02, 0x04, 0xFF };//右侧速度为7
array<Byte>^ rcode = gcnew array<Byte>(100);
int i = 0;
while (c->Connected)
{
cvWaitKey(10);
vcap.read(frame);
//方向测试----------------------------------------------------------------------------------------------------------------------
i++;
if (i>100)
{
c->Send(stop, stop->Length, SocketFlags::None);//发送指令
}
else{
c->Send(up, up->Length, SocketFlags::None);//发送指令
}
//--------------------------------------------------------------------------------------------------------------------------------
imshow("camera", frame);
}
cvDestroyWindow("camera");
c->Close();
return 0;
}
1 0
- 一、c++上位机与WiFi小车通讯
- 基于C#+51上位机通讯程序
- 上位机与PLC通讯及OPC数据采集实践一
- 智能小车七《上位机android》
- MX Component 上位机与三菱PLC通讯
- 机器人进阶学习(一)---基于stm32的底层搭建,与上位机通讯及base_control编写
- WiFi控制上位机软件
- WiFi通信上位机实现
- WiFi遥控小车(一):基于wicam模块的小车
- Siemens S7与上位监控软件通讯
- WiFi小车记录一:基本构思
- WIFI小车之旅(一)
- 基于VC++和MFC的上位机与PLC的通讯系统
- S7 PLC与 上位机之间可以采用TCP/IP,Socket通讯吗?
- 基于OPC 技术的上位机与S7-200 系列PLC通讯的实现
- STM32与上位机串口通讯的学习笔记(简明的数据帧设计方法)
- 基于Qt的wifi智能小车的制作(一)
- windows phone 7 与wifi小车的socket通信
- iOS 开发-教大家如何使用github客户端上传自己的代码到github网站
- Python爬linkedin——规模在1001-5000的瑞士公司(非官方API)
- 已经加载了类库,还是报错启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderList
- 指针函数与函数指针的区别
- python multiprocessing.Pipe() Queue 示例
- 一、c++上位机与WiFi小车通讯
- RT-Thread ---开启基于RTGUI的LCD显示功能(2)<编译测试>
- 我的博客——第一天。
- GC收集器
- 第十二章与Spring集成
- Yocto tips (16): Yocto 制作SDK分发Toolchain 脱离Yocto环境开发
- Python3爬取图片
- 输入框与scrollview的滑动冲突
- JSP基本语法