The instructions of robot car control platform API

Data Driven Engine Command Engine.dll

The engine must be initialized before use it. I have initialized the engine as an instance of RobotEngine2. The following are based on this instance to introduce the calling of various functions.

 Function description

  1. public IPEndPoint IPE {get; set;}

Role: attribute constructor

Parameters: an instance of IP End Point

Routine:

ips = IP Address.Parse(control IP.To String());

ipe = new IP End Point(ips, Convert.ToInt32(port.To String()));

RobotEngine2.IPE = ipe;

  1. public Socket SOCKET {get; set;}

Role: attribute constructor

Parameters: Socket instance

Routine:

socket = new Socket(Address Family.Inter Network, Socket Type.Stream, Protocol Type.Tcp);

Robot Engine2.SOCKET = socket;

  1. public byte[] CreateData(byte type, byte cmd, byte data);

Role: build data package

Parameters: type: type bit, cmd: command bit, data: data bit

Return value: return a 5-bit byte format data packet, the header and the end of the packet are both FF, no parity bit

Routine:

byte [] data = Create Data(0x01, 0x02, 0x03);

The returned data value is: FF 01 02 03 FF

  1. public void DrawSignal(int signalType, Graphics g, int x, int y, int PenWidth);

Function: Generate a crosshair or circular crosshair on the specified control

Parameters: singalType: crosshair type, 0 is cross, 1 is circle; g: PaintEventArgs.Graphics value of the control; x: control length; y: control width; PenWidth: pen thickness

Routine:

private void camera Window_Paint(object sender, PaintEventArgs e)

{,

RobotEngine2.DrawSignal(signalType,e.Graphics,this.cameraWindow.Width,this.cameraWindow.Height,2);

}

This function must be run in the Paint event of the control so that it can be called every time when it is redrawn.

  1. public byte[] HexStringToByteArray(string s);

Function: Convert a character string to a data packet in byte [] format

Parameters: string format string, an even-digit string accord with hexadecimal format

Return value: byte [] format packet

Routine:

byte [] data= HexStringToByteArray("FF000100FF");

The return data value is: FF 00 01 00 FF

  1. public void SendCMD(int controlType, byte[] byteData, SerialPort comm);

Role: overload function, send byte data packet format command

Parameters: controlType: type, 0 is WIFI mode, 1 is Bluetooth mode; byteData: byte[] format data packet, comm: Bluetooth serial port, SerialPort type.

Routine:

byteData = CreateData("FF000100FF");

comm=this.SerialPort1;

RobotEngine2.SendCMD(0, byteData, comm);

This program will send byteData data packets to the designated socket in WIFI mode;

byteData = CreateData("FF000100FF");

comm=this.SerialPort1;

public void SendCMD(1, byteData, comm);

This program will send byteData packets to the designated serial port comm in Bluetooth mode

  1. public void SendCMD(int controlType, string CMD_Custom, Serial Port comm);

Role: overload function, send format command of string data packet

 Parameters: control Type: type, 0 is WIFI mode, 1 is Bluetooth mode; CMD_Custom: string format data packet, comm: Bluetooth serial port, Serial Port type.

Routine:

String S="FF000100FF";

comm=this.SerialPort1;

RobotEngine2.Send CMD(0, s, comm);

This program will send the “S “ data string to the designated socket in WIFI mode;

String S="FF000100FF";

comm=this.SerialPort1;

RobotEngine2.Send CMD(1, s, comm);

This program will send the “S” data string to the designated serial port comm in Bluetooth mode

  1. public void SendDataIn Comm(Serial Port comm, byte[] data);

Role: Overload function, used to send byte format data packet directly from Bluetooth serial port

Parameters: comm: serial port instance of Serial Port type, data packet in data:byte[] format

Routine:

comm=this.SerialPort1;

data = Create Data("FF000100FF");

RobotEngine2.Send Data In Comm(Serial Port comm, byte[] data);

This program sends the data packet data in byte format from the designated serial port comm (SerialPort1).

  1. public void SendData In Comm(Serial Port comm, string data);

 Role: overloaded function, used to send string format data directly from the Bluetooth serial port

Parameters: comm: serial port instance of Serial Port type, data packet in data:byte[] format

Routine: comm=this. SerialPort1; RobotEngine2.Send Data In Comm(Serial Port comm, “FF000100FF”);

This program sends out the data string in string format from the designated serial port comm (SerialPort1).

  1. public void SendHeart CMD(int control Type, Serial Port comm);

Function: Send a heartbeat packet each 10S, to maintain a long-term connection with the server.

Parameters: control Type: type, 0 is WIFI mode, 1 is Bluetooth mode, comm: Bluetooth serial port instance of Serial Port type Routine: comm=this. SerialPort1; RobotEngine2. Send Heart CMD (0, comm);

The program will send a heartbeat packet FFEFEFEEFF to the WIFI channel every 10 seconds

  1. public bool SocketConnect();

Function: Socket connection function, connect to the routing server through WIFI, the connection is asynchronous callback.

Parameter: The function parameter is special, and its connection needs a socket. The socket comes from the attribute constructor SOCKET, so before calling this parameter, complete the instantiation of the socket, and refer to function 2 to assign it to the SOCKET attribute.

Return value: The function returns a bool value, true if the connection is successful, false if it fails.

Routine:

Bool ret;

ret = RobotEngine2.Socket Connect();

Execute this section of the program, if the connection is successful WIFI routing, return true, otherwise false

  1. public void TakePhoto(Bitmap snapshot, string RootPath, string FileName);

Function: The camera function is used to take photos on the control platform and save them in the Root Path+File Name path in BMP format.

Parameters: snapshot: the bitmap format object of the current video window; RootPath: the path where the photo is saved; File Name: the name of the photo file.

Routine:

RobotEngine2.Take Photo(camera Window.Camera.Last Frame, Image Path, Create Picture File());

Robot carSmart robot car

Lascia un commento

Tutti i commenti vengono moderati prima della pubblicazione