3712 views|1 replies

654

Posts

26

Resources
The OP
 

22 "Wanli" Raspberry Pi car - mobile phone remote control motor rotation [Copy link]

 This post was last edited by lb8820265 on 2022-1-30 11:55

After struggling for a long time on how to accurately control the wheel speed, I finally decided to use open-loop control without calibrating the speed.

We have introduced the motor control and the UDP communication between the mobile phone and the Raspberry Pi . By combining these two functions and formulating a communication protocol, we can use the mobile phone to control the motor speed. The goal is broken down into three parts: the communication protocol, the APP host computer, and the Raspberry Pi car.

Communication Protocol

Before writing the APP and car code, it is important to understand the communication protocol between the two. This does not refer to the UDP described above, but to the specific meaning of the control data sent by the mobile phone. Since the ultimate goal is to control the speed of the four wheels of the car, it can be simply represented by 4 bytes. Each byte represents the speed of a wheel. The value range is from -100 to 100. Negative numbers represent reverse rotation, and positive numbers represent forward rotation. The larger the value, the faster the speed. In addition, one byte is used as a backup, for a total of five bytes.

Location

Byte0

Byte1

Byte2

Byte3

meaning

M1 Speed

M2 Speed

M3 Speed

M4 Speed

scope

-100~100

-100~100

-100~100

-100~100

APP host computer

The main function of the APP host computer is to connect to the Raspberry Pi and send control data. I mainly refer to my previous open source car project for the production of the host computer . Over the past so many years, AS software has changed too much and many libraries are no longer supported, but this is not a problem. Use AS4.1 to create a new "lb_Wanli_Car" project, integrate the previous UDP communication project, add a joystick and four drag bars and four edit boxes to display the control amount. The effect diagram and source code are detailed at the end.

The joystick is not used for the time being. This time, a drag bar is used to control the motor speed. A timer is added. It is turned on when the connection is successful and turned off when the connection is disconnected. The value of the drag bar is read every 100ms and sent to the Raspberry Pi.

Raspberry Pi Car

The Raspberry Pi car is mainly responsible for data reception and motor control, that is, integrating motor control with UDP communication. Modifications are made based on the previous four-wheel control speed. A new Car_Control project is created, and the Socket_UDP.cpp file is added. A new thread is opened in the main function to specifically receive data. The received data is parsed in the receiving function and the motor is controlled.

The parsing of data requires extra attention. The value range is -100~100, but there is no negative number for char type data. However, data greater than 128 can be considered a negative number. Subtracting this number from 256 is equivalent to taking the absolute value. The processing code is as follows.

void Data_Process(char * Data){
	float gen=2.55;
	if(Data[0]>128){
		M1.Motor_out=(256-Data[0])*gen;
		M1.Direction=2;
	}else{
		M1.Motor_out=Data[0];
		M1.Direction=1;
	}
	if(Data[1]>128){
		M2.Motor_out=(256-Data[1])*gen;
		M2.Direction=2;
	}else{
		M2.Motor_out=Data[1];
		M2.Direction=1;
	}
	if(Data[2]>128){
		M3.Motor_out=(256-Data[2])*gen;
		M3.Direction=2;
	}else{
		M3.Motor_out=Data[2];
		M3.Direction=1;
	}
	if(Data[3]>128){
		M4.Motor_out=(256-Data[3])*gen;
		M4.Direction=2;
	}else{
		M4.Motor_out=Data[3];
		M4.Direction=1;
	}
}

Operation effect

First, connect the hardware and run Car_Control on the Raspberry Pi.

Open the APP and connect the Raspberry Pi on the connection interface. Drag the drag bar on the control interface to control the motor, and you can achieve different speeds and forward and reverse control.

[attach]586548[/attach ]

Now it is possible to use a mobile phone to control the rotation of four motors, but the car uses a Nam wheel, so it is still not easy to make the car move.

Source code

GitHub:

链接已隐藏,如需查看请登录或者注册

链接已隐藏,如需查看请登录或者注册

Gitee:

链接已隐藏,如需查看请登录或者注册

链接已隐藏,如需查看请登录或者注册

image-20220130114141-2.jpeg (163.62 KB, downloads: 0)

image-20220130114141-2.jpeg
This post is from Innovation Lab

Latest reply

Summary of "Wanli" Raspberry Pi car: lb8820265's "Wanli" Raspberry Pi car open source sharing - DIY/Open Source Hardware Zone - Electronic Engineering World - Forum (eeworld.com.cn) Table of contents: "Wanli" Raspberry Pi car launched 1. “Wanli” Raspberry Pi car - Establishing a project warehouse 2. "Wanli" Raspberry Pi car - Python learning (using Thonny) 3. "Wanli" Raspberry Pi car - Python learning (timing task) 4. "Wanli" Raspberry Pi car - C++ learning (compile and run, use geany) 5. "Ten Thousand Miles" Raspberry Pi Car - WiringPi Learning (Delay and Thread Simulation Timer) 6. "Wanli" Raspberry Pi car - wiringPi learning (PWM and external interrupt simulation timer) 7. "Ten Thousand Miles" Raspberry Pi Car——RPi.GPIO Learning (PWM and External Interrupt Simulation Timer) 8. "Wanli" Raspberry Pi car - socket learning (local communication) 9. "Ten Thousand Miles" Raspberry Pi Car - Socket Learning (TCP Two-Machine Communication) 10. "Ten Thousand Miles" Raspberry Pi Car - Socket Learning (UDP Two-Machine Communication) 11. "Wanli" Raspberry Pi car - socket learning (sent from Android) 12 "Wanli" Raspberry Pi car - socket learning (Android sending and receiving) 13. "Wanli" Raspberry Pi Car - Accessories Preparation 14 "Wanli" Raspberry Pi car - motor drive learning 15 "Wanli" Raspberry Pi car - photoelectric encoder learning (forward and reverse judgment) 16. "Wanli" Raspberry Pi car - photoelectric encoder learning (obtaining speed) 17 "Ten Thousand Miles" Raspberry Pi Car——VSCode Learning (Compiling and Debugging) 18. "Ten Thousand Miles" Raspberry Pi Car——Makefile Learning 19 "Ten Thousand Miles" Raspberry Pi Car——VSCode Learning (Multiple C File Link Debugging) 20 "Million Miles" Raspberry Pi Car - Motor Control Learning (Control Speed) 21. "Wanli" Raspberry Pi car - motor control learning (4-wheel speed control) 22. "Wanli" Raspberry Pi car - mobile phone remote control motor rotation 23 "Wanli" Raspberry Pi car - connected to Raspberry Pi without screen 24 "Millions" Raspberry Pi Car - Bullseye Benchmark Test of Raspberry Pi 64-bit System 25 "Million Miles" Raspberry Pi Car - Nam Wheel Control 26 "Wanli" Raspberry Pi car - program startup 27 "Ten Thousand Miles" Raspberry Pi Car - Fix and Get the Raspberry Pi IP Address 28 "Wanli" Raspberry Pi car - car assembly 29 "Wanli" Raspberry Pi car - straight-driving deviation problem and new control mode 30. "Wanli" Raspberry Pi car - Phase 1 completed demonstration (introduction from scratch)   Details Published on 2022-3-21 13:37
Personal signatureQQ:252669569
 
 

1w

Posts

204

Resources
From 2
 

Summary of "Wanli" Raspberry Pi car:

lb8820265's "Wanli" Raspberry Pi car open source sharing - DIY/Open Source Hardware Zone - Electronic Engineering World - Forum (eeworld.com.cn)

Table of contents:

"Wanli" Raspberry Pi car launched

1. “Wanli” Raspberry Pi car - Establishing a project warehouse

2. "Wanli" Raspberry Pi car - Python learning (using Thonny)

3. "Wanli" Raspberry Pi car - Python learning (timing task)

4. "Wanli" Raspberry Pi car - C++ learning (compile and run, use geany)

5. "Ten Thousand Miles" Raspberry Pi Car - WiringPi Learning (Delay and Thread Simulation Timer)

6. "Wanli" Raspberry Pi car - wiringPi learning (PWM and external interrupt simulation timer)

7. "Ten Thousand Miles" Raspberry Pi Car——RPi.GPIO Learning (PWM and External Interrupt Simulation Timer)

8. "Wanli" Raspberry Pi car - socket learning (local communication)

9. "Ten Thousand Miles" Raspberry Pi Car - Socket Learning (TCP Two-Machine Communication)

10. "Ten Thousand Miles" Raspberry Pi Car - Socket Learning (UDP Two-Machine Communication)

11. "Wanli" Raspberry Pi car - socket learning (sent from Android)

12 "Wanli" Raspberry Pi car - socket learning (Android sending and receiving)

13. "Wanli" Raspberry Pi Car - Accessories Preparation

14 "Wanli" Raspberry Pi car - motor drive learning

15 "Wanli" Raspberry Pi car - photoelectric encoder learning (forward and reverse judgment)

16. "Wanli" Raspberry Pi car - photoelectric encoder learning (obtaining speed)

17 "Ten Thousand Miles" Raspberry Pi Car——VSCode Learning (Compiling and Debugging)

18. "Ten Thousand Miles" Raspberry Pi Car——Makefile Learning

19 "Ten Thousand Miles" Raspberry Pi Car——VSCode Learning (Multiple C File Link Debugging)

20 "Million Miles" Raspberry Pi Car - Motor Control Learning (Control Speed)

21. "Wanli" Raspberry Pi car - motor control learning (4-wheel speed control)
22. "Wanli" Raspberry Pi car - mobile phone remote control motor rotation

23 "Wanli" Raspberry Pi car - connected to Raspberry Pi without screen

24 "Millions" Raspberry Pi Car - Bullseye Benchmark Test of Raspberry Pi 64-bit System

25 "Million Miles" Raspberry Pi Car - Nam Wheel Control

26 "Wanli" Raspberry Pi car - program startup

27 "Ten Thousand Miles" Raspberry Pi Car - Fix and Get the Raspberry Pi IP Address

28 "Wanli" Raspberry Pi car - car assembly

29 "Wanli" Raspberry Pi car - straight-driving deviation problem and new control mode

30. "Wanli" Raspberry Pi car - Phase 1 completed demonstration (introduction from scratch)

This post is from Innovation Lab
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
Personal signature

玩板看这里:

http://en.eeworld.com/bbs/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!

 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list