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
634d5df3
Commit
634d5df3
authored
Sep 09, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入了开炮后再退后
parent
56071c38
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
42 deletions
+47
-42
CMakeLists.txt
CMakeLists.txt
+1
-1
main
build/main
+0
-0
tank_common.c
drivers/devicecontrol/tank_common.c
+30
-30
tank_common.h
drivers/devicecontrol/tank_common.h
+3
-0
gpio_control.c
drivers/gpio/gpio_control.c
+10
-11
gpio_control.h
drivers/gpio/gpio_control.h
+3
-0
No files found.
CMakeLists.txt
View file @
634d5df3
cmake_minimum_required
(
VERSION 3.10
)
project
(
car
VERSION 1.2.1
1
VERSION 1.2.1
2
LANGUAGES C
)
...
...
build/main
View file @
634d5df3
No preview for this file type
drivers/devicecontrol/tank_common.c
View file @
634d5df3
...
...
@@ -9,8 +9,8 @@ int tank_shot_back_stop(unsigned char pin,unsigned char val);
const
tank_common_back
*
g_tank_common_config_t
=
NULL
;
long
long
shot_device_time_start
=
0
;
long
long
shot_device_time_end
=
0
;
int
g_tank_shot_index
=
0
;
//状态机,用于状态机,坦克接收射击倒退状态机全局变量
int
g_tank_shot_index_cool
=
1
;
//状态机,用于冷却状态机,坦克接收射击倒退状态机全局变量
/*击打后退速度设置,混空模式下为单路,单独模式下为双路控制,后续需要优化*/
void
tank_shot_back
(
unsigned
char
gval
)
{
...
...
@@ -46,24 +46,24 @@ void tank_shot_back(unsigned char gval) {
const
tank_common_back
tank_common_config_t
[]
=
{
{
.
device_id
=
DEVICE_TANK0202
,
.
back_time
=
25
,
//后退多少ms
.
back_interval_back
=
300
,
//间隔多少ms才能再次使用
.
shot_back_speed
=
8
0
,
.
back_time
=
30
,
//后退多少ms
.
back_interval_back
=
1000
,
//间隔多少次才能再次使用,一次等于5ms
.
shot_back_speed
=
9
0
,
.
shot_back
=
tank_shot_back_stop
},
{
.
device_id
=
DEVICE_TANK0203
,
.
back_time
=
25
,
//后退多少ms
.
back_interval_back
=
300
,
//间隔多少ms才能再次使用
.
shot_back_speed
=
8
0
,
.
back_time
=
30
,
//后退多少ms
.
back_interval_back
=
1000
,
//间隔多少次才能再次使用,一次等于5ms
.
shot_back_speed
=
9
0
,
.
shot_back
=
tank_shot_back_stop
},
{
.
device_id
=
DEVICE_TANK0204
,
.
back_time
=
25
,
//后退多少ms
.
back_interval_back
=
300
,
//间隔多少ms才能再次使用
.
shot_back_speed
=
8
0
,
.
back_time
=
30
,
//后退多少ms
.
back_interval_back
=
1000
,
//间隔多少次才能再次使用,一次等于5ms
.
shot_back_speed
=
9
0
,
.
shot_back
=
tank_shot_back_stop
},
...
...
@@ -93,17 +93,19 @@ void tank_shot_back_stop_task_function(void *arg) {
// }
// }else tank_shot_back(0);
//下面一部分为射击后按时间后退
long
long
interval
=
shot_device_time_start
-
shot_device_time_end
;
if
(
g_device_delay_back_count
>
g_tank_common_config_t
->
back_time
&&
g_device_delay_back_count
<
(
g_tank_common_config_t
->
back_time
+
30
))
tank_shot_back
(
0
);
if
(
interval
>
g_tank_common_config_t
->
back_interval_back
){
if
(
g_device_delay_back_count
<=
g_tank_common_config_t
->
back_time
)
{
tank_shot_back
(
g_tank_common_config_t
->
shot_back_speed
);
my_zlog_debug
(
"操作耗时: %lld 毫秒"
,
interval
);
}
if
(
g_device_delay_back_count
<=
g_tank_common_config_t
->
back_time
)
{
tank_shot_back
(
g_tank_common_config_t
->
shot_back_speed
);
my_zlog_debug
(
"击打成功"
);
}
else
if
(
g_device_delay_back_count
>
g_tank_common_config_t
->
back_time
&&
g_device_delay_back_count
<
(
g_tank_common_config_t
->
back_time
+
30
)){
tank_shot_back
(
0
);
}
else
if
(
g_device_delay_back_count
>
g_tank_common_config_t
->
back_interval_back
){
g_tank_shot_index
=
1
;
}
else
{
delay_ms
(
1
);
}
}
...
...
@@ -122,8 +124,7 @@ void tank_shot_pthrpoll_task_init(){
/*坦克后退射击*/
int
tank_shot_back_stop
(
unsigned
char
pin
,
unsigned
char
val
){
static
int
shot_count
=
0
;
shot_device_time_start
=
get_current_time_millis
();
if
(
pin
!=
27
){
my_zlog_debug
(
"非27引脚"
);
return
1
;
...
...
@@ -131,20 +132,19 @@ int tank_shot_back_stop(unsigned char pin,unsigned char val){
if
(
val
==
0
)
{
tank_shot_back
(
0
);
shot_count
=
2
;
}
if
(
val
!=
0
)
{
if
(
shot_count
==
0
){
if
(
g_tank_shot_index
==
0
){
tank_shot_pthrpoll_task_init
();
shot_count
=
1
;
g_tank_shot_index
=
1
;
}
shot_count
=
1
;
if
(
shot_count
==
1
){
if
(
g_tank_shot_index
==
1
&&
g_tank_shot_index_cool
==
0
){
g_device_delay_back_count
=
0
;
g_tank_shot_index
=
2
;
g_tank_shot_index_cool
=
1
;
}
}
shot_device_time_end
=
get_current_time_millis
();
}
/*销毁坦克使用的线程池,让其正常销毁,只有在tank相关设备号下才有用,最后销毁都会到device——common.h中*/
...
...
drivers/devicecontrol/tank_common.h
View file @
634d5df3
...
...
@@ -17,4 +17,6 @@ void tank_shot_stop_control(int device_id,unsigned char pin,unsigned char val);
/*关闭线程*/
void
tank_thread_close
();
extern
int
g_tank_shot_index_cool
;
#endif
\ No newline at end of file
drivers/gpio/gpio_control.c
View file @
634d5df3
...
...
@@ -34,14 +34,14 @@ uint64_t g_tank_shot_ms=1000; //射击时间
TankFireControl
g_device_shot_t
;
// 真正的结构体变量
/*获取时间戳函数*/
uint64_t
get_shot_timestamp_ms
()
{
struct
timeval
tv
;
if
(
gettimeofday
(
&
tv
,
NULL
)
==
-
1
)
{
my_zlog_error
(
"gettimeofday failed"
);
return
0
;
}
return
(
uint64_t
)
tv
.
tv_sec
*
1000
+
tv
.
tv_usec
/
1000
;
}
//
uint64_t get_shot_timestamp_ms() {
//
struct timeval tv;
//
if (gettimeofday(&tv, NULL) == -1) {
//
my_zlog_error("gettimeofday failed");
//
return 0;
//
}
//
return (uint64_t)tv.tv_sec * 1000 + tv.tv_usec / 1000;
//
}
/**
* @brief 初始化坦克射击控制器
...
...
@@ -72,15 +72,13 @@ int device_shot_cooling_init(){
return
0
;
}
/**
* @brief 检查坦克射击状态
* @param this 控制器指针
* @return 0=允许射击, -1=禁止射击(冷却中或射击中)
*/
int
device_fire_check
(
TankFireControl
*
this
)
{
uint64_t
current_time
=
get_
shot_timestamp_m
s
();
// 假设已实现此函数
uint64_t
current_time
=
get_
current_time_milli
s
();
// 假设已实现此函数
switch
(
this
->
state
)
{
case
TANK_STATE_READY
:
...
...
@@ -99,6 +97,7 @@ int device_fire_check(TankFireControl* this) {
my_zlog_info
(
"shotend,cooling"
);
this
->
last_shot_end_time
=
current_time
;
this
->
state
=
TANK_STATE_COOLDOWN
;
g_tank_shot_index_cool
=
0
;
return
-
1
;
}
my_zlog_info
(
"shot continue"
);
...
...
drivers/gpio/gpio_control.h
View file @
634d5df3
...
...
@@ -31,5 +31,7 @@ void device_gpio_control(int device_id,int pin,int val);
int
device_shot_cooling_init
();
extern
ThreadPool_t
*
g_pool_device_gpio_control_t
;
extern
int
g_tank_shot_index
;
#endif
\ No newline at end of file
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