Commit f3dd98fa authored by 957dd's avatar 957dd

加入了坦克发射会后退一瞬间

parent e1da35d4
log log
deviceback deviceback
loghttp loghttp
Deviceld.txt Deviceld.txt
\ No newline at end of file build/CMakeFiles
build/cmake_install.cmake
build/CMakeCache.txt
build/CTestTestfile.cmake
\ No newline at end of file
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(DeviceControlSystem project(DeviceControlSystem
VERSION 1.1.1 VERSION 1.1.2
LANGUAGES C LANGUAGES C
) )
......
...@@ -122,7 +122,7 @@ CMAKE_PROJECT_HOMEPAGE_URL:STATIC= ...@@ -122,7 +122,7 @@ CMAKE_PROJECT_HOMEPAGE_URL:STATIC=
CMAKE_PROJECT_NAME:STATIC=DeviceControlSystem CMAKE_PROJECT_NAME:STATIC=DeviceControlSystem
//Value Computed by CMake //Value Computed by CMake
CMAKE_PROJECT_VERSION:STATIC=1.1.1 CMAKE_PROJECT_VERSION:STATIC=1.1.2
//Value Computed by CMake //Value Computed by CMake
CMAKE_PROJECT_VERSION_MAJOR:STATIC=1 CMAKE_PROJECT_VERSION_MAJOR:STATIC=1
...@@ -131,7 +131,7 @@ CMAKE_PROJECT_VERSION_MAJOR:STATIC=1 ...@@ -131,7 +131,7 @@ CMAKE_PROJECT_VERSION_MAJOR:STATIC=1
CMAKE_PROJECT_VERSION_MINOR:STATIC=1 CMAKE_PROJECT_VERSION_MINOR:STATIC=1
//Value Computed by CMake //Value Computed by CMake
CMAKE_PROJECT_VERSION_PATCH:STATIC=1 CMAKE_PROJECT_VERSION_PATCH:STATIC=2
//Value Computed by CMake //Value Computed by CMake
CMAKE_PROJECT_VERSION_TWEAK:STATIC= CMAKE_PROJECT_VERSION_TWEAK:STATIC=
......
...@@ -3009,6 +3009,9 @@ CMakeFiles/main.dir/system/gpio/gpio_common.c.o ...@@ -3009,6 +3009,9 @@ CMakeFiles/main.dir/system/gpio/gpio_common.c.o
/home/orangepi/car/master/include/delay.h /home/orangepi/car/master/include/delay.h
/home/orangepi/car/master/include/softiic.h /home/orangepi/car/master/include/softiic.h
/home/orangepi/car/master/system/gpio/gpio_common.h /home/orangepi/car/master/system/gpio/gpio_common.h
/home/orangepi/car/master/include/mqtt.h
/usr/include/mosquitto.h
/usr/include/cjson/cJSON.h
/home/orangepi/car/master/include/request.h /home/orangepi/car/master/include/request.h
/home/orangepi/car/master/include/common.h /home/orangepi/car/master/include/common.h
...@@ -3622,6 +3625,8 @@ CMakeFiles/main.dir/system/gpio/gpio_pwm_tank0202.c.o ...@@ -3622,6 +3625,8 @@ CMakeFiles/main.dir/system/gpio/gpio_pwm_tank0202.c.o
/home/orangepi/car/master/include/log.h /home/orangepi/car/master/include/log.h
/home/orangepi/car/master/include/delay.h /home/orangepi/car/master/include/delay.h
/home/orangepi/car/master/include/softiic.h /home/orangepi/car/master/include/softiic.h
/home/orangepi/car/master/include/pthrpoll.h
/home/orangepi/car/master/include/common.h
/home/orangepi/car/master/system/gpio/gpio_pwm_tank0202.h /home/orangepi/car/master/system/gpio/gpio_pwm_tank0202.h
CMakeFiles/main.dir/system/sensor/INA226.c.o CMakeFiles/main.dir/system/sensor/INA226.c.o
......
...@@ -2990,6 +2990,9 @@ CMakeFiles/main.dir/system/gpio/gpio_common.c.o: ../system/gpio/gpio_common.c \ ...@@ -2990,6 +2990,9 @@ CMakeFiles/main.dir/system/gpio/gpio_common.c.o: ../system/gpio/gpio_common.c \
../include/delay.h \ ../include/delay.h \
../include/softiic.h \ ../include/softiic.h \
../system/gpio/gpio_common.h \ ../system/gpio/gpio_common.h \
../include/mqtt.h \
/usr/include/mosquitto.h \
/usr/include/cjson/cJSON.h \
../include/request.h \ ../include/request.h \
../include/common.h ../include/common.h
...@@ -3599,6 +3602,8 @@ CMakeFiles/main.dir/system/gpio/gpio_pwm_tank0202.c.o: ../system/gpio/gpio_pwm_t ...@@ -3599,6 +3602,8 @@ CMakeFiles/main.dir/system/gpio/gpio_pwm_tank0202.c.o: ../system/gpio/gpio_pwm_t
../include/log.h \ ../include/log.h \
../include/delay.h \ ../include/delay.h \
../include/softiic.h \ ../include/softiic.h \
../include/pthrpoll.h \
../include/common.h \
../system/gpio/gpio_pwm_tank0202.h ../system/gpio/gpio_pwm_tank0202.h
CMakeFiles/main.dir/system/sensor/INA226.c.o: ../system/sensor/INA226.c \ CMakeFiles/main.dir/system/sensor/INA226.c.o: ../system/sensor/INA226.c \
......
...@@ -131,5 +131,7 @@ CMakeFiles/main.dir/system/gpio/gpio_common.c.o: \ ...@@ -131,5 +131,7 @@ CMakeFiles/main.dir/system/gpio/gpio_common.c.o: \
/home/orangepi/car/master/include/delay.h \ /home/orangepi/car/master/include/delay.h \
/home/orangepi/car/master/include/softiic.h \ /home/orangepi/car/master/include/softiic.h \
/home/orangepi/car/master/system/gpio/gpio_common.h \ /home/orangepi/car/master/system/gpio/gpio_common.h \
/home/orangepi/car/master/include/request.h \ /home/orangepi/car/master/include/mqtt.h /usr/include/mosquitto.h \
/home/orangepi/car/master/include/common.h /usr/include/cjson/cJSON.h /home/orangepi/car/master/include/request.h \
/home/orangepi/car/master/include/common.h \
/home/orangepi/car/master/system/gpio/gpio_pwm_tank0202.h
...@@ -130,4 +130,6 @@ CMakeFiles/main.dir/system/gpio/gpio_pwm_tank0202.c.o: \ ...@@ -130,4 +130,6 @@ CMakeFiles/main.dir/system/gpio/gpio_pwm_tank0202.c.o: \
/home/orangepi/car/master/include/log.h \ /home/orangepi/car/master/include/log.h \
/home/orangepi/car/master/include/delay.h \ /home/orangepi/car/master/include/delay.h \
/home/orangepi/car/master/include/softiic.h \ /home/orangepi/car/master/include/softiic.h \
/home/orangepi/car/master/include/pthrpoll.h \
/home/orangepi/car/master/include/common.h \
/home/orangepi/car/master/system/gpio/gpio_pwm_tank0202.h /home/orangepi/car/master/system/gpio/gpio_pwm_tank0202.h
#define PROJECT_VERSION_MAJOR 1 #define PROJECT_VERSION_MAJOR 1
#define PROJECT_VERSION_MINOR 1 #define PROJECT_VERSION_MINOR 1
#define PROJECT_VERSION_PATCH 1 #define PROJECT_VERSION_PATCH 2
#define GIT_HASH "" #define GIT_HASH ""
#define BUILD_TIMESTAMP "2025-05-16T06:54:04" #define BUILD_TIMESTAMP "2025-05-19T12:32:09"
#define BUILD_USER "orangepi" #define BUILD_USER "orangepi"
No preview for this file type
#ifndef THREAD_MAIN_H__ #ifndef THREAD_MAIN_H__
#define THREAD_MAIN_H__ #define THREAD_MAIN_H__
int thread_start(void *AppExit(void *arg),void *Mqttbeat(void *arg),void *opensh(void *arg),void *Mqtt_onnect(void *arg)) ; int thread_start(void *AppExit(void *arg),void *Mqttbeat(void *arg),void *opensh(void *arg),void *Mqtt_onnect(void *arg),void *delay_count(void *arg)) ;
void *AppExit(void *arg) ; void *AppExit(void *arg) ;//异常停止线程
void *Mqttbeat(void *arg) ; void *Mqttbeat(void *arg) ;//心跳线程
void *opensh(void *arg) ; void *opensh(void *arg) ;//启动游览器线程
void *Mqtt_onnect(void *arg) ; void *Mqtt_onnect(void *arg) ;//mqtt自带重连线程
void *delay_count(void *arg) ;//延时计算延迟
void thread_end() ; void thread_end() ;
#endif #endif
\ No newline at end of file
...@@ -174,6 +174,7 @@ void message_4(cJSON *body, cJSON *pin_setctrl){//message 为4时候 ...@@ -174,6 +174,7 @@ void message_4(cJSON *body, cJSON *pin_setctrl){//message 为4时候
pin_value(gvalt[1],gvalt[2]); pin_value(gvalt[1],gvalt[2]);
pwm_value(gvalt[1],gvalt[2]); pwm_value(gvalt[1],gvalt[2]);
if(AppExit_pin_pwm == 202 ) tank_shot_back_stop(gvalt[1],gvalt[2]);
} }
int device_message(cJSON *json){//接收到的控制设备的mqtt消息 int device_message(cJSON *json){//接收到的控制设备的mqtt消息
......
...@@ -11,9 +11,10 @@ ...@@ -11,9 +11,10 @@
#include "device_exit.h" #include "device_exit.h"
#include "thread_main.h" #include "thread_main.h"
pthread_t thread[4]; pthread_t thread[5];
//开启线程 //开启线程
int thread_start(void *AppExit(void *arg),void *Mqttbeat(void *arg),void *opensh(void *arg),void *Mqtt_onnect(void *arg)){ int thread_start(void *AppExit(void *arg),void *Mqttbeat(void *arg),
void *opensh(void *arg),void *Mqtt_onnect(void *arg),void *delay_count(void *arg)){
if(pthread_create(&thread[0],NULL,AppExit,NULL)!=0) { if(pthread_create(&thread[0],NULL,AppExit,NULL)!=0) {
//perror("Failed to create thread 0"); //perror("Failed to create thread 0");
my_zlog_error("Failed to create thread 0"); my_zlog_error("Failed to create thread 0");
...@@ -34,6 +35,11 @@ int thread_start(void *AppExit(void *arg),void *Mqttbeat(void *arg),void *opensh ...@@ -34,6 +35,11 @@ int thread_start(void *AppExit(void *arg),void *Mqttbeat(void *arg),void *opensh
my_zlog_error("Failed to create thread 3"); my_zlog_error("Failed to create thread 3");
return 4; return 4;
} }
if(pthread_create(&thread[4],NULL,delay_count,NULL)!=0) {
//perror("Failed to create thread 3");
my_zlog_error("Failed to create thread 4");
return 5;
}
return 0; return 0;
} }
...@@ -87,6 +93,14 @@ void *Mqtt_onnect(void *arg) {//mqtt异常处理,断开自动重连,简单 ...@@ -87,6 +93,14 @@ void *Mqtt_onnect(void *arg) {//mqtt异常处理,断开自动重连,简单
return NULL; return NULL;
} }
void *delay_count(void *arg) {//专门用于计时的线程
while (1) {
Delay_Ms(0,1);
device_delay_count++;
if(device_delay_count >= 10000) device_delay_count = 10000;
}
}
// 等待线程结束 // 等待线程结束
void thread_end() { void thread_end() {
...@@ -94,5 +108,6 @@ void thread_end() { ...@@ -94,5 +108,6 @@ void thread_end() {
pthread_join(thread[1], NULL); pthread_join(thread[1], NULL);
pthread_join(thread[2], NULL); pthread_join(thread[2], NULL);
pthread_join(thread[3], NULL); pthread_join(thread[3], NULL);
pthread_join(thread[4], NULL);
} }
#include "common.h" #include "common.h"
#include "gpio_common.h" #include "gpio_common.h"
#include "mqtt.h"
#include "request.h" #include "request.h"
#include "gpio_pwm_tank0202.h"
#define MIN_DUTY 0 // 最小占空比 #define MIN_DUTY 0 // 最小占空比
#define MAX_DUTY 100 // 最大占空比 #define MAX_DUTY 100 // 最大占空比
int device_delay_count =0;//设备计算函数
int gpioPwm[30];//软件控制 int gpioPwm[30];//软件控制
int gpioWPi[40]; //能使用高低引脚和其他引脚 int gpioWPi[40]; //能使用高低引脚和其他引脚
...@@ -97,4 +101,8 @@ void pwm_init_speed() { ...@@ -97,4 +101,8 @@ void pwm_init_speed() {
pwmSetClock(PWM_PIN_CHANGE,pwm_clock);//=19200*1000/(hz*2000) pwmSetClock(PWM_PIN_CHANGE,pwm_clock);//=19200*1000/(hz*2000)
pwmSetRange(PWM_PIN_CHANGE,1000);//占空比范围 pwmSetRange(PWM_PIN_CHANGE,1000);//占空比范围
}
void Device_exit_end(){//main最后结束需要调用的函数
if(AppExit_pin_pwm == 202) tank_shot_back_stop_task_end();
} }
\ No newline at end of file
/*
此文件为通用文件,一般用于50hz的驱动等和引脚高低,适合车和船使用,
如果有其他需求,此文件就不需要使用
*/
#ifndef GPIO_COMMON_H__ #ifndef GPIO_COMMON_H__
#define GPIO_COMMON_H__ #define GPIO_COMMON_H__
...@@ -10,6 +5,10 @@ ...@@ -10,6 +5,10 @@
#define PWM_PIN_SPEED 21 #define PWM_PIN_SPEED 21
#define PWM_PIN_CHANGE 2 #define PWM_PIN_CHANGE 2
extern int device_delay_count;//延时计算函数,使用前必须置0
void Device_exit_end();//main最后结束需要调用的函数
void init_gpioWPi(int *values_pin);//gpio引脚初始化 void init_gpioWPi(int *values_pin);//gpio引脚初始化
void init_gpioPwm(int *values_pwm); void init_gpioPwm(int *values_pwm);
...@@ -22,4 +21,8 @@ void pin_value(int pin,int value); ...@@ -22,4 +21,8 @@ void pin_value(int pin,int value);
void pwm_init_speed(); void pwm_init_speed();
void pwm_value(int pin,int value); //软件陪我们控制调速 void pwm_value(int pin,int value); //软件陪我们控制调速
#endif #endif
\ No newline at end of file /*
此文件为通用文件,一般用于50hz的驱动等和引脚高低,适合车和船使用,
如果有其他需求,此文件就不需要使用
*/
\ No newline at end of file
#include "common.h" #include "common.h"
#include "pthrpoll.h"
#include "gpio_pwm_tank0202.h" #include "gpio_pwm_tank0202.h"
int modecount=0; int modecount=0;
...@@ -8,6 +9,10 @@ int tank0202_middle() { ...@@ -8,6 +9,10 @@ int tank0202_middle() {
pwmWrite(PWM_PIN_CHANGE,75); pwmWrite(PWM_PIN_CHANGE,75);
return 0; return 0;
} }
long long shot_device_time_start ;
long long shot_device_time_end = 0;
void mode_lift_flont(unsigned char gval) { void mode_lift_flont(unsigned char gval) {
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -192,4 +197,57 @@ int tank0202_change(unsigned char *buf) { ...@@ -192,4 +197,57 @@ int tank0202_change(unsigned char *buf) {
if(modecount == 1) mode_lift_back(val+25); if(modecount == 1) mode_lift_back(val+25);
} }
}
// 函数功能:获取当前精确到毫秒的时间戳
// 返回值:当前时间的毫秒数
long long get_current_time_millis() {
struct timeval tv;
// 获取当前时间,存储在tv结构体中,第二个参数一般传NULL
if (gettimeofday(&tv, NULL)!= 0) {
perror("gettimeofday error");
return -1;
}
// 秒数部分转换为毫秒(乘以1000),微秒数部分转换为毫秒(除以1000),然后相加
return (long long)tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
void tank_shot_back_stop_task_function(void *arg) {
if(device_delay_count>=20&&device_delay_count<=40) {
mode_right_back(80);
}
if(device_delay_count>40) {
mode_right_back(0);
}
}
ThreadPool *pool_tank;
void tank_shot_back_stop_task_end(){
thread_pool_destroy(pool_tank);
}
int tank_shot_back_stop(int pin,int val){
static int shot_count=0;
shot_device_time_start=get_current_time_millis();
if(pin !=27){
my_zlog_debug("非27引脚\n");
return 1;
}
if(val == 0) {
mode_right_back(0);
shot_count=1;
//thread_pool_destroy(pool);
}
if(val != 0) {
if(shot_count == 0){
int arg =1;
pool_tank=thread_pool_init(1,1);
thread_pool_add_task(pool_tank, tank_shot_back_stop_task_function, &arg);
shot_count=1;
}if(shot_count == 1){
device_delay_count=0;
}
}
shot_device_time_end=get_current_time_millis();
} }
\ No newline at end of file
...@@ -3,5 +3,9 @@ ...@@ -3,5 +3,9 @@
int tank0202_middle(); int tank0202_middle();
void tank_shot_back_stop_task_end();
int tank0202_change(unsigned char *buf); int tank0202_change(unsigned char *buf);
int tank_shot_back_stop(int pin,int val);
#endif #endif
\ No newline at end of file
...@@ -60,7 +60,7 @@ int main(int argc, char *argv[]) { ...@@ -60,7 +60,7 @@ int main(int argc, char *argv[]) {
my_zlog_fatal("I获取失败"); my_zlog_fatal("I获取失败");
return -1; return -1;
} }
if(thread_start(AppExit,Mqttbeat,opensh,Mqtt_onnect) !=0 ) {//开启线程) if(thread_start(AppExit,Mqttbeat,opensh,Mqtt_onnect,delay_count) !=0 ) {//开启线程)
my_zlog_fatal("开启线程失败"); my_zlog_fatal("开启线程失败");
return -1 ; return -1 ;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment