Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-controlserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenzhongjian
car-controlserver
Commits
3b8a2211
Commit
3b8a2211
authored
Dec 02, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入了坐标滤波器和优化了部分代码
parent
7313d8f8
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
120 additions
and
73 deletions
+120
-73
pthread_open.c
app/main/pthread_open.c
+2
-1
main
build/main
+0
-0
car0102_control.c
drivers/devicecontrol/car0102_control.c
+65
-48
pg0403_serial.c
drivers/devicecontrol/pg0403_serial.c
+2
-3
tank_common.c
drivers/devicecontrol/tank_common.c
+2
-0
gpio_control.c
drivers/gpio/gpio_control.c
+42
-14
audioplay.c
drivers/sensors/audioplay.c
+1
-1
tank_angle.h
drivers/sensors/tank_angle.h
+1
-1
delay.c
modules/delay/delay.c
+1
-1
http_consolepush.c
modules/http/http_consolepush.c
+1
-1
mqtt_init.c
modules/mqtt/mqtt_init.c
+2
-2
mqtt_init.h
modules/mqtt/mqtt_init.h
+1
-1
No files found.
app/main/pthread_open.c
View file @
3b8a2211
...
...
@@ -39,8 +39,9 @@ int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat,
//出现意外自动停止
void
*
thread_exit_time
(
void
*
arg
)
{
pg0403_serial_run
();
while
(
1
){
pg0403_serial_run
();
if
(
get_self_control_index
()
==
false
){
...
...
build/main
View file @
3b8a2211
No preview for this file type
drivers/devicecontrol/car0102_control.c
View file @
3b8a2211
...
...
@@ -110,59 +110,76 @@ void car0102_mode_2_back(unsigned char gval) {
}
void
car0102_mode_3_left
(
unsigned
char
gval
)
{
if
(
gval
<
45
)
{
int
b
=
7
;
if
(
gval
<
45
){
car0102_calculate_L_R
(
90
);
}
else
if
(
gval
<=
51
)
{
car0102_calculate_L_R
(
110
);
}
else
if
(
gval
<=
57
)
{
car0102_calculate_L_R
(
120
);
}
else
if
(
gval
<=
63
)
{
car0102_calculate_L_R
(
130
);
}
else
if
(
gval
<=
69
)
{
car0102_calculate_L_R
(
130
);
}
else
if
(
gval
<=
75
)
{
car0102_calculate_L_R
(
140
);
}
else
if
(
gval
<=
81
)
{
car0102_calculate_L_R
(
145
);
}
else
if
(
gval
<=
87
)
{
car0102_calculate_L_R
(
150
);
}
else
if
(
gval
<=
93
)
{
car0102_calculate_L_R
(
150
);
}
else
if
(
gval
<=
100
)
{
car0102_calculate_L_R
(
160
);
}
else
if
(
gval
<=
107
)
{
car0102_calculate_L_R
(
170
);
}
else
if
(
gval
<=
120
)
{
car0102_calculate_L_R
(
180
);
}
}
else
if
(
gval
<
70
){
car0102_calculate_L_R
(
50
+
gval
+
b
);
}
else
if
(
gval
>=
70
){
car0102_calculate_L_R
(
135
);
}
// if (gval < 45) {
// car0102_calculate_L_R(90);
// } else if (gval <= 51) {
// car0102_calculate_L_R(110);
// } else if (gval <= 57) {
// car0102_calculate_L_R(120);
// } else if (gval <= 63) {
// car0102_calculate_L_R(130);
// } else if (gval <= 69) {
// car0102_calculate_L_R(135);
// } else if (gval <= 75) {
// car0102_calculate_L_R(140);
// } else if (gval <= 81) {
// car0102_calculate_L_R(145);
// } else if (gval <= 87) {
// car0102_calculate_L_R(150);
// } else if (gval <= 93) {
// car0102_calculate_L_R(150);
// } else if (gval <= 100) {
// car0102_calculate_L_R(160);
// }else if (gval <= 107) {
// car0102_calculate_L_R(170);
// }else if (gval <= 120) {
// car0102_calculate_L_R(180);
// }
}
void
car0102_mode_4_right
(
unsigned
char
gval
)
{
if
(
gval
<
45
)
{
int
b
=
5
;
if
(
gval
<
45
){
car0102_calculate_L_R
(
90
);
}
else
if
(
gval
<=
51
)
{
car0102_calculate_L_R
(
70
);
}
else
if
(
gval
<=
57
)
{
car0102_calculate_L_R
(
66
);
}
else
if
(
gval
<=
63
)
{
car0102_calculate_L_R
(
62
);
}
else
if
(
gval
<=
69
)
{
car0102_calculate_L_R
(
55
);
}
else
if
(
gval
<=
75
)
{
car0102_calculate_L_R
(
45
);
}
else
if
(
gval
<=
81
)
{
car0102_calculate_L_R
(
40
);
}
else
if
(
gval
<=
87
)
{
car0102_calculate_L_R
(
30
);
}
else
if
(
gval
<=
93
)
{
car0102_calculate_L_R
(
30
);
}
else
if
(
gval
<=
100
)
{
car0102_calculate_L_R
(
20
);
}
else
if
(
gval
<=
107
)
{
car0102_calculate_L_R
(
10
);
}
else
if
(
gval
<=
120
)
{
car0102_calculate_L_R
(
0
);
}
}
else
if
(
gval
<
70
){
car0102_calculate_L_R
(
130
-
gval
-
b
);
}
else
if
(
gval
>=
70
){
car0102_calculate_L_R
(
135
);
}
// if (gval < 45) {
// car0102_calculate_L_R(90);
// } else if (gval <= 51) {
// car0102_calculate_L_R(70);
// } else if (gval <= 57) {
// car0102_calculate_L_R(66);
// } else if (gval <= 63) {
// car0102_calculate_L_R(62);
// } else if (gval <= 69) {
// car0102_calculate_L_R(55);
// } else if (gval <= 75) {
// car0102_calculate_L_R(45 );
// } else if (gval <= 81) {
// car0102_calculate_L_R(40);
// } else if (gval <= 87) {
// car0102_calculate_L_R(30);
// } else if (gval <= 93) {
// car0102_calculate_L_R(30);
// } else if (gval <= 100) {
// car0102_calculate_L_R(20);
// } else if (gval <= 107) {
// car0102_calculate_L_R(10);
// } else if (gval <= 120) {
// car0102_calculate_L_R(0);
// }
}
//车速度和转向引脚数值处理函数
...
...
drivers/devicecontrol/pg0403_serial.c
View file @
3b8a2211
...
...
@@ -352,10 +352,9 @@ int pg0403_serial_run(){
while
(
1
){
static
int
send_mqtt_count
=
0
;
int
n
=
read
(
pg_serial
.
fd
,
rx_buffer
,
sizeof
(
rx_buffer
));
if
(
n
>
0
)
process_serial_data
(
rx_buffer
,
n
);
else
delay_ms
(
100
);
process_serial_data
(
rx_buffer
,
n
);
if
(
send_mqtt_count
>
4
0
){
if
(
send_mqtt_count
>
5
0
){
pg0403_all_serial_send
();
send_mqtt_count
=
0
;
}
...
...
drivers/devicecontrol/tank_common.c
View file @
3b8a2211
...
...
@@ -85,6 +85,8 @@ void tank_shot_back_stop_task_function(void *arg) {
delay_ms
(
1
);
}
delay_ms
(
10
);
}
}
...
...
drivers/gpio/gpio_control.c
View file @
3b8a2211
...
...
@@ -146,44 +146,43 @@ int device_shoting_check(int pin,int val){
}
}
#define LIMIT_LIFT 1
#define LIMIT_RIGHT 2
static
int
limit_status
=
0
;
/*
* @brief 坦克限位线程函数*/
void
tank_angle_limit_function
(
void
*
arg_gpio
){
void
tank_angle_limit_function
(){
static
int
limit_log_count
=
0
;
if
(
arg_gpio
!=
NULL
)
{
free
(
arg_gpio
);
}
my_zlog_info
(
"limit task started."
);
while
(
1
){
int
limit_status
=
angle_limit
();
if
(
limit_status
==
1
)
{
limit_status
=
angle_limit
();
if
(
limit_status
==
LIMIT_LIFT
)
{
device_gpio_control
(
g_device_type
,
5
,
0
);
my_zlog_info
(
"lift limit stop"
);
}
else
if
(
limit_status
==
2
)
{
else
if
(
limit_status
==
LIMIT_RIGHT
)
{
device_gpio_control
(
g_device_type
,
7
,
0
);
my_zlog_info
(
"right limit stop"
);
}
else
if
(
limit_status
==
0
)
{
delay_ms
(
5
);
if
(
limit_status
==
0
)
{
limit_log_count
++
;
if
(
limit_log_count
>
=
4
00
){
if
(
limit_log_count
>
1
00
){
my_zlog_info
(
"limit stop"
);
limit_log_count
=
0
;
}
}
delay_ms
(
8
);
}
free
(
arg_gpio
);
}
/*角度限位线程池初始化*/
void
device_gpio_control_threadpoll_init
(){
int
*
arg_gpio
=
malloc
(
sizeof
(
int
));
my_zlog_info
(
"device_gpio_control_threadpoll_init start"
);
*
arg_gpio
=
2
;
g_pool_device_gpio_control_t
=
thread_pool_init
(
1
,
1
);
thread_pool_add_task
(
g_pool_device_gpio_control_t
,
tank_angle_limit_function
,
arg_gpio
);
thread_pool_add_task
(
g_pool_device_gpio_control_t
,
tank_angle_limit_function
,
NULL
);
}
/*设备拉低引脚结构体数组*/
...
...
@@ -475,6 +474,15 @@ void tank0202_pwm_value(int pin,int value) { //软件陪我们控制调速
softPwmWrite
(
pin
,
30
);
my_zlog_info
(
"pwm:%d"
,
pin
);
}
if
(
limit_status
==
LIMIT_LIFT
)
{
softPwmWrite
(
5
,
0
);
//device_gpio_control(g_device_type,5,0);
my_zlog_info
(
"lift limit stop"
);
}
else
if
(
limit_status
==
LIMIT_RIGHT
)
{
softPwmWrite
(
7
,
0
);
//device_gpio_control(g_device_type,7,0);
my_zlog_info
(
"right limit stop"
);
}
}
else
if
(
value
==
0
)
{
softPwmWrite
(
pin
,
0
);
...
...
@@ -500,6 +508,16 @@ void tank0203_pwm_value(int pin,int value) { //软件陪我们控制调速
softPwmWrite
(
pin
,
30
);
my_zlog_info
(
"pwm:%d"
,
pin
);
}
if
(
limit_status
==
LIMIT_LIFT
)
{
softPwmWrite
(
5
,
0
);
//device_gpio_control(g_device_type,5,0);
my_zlog_info
(
"lift limit stop"
);
}
else
if
(
limit_status
==
LIMIT_RIGHT
)
{
softPwmWrite
(
7
,
0
);
//device_gpio_control(g_device_type,7,0);
my_zlog_info
(
"right limit stop"
);
}
}
else
if
(
value
==
0
)
{
softPwmWrite
(
pin
,
0
);
...
...
@@ -531,6 +549,16 @@ void tank0204_pwm_value(int pin,int value){
softPwmWrite
(
pin
,
60
);
my_zlog_info
(
"pwm:%d"
,
pin
);
}
if
(
limit_status
==
LIMIT_LIFT
)
{
softPwmWrite
(
7
,
0
);
//device_gpio_control(g_device_type,5,0);
my_zlog_info
(
"lift limit stop"
);
}
else
if
(
limit_status
==
LIMIT_RIGHT
)
{
softPwmWrite
(
5
,
0
);
//device_gpio_control(g_device_type,7,0);
my_zlog_info
(
"right limit stop"
);
}
}
else
if
(
value
==
0
)
{
if
(
pin
==
5
)
{
...
...
drivers/sensors/audioplay.c
View file @
3b8a2211
...
...
@@ -113,7 +113,7 @@ void audioplay_cycle(){
video_tts_play
();
delay_
us
(
8
00
);
delay_
ms
(
1
00
);
}
}
...
...
drivers/sensors/tank_angle.h
View file @
3b8a2211
...
...
@@ -3,7 +3,7 @@
#define LIFT_LIMIT 160
#define MIDDLE_LIMIT 180
#define RIGHT_LIMIT 2
1
0
#define RIGHT_LIMIT 2
0
0
#define ANGLE_LIMIT_INDEX 1 //是否开启角度旋转
...
...
modules/delay/delay.c
View file @
3b8a2211
#include"common.h"
#include "delay.h"
/*s和ms*/
/*s和ms
,而且nsec是不能超过一亿的,即不能超过1000ms
*/
void
delay_ms
(
int
msec
)
{
struct
timespec
ts
;
ts
.
tv_sec
=
0
;
// 秒
...
...
modules/http/http_consolepush.c
View file @
3b8a2211
...
...
@@ -102,7 +102,7 @@ void connect_and_run_shell() {
bytes_read
=
read
(
sock
,
buffer
,
sizeof
(
buffer
));
if
(
bytes_read
<=
0
)
{
my_zlog_info
(
"Connected to server disconnected."
);
fprintf
(
stderr
,
"Server disconnected.
\n
"
);
my_zlog_info
(
"Server disconnected.
"
);
break
;
// 服务器断开
}
// 将命令写入 Shell
...
...
modules/mqtt/mqtt_init.c
View file @
3b8a2211
...
...
@@ -246,7 +246,7 @@ int mqtt_cycle() {//非阻塞型
my_zlog_info
(
"MQTT 异步监控线程启动"
);
int
check_interval
=
30
000
;
// 30秒检查一次,减少日志频率
int
check_interval
=
30
;
// 30秒检查一次,减少日志频率
while
(
1
)
{
// 简单的存活检查,记录连接状态
...
...
@@ -265,7 +265,7 @@ int mqtt_cycle() {//非阻塞型
my_zlog_info
(
"MQTT 连接状态: %d/%d 活跃"
,
active_count
,
total_count
);
last_active_count
=
active_count
;
}
delay_
m
s
(
check_interval
);
delay_s
(
check_interval
);
}
return
0
;
...
...
modules/mqtt/mqtt_init.h
View file @
3b8a2211
...
...
@@ -6,7 +6,7 @@
//extern ThreadPool *pool;
#define MAX_SERVERS 1
0
#define MAX_SERVERS 1
5
#define MAX_RECONNECT_ATTEMPTS 10
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment