Commit 555a2968 authored by 957dd's avatar 957dd

完成了自控模式的开关

parent 6d50e9e8
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(car project(car
VERSION 1.2.17 VERSION 1.2.19
LANGUAGES C LANGUAGES C
) )
...@@ -44,6 +44,7 @@ include_directories( ...@@ -44,6 +44,7 @@ include_directories(
drivers/network drivers/network
drivers/sensors drivers/sensors
drivers/devicecontrol drivers/devicecontrol
drivers/selfcontrol
modules/logger modules/logger
modules/delay modules/delay
modules/thread_pool modules/thread_pool
...@@ -60,7 +61,8 @@ file(GLOB_RECURSE SOURCES ...@@ -60,7 +61,8 @@ file(GLOB_RECURSE SOURCES
drivers/gpio/*.c drivers/gpio/*.c
drivers/network/*.c drivers/network/*.c
drivers/sensors/*.c drivers/sensors/*.c
drivers/devicecontrol/*c drivers/devicecontrol/*.c
drivers/selfcontrol/*.c
modules/logger/*.c modules/logger/*.c
modules/delay/*.c modules/delay/*.c
modules/thread_pool/*.c modules/thread_pool/*.c
......
...@@ -39,18 +39,22 @@ int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat, ...@@ -39,18 +39,22 @@ int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat,
//出现意外自动停止 //出现意外自动停止
void *thread_exit_time(void *arg) { void *thread_exit_time(void *arg) {
while(1){ while(1){
if(get_self_control_index()==false){
delay_ms(100); delay_ms(100);
pthread_mutex_lock(&g_exit_count_mutex); pthread_mutex_lock(&g_exit_count_mutex);
g_devcontrol_exit_count++; g_devcontrol_exit_count++;
if(g_devcontrol_exit_count>=5) { if(g_devcontrol_exit_count>=5) {
device_stop(g_device_type); device_stop(g_device_type);
g_devcontrol_exit_count=6; g_devcontrol_exit_count=6;
} }
pthread_mutex_unlock(&g_exit_count_mutex); pthread_mutex_unlock(&g_exit_count_mutex);
}else {
set_self_control_time_countfuntion();
delay_ms(20);
}
} }
return NULL; return NULL;
} }
......
...@@ -942,6 +942,30 @@ drivers/network/ip_reader.c.s: ...@@ -942,6 +942,30 @@ drivers/network/ip_reader.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/network/ip_reader.c.s $(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/network/ip_reader.c.s
.PHONY : drivers/network/ip_reader.c.s .PHONY : drivers/network/ip_reader.c.s
drivers/selfcontrol/self_devicecontrol.o: drivers/selfcontrol/self_devicecontrol.c.o
.PHONY : drivers/selfcontrol/self_devicecontrol.o
# target to build an object file
drivers/selfcontrol/self_devicecontrol.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/selfcontrol/self_devicecontrol.c.o
.PHONY : drivers/selfcontrol/self_devicecontrol.c.o
drivers/selfcontrol/self_devicecontrol.i: drivers/selfcontrol/self_devicecontrol.c.i
.PHONY : drivers/selfcontrol/self_devicecontrol.i
# target to preprocess a source file
drivers/selfcontrol/self_devicecontrol.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/selfcontrol/self_devicecontrol.c.i
.PHONY : drivers/selfcontrol/self_devicecontrol.c.i
drivers/selfcontrol/self_devicecontrol.s: drivers/selfcontrol/self_devicecontrol.c.s
.PHONY : drivers/selfcontrol/self_devicecontrol.s
# target to generate assembly for a file
drivers/selfcontrol/self_devicecontrol.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/selfcontrol/self_devicecontrol.c.s
.PHONY : drivers/selfcontrol/self_devicecontrol.c.s
drivers/sensors/INA226.o: drivers/sensors/INA226.c.o drivers/sensors/INA226.o: drivers/sensors/INA226.c.o
.PHONY : drivers/sensors/INA226.o .PHONY : drivers/sensors/INA226.o
...@@ -1978,6 +2002,9 @@ help: ...@@ -1978,6 +2002,9 @@ help:
@echo "... drivers/network/ip_reader.o" @echo "... drivers/network/ip_reader.o"
@echo "... drivers/network/ip_reader.i" @echo "... drivers/network/ip_reader.i"
@echo "... drivers/network/ip_reader.s" @echo "... drivers/network/ip_reader.s"
@echo "... drivers/selfcontrol/self_devicecontrol.o"
@echo "... drivers/selfcontrol/self_devicecontrol.i"
@echo "... drivers/selfcontrol/self_devicecontrol.s"
@echo "... drivers/sensors/INA226.o" @echo "... drivers/sensors/INA226.o"
@echo "... drivers/sensors/INA226.i" @echo "... drivers/sensors/INA226.i"
@echo "... drivers/sensors/INA226.s" @echo "... drivers/sensors/INA226.s"
......
#define PROJECT_VERSION_MAJOR 1 #define PROJECT_VERSION_MAJOR 1
#define PROJECT_VERSION_MINOR 2 #define PROJECT_VERSION_MINOR 2
#define PROJECT_VERSION_PATCH 17 #define PROJECT_VERSION_PATCH 19
#define GIT_HASH "" #define GIT_HASH ""
#define BUILD_TIMESTAMP "" #define BUILD_TIMESTAMP ""
#define BUILD_USER "" #define BUILD_USER ""
No preview for this file type
CMAKE_PROGRESS_1 = CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 = CMAKE_PROGRESS_2 = 81
CMAKE_PROGRESS_3 = 81 CMAKE_PROGRESS_3 =
CMAKE_PROGRESS_4 = CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = 82 CMAKE_PROGRESS_5 = 82
CMAKE_PROGRESS_6 = CMAKE_PROGRESS_6 =
......
...@@ -32,8 +32,8 @@ CMAKE_PROGRESS_31 = ...@@ -32,8 +32,8 @@ CMAKE_PROGRESS_31 =
CMAKE_PROGRESS_32 = CMAKE_PROGRESS_32 =
CMAKE_PROGRESS_33 = 12 CMAKE_PROGRESS_33 = 12
CMAKE_PROGRESS_34 = CMAKE_PROGRESS_34 =
CMAKE_PROGRESS_35 = 13 CMAKE_PROGRESS_35 =
CMAKE_PROGRESS_36 = CMAKE_PROGRESS_36 = 13
CMAKE_PROGRESS_37 = CMAKE_PROGRESS_37 =
CMAKE_PROGRESS_38 = 14 CMAKE_PROGRESS_38 = 14
CMAKE_PROGRESS_39 = CMAKE_PROGRESS_39 =
......
...@@ -5,8 +5,8 @@ CMAKE_PROGRESS_4 = ...@@ -5,8 +5,8 @@ CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = CMAKE_PROGRESS_5 =
CMAKE_PROGRESS_6 = 18 CMAKE_PROGRESS_6 = 18
CMAKE_PROGRESS_7 = CMAKE_PROGRESS_7 =
CMAKE_PROGRESS_8 = 19 CMAKE_PROGRESS_8 =
CMAKE_PROGRESS_9 = CMAKE_PROGRESS_9 = 19
CMAKE_PROGRESS_10 = CMAKE_PROGRESS_10 =
CMAKE_PROGRESS_11 = 20 CMAKE_PROGRESS_11 = 20
CMAKE_PROGRESS_12 = CMAKE_PROGRESS_12 =
...@@ -22,11 +22,11 @@ CMAKE_PROGRESS_21 = ...@@ -22,11 +22,11 @@ CMAKE_PROGRESS_21 =
CMAKE_PROGRESS_22 = CMAKE_PROGRESS_22 =
CMAKE_PROGRESS_23 = 24 CMAKE_PROGRESS_23 = 24
CMAKE_PROGRESS_24 = CMAKE_PROGRESS_24 =
CMAKE_PROGRESS_25 = 25 CMAKE_PROGRESS_25 =
CMAKE_PROGRESS_26 = CMAKE_PROGRESS_26 = 25
CMAKE_PROGRESS_27 = CMAKE_PROGRESS_27 =
CMAKE_PROGRESS_28 = 26 CMAKE_PROGRESS_28 =
CMAKE_PROGRESS_29 = CMAKE_PROGRESS_29 = 26
CMAKE_PROGRESS_30 = CMAKE_PROGRESS_30 =
CMAKE_PROGRESS_31 = 27 CMAKE_PROGRESS_31 = 27
CMAKE_PROGRESS_32 = CMAKE_PROGRESS_32 =
......
...@@ -3,8 +3,8 @@ CMAKE_PROGRESS_2 = ...@@ -3,8 +3,8 @@ CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3 = CMAKE_PROGRESS_3 =
CMAKE_PROGRESS_4 = 86 CMAKE_PROGRESS_4 = 86
CMAKE_PROGRESS_5 = CMAKE_PROGRESS_5 =
CMAKE_PROGRESS_6 = CMAKE_PROGRESS_6 = 87
CMAKE_PROGRESS_7 = 87 CMAKE_PROGRESS_7 =
CMAKE_PROGRESS_8 = CMAKE_PROGRESS_8 =
CMAKE_PROGRESS_9 = 88 CMAKE_PROGRESS_9 = 88
CMAKE_PROGRESS_10 = CMAKE_PROGRESS_10 =
......
CMAKE_PROGRESS_1 = 54 CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 = CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3 = CMAKE_PROGRESS_3 = 55
CMAKE_PROGRESS_4 = 55 CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = CMAKE_PROGRESS_5 =
CMAKE_PROGRESS_6 = CMAKE_PROGRESS_6 = 56
CMAKE_PROGRESS_7 = 56 CMAKE_PROGRESS_7 =
CMAKE_PROGRESS_8 = CMAKE_PROGRESS_8 =
CMAKE_PROGRESS_9 = 57 CMAKE_PROGRESS_9 = 57
CMAKE_PROGRESS_10 = CMAKE_PROGRESS_10 =
...@@ -14,14 +14,14 @@ CMAKE_PROGRESS_13 = ...@@ -14,14 +14,14 @@ CMAKE_PROGRESS_13 =
CMAKE_PROGRESS_14 = CMAKE_PROGRESS_14 =
CMAKE_PROGRESS_15 = 59 CMAKE_PROGRESS_15 = 59
CMAKE_PROGRESS_16 = CMAKE_PROGRESS_16 =
CMAKE_PROGRESS_17 = CMAKE_PROGRESS_17 = 60
CMAKE_PROGRESS_18 = 60 CMAKE_PROGRESS_18 =
CMAKE_PROGRESS_19 = CMAKE_PROGRESS_19 =
CMAKE_PROGRESS_20 = CMAKE_PROGRESS_20 = 61
CMAKE_PROGRESS_21 = 61 CMAKE_PROGRESS_21 =
CMAKE_PROGRESS_22 = CMAKE_PROGRESS_22 =
CMAKE_PROGRESS_23 = CMAKE_PROGRESS_23 = 62
CMAKE_PROGRESS_24 = 62 CMAKE_PROGRESS_24 =
CMAKE_PROGRESS_25 = CMAKE_PROGRESS_25 =
CMAKE_PROGRESS_26 = 63 CMAKE_PROGRESS_26 = 63
CMAKE_PROGRESS_27 = CMAKE_PROGRESS_27 =
...@@ -34,11 +34,11 @@ CMAKE_PROGRESS_33 = ...@@ -34,11 +34,11 @@ CMAKE_PROGRESS_33 =
CMAKE_PROGRESS_34 = CMAKE_PROGRESS_34 =
CMAKE_PROGRESS_35 = 66 CMAKE_PROGRESS_35 = 66
CMAKE_PROGRESS_36 = CMAKE_PROGRESS_36 =
CMAKE_PROGRESS_37 = CMAKE_PROGRESS_37 = 67
CMAKE_PROGRESS_38 = 67 CMAKE_PROGRESS_38 =
CMAKE_PROGRESS_39 = CMAKE_PROGRESS_39 =
CMAKE_PROGRESS_40 = CMAKE_PROGRESS_40 = 68
CMAKE_PROGRESS_41 = 68 CMAKE_PROGRESS_41 =
CMAKE_PROGRESS_42 = CMAKE_PROGRESS_42 =
CMAKE_PROGRESS_43 = 69 CMAKE_PROGRESS_43 = 69
CMAKE_PROGRESS_44 = CMAKE_PROGRESS_44 =
...@@ -54,8 +54,8 @@ CMAKE_PROGRESS_53 = ...@@ -54,8 +54,8 @@ CMAKE_PROGRESS_53 =
CMAKE_PROGRESS_54 = CMAKE_PROGRESS_54 =
CMAKE_PROGRESS_55 = 73 CMAKE_PROGRESS_55 = 73
CMAKE_PROGRESS_56 = CMAKE_PROGRESS_56 =
CMAKE_PROGRESS_57 = CMAKE_PROGRESS_57 = 74
CMAKE_PROGRESS_58 = 74 CMAKE_PROGRESS_58 =
CMAKE_PROGRESS_59 = CMAKE_PROGRESS_59 =
CMAKE_PROGRESS_60 = 75 CMAKE_PROGRESS_60 = 75
CMAKE_PROGRESS_61 = CMAKE_PROGRESS_61 =
...@@ -71,6 +71,6 @@ CMAKE_PROGRESS_70 = ...@@ -71,6 +71,6 @@ CMAKE_PROGRESS_70 =
CMAKE_PROGRESS_71 = CMAKE_PROGRESS_71 =
CMAKE_PROGRESS_72 = 79 CMAKE_PROGRESS_72 = 79
CMAKE_PROGRESS_73 = CMAKE_PROGRESS_73 =
CMAKE_PROGRESS_74 = CMAKE_PROGRESS_74 = 80
CMAKE_PROGRESS_75 = 80 CMAKE_PROGRESS_75 =
...@@ -81,14 +81,14 @@ void car0104_change(unsigned char *buf) { ...@@ -81,14 +81,14 @@ void car0104_change(unsigned char *buf) {
unsigned char val = buf[2]; unsigned char val = buf[2];
if(mode == 1 ) { if(mode == 1 ) {
car0104_flont(val); car0104_flont(val+10);
}else if(mode == 2 ) { }else if(mode == 2 ) {
car0104_back(val); car0104_back(val+10);
}else if(mode == 3) { }else if(mode == 3) {
if(val !=0) car0104_lift(85); if(val !=0) car0104_lift(100);
else car0104_lift(0); else car0104_lift(0);
}else if(mode == 4) { }else if(mode == 4) {
if(val !=0) car0104_right(85); if(val !=0) car0104_right(100);
else car0104_lift(0); else car0104_lift(0);
} }
......
...@@ -10,7 +10,7 @@ void tank0202_middle() { ...@@ -10,7 +10,7 @@ void tank0202_middle() {
pwmWrite(PWM_PIN_CHANGE,75); pwmWrite(PWM_PIN_CHANGE,75);
} }
void mode_lift_flont(unsigned char gval) { void mode_right(unsigned char gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -26,7 +26,7 @@ void mode_lift_flont(unsigned char gval) { ...@@ -26,7 +26,7 @@ void mode_lift_flont(unsigned char gval) {
} }
} }
void mode_lift_back(unsigned char gval) { void mode_lift(unsigned char gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -41,7 +41,7 @@ void mode_lift_back(unsigned char gval) { ...@@ -41,7 +41,7 @@ void mode_lift_back(unsigned char gval) {
} }
} }
void mode_right_flont(unsigned char gval) { void mode_flont(unsigned char gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -56,7 +56,7 @@ void mode_right_flont(unsigned char gval) { ...@@ -56,7 +56,7 @@ void mode_right_flont(unsigned char gval) {
} }
} }
void mode_right_back(unsigned char gval) { void mode_back(unsigned char gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -128,33 +128,33 @@ void tank0202_change(unsigned char *buf) { ...@@ -128,33 +128,33 @@ void tank0202_change(unsigned char *buf) {
} }
if(tank0202_front_t ==0&&tank0202_steering_t==0){ if(tank0202_front_t ==0&&tank0202_steering_t==0){
mode_lift_flont(0); mode_right(0);
mode_right_flont(0); mode_flont(0);
}else if(tank0202_front_t ==1&&tank0202_steering_t==0){ }else if(tank0202_front_t ==1&&tank0202_steering_t==0){
mode_right_flont(tank0202_front_val+10); mode_flont(tank0202_front_val+10);
mode_lift_flont(0); mode_right(0);
}else if(tank0202_front_t ==2&&tank0202_steering_t==0){ }else if(tank0202_front_t ==2&&tank0202_steering_t==0){
mode_right_back(tank0202_front_val+10); mode_back(tank0202_front_val+10);
mode_lift_back(0); mode_lift(0);
}else if(tank0202_front_t ==0&&tank0202_steering_t==1){ }else if(tank0202_front_t ==0&&tank0202_steering_t==1){
mode_lift_back(tank0202_steering_val + tank0202_count+20); mode_lift(tank0202_steering_val + tank0202_count+20);
mode_right_back(0); mode_back(0);
}else if(tank0202_front_t ==0&&tank0202_steering_t==2){ }else if(tank0202_front_t ==0&&tank0202_steering_t==2){
mode_lift_flont(tank0202_steering_val + tank0202_count+20); mode_right(tank0202_steering_val + tank0202_count+20);
mode_right_back(0); mode_back(0);
} }
else if(tank0202_front_t ==1&&tank0202_steering_t==1){ else if(tank0202_front_t ==1&&tank0202_steering_t==1){
mode_lift_back(tank0202_steering_val + 10); mode_lift(tank0202_steering_val + 10);
mode_right_flont(tank0202_steering_val + 20); mode_flont(tank0202_steering_val + 20);
}else if(tank0202_front_t ==1&&tank0202_steering_t==2){ }else if(tank0202_front_t ==1&&tank0202_steering_t==2){
mode_lift_flont(tank0202_steering_val +10); mode_right(tank0202_steering_val +10);
mode_right_flont(tank0202_steering_val + 20); mode_flont(tank0202_steering_val + 20);
}else if(tank0202_front_t ==2&&tank0202_steering_t==1){ }else if(tank0202_front_t ==2&&tank0202_steering_t==1){
mode_lift_back(tank0202_steering_val + 10); mode_lift(tank0202_steering_val + 10);
mode_right_back(tank0202_steering_val + 20); mode_back(tank0202_steering_val + 20);
}else if(tank0202_front_t ==2&&tank0202_steering_t==2){ }else if(tank0202_front_t ==2&&tank0202_steering_t==2){
mode_lift_flont(tank0202_steering_val + 10); mode_right(tank0202_steering_val + 10);
mode_right_back(tank0202_steering_val + 20); mode_back(tank0202_steering_val + 20);
} }
......
...@@ -8,7 +8,7 @@ void tank0204_stop() { ...@@ -8,7 +8,7 @@ void tank0204_stop() {
pwmWrite(PWM_PIN_CHANGE,75); pwmWrite(PWM_PIN_CHANGE,75);
} }
void tank0204_mode_lift_flont(unsigned char gval) { void tank0204_mode_lift(unsigned char gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -24,7 +24,7 @@ void tank0204_mode_lift_flont(unsigned char gval) { ...@@ -24,7 +24,7 @@ void tank0204_mode_lift_flont(unsigned char gval) {
} }
} }
void tank0204_mode_lift_back(unsigned char gval) { void tank0204_mode_right(unsigned char gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -39,7 +39,7 @@ void tank0204_mode_lift_back(unsigned char gval) { ...@@ -39,7 +39,7 @@ void tank0204_mode_lift_back(unsigned char gval) {
} }
} }
void tank0204_mode_right_back(unsigned char gval) { void tank0204_mode_flont(unsigned char gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -54,7 +54,7 @@ void tank0204_mode_right_back(unsigned char gval) { ...@@ -54,7 +54,7 @@ void tank0204_mode_right_back(unsigned char gval) {
} }
} }
void tank0204_mode_right_flont(unsigned char gval) { void tank0204_mode_back(unsigned char gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -125,33 +125,33 @@ void tank0204_change(unsigned char *buf) { ...@@ -125,33 +125,33 @@ void tank0204_change(unsigned char *buf) {
} }
if(tank0204_front_t ==0&&tank0204_steering_t==0){ if(tank0204_front_t ==0&&tank0204_steering_t==0){
tank0204_mode_lift_flont(0); tank0204_mode_right(0);
tank0204_mode_right_flont(0); tank0204_mode_flont(0);
}else if(tank0204_front_t ==1&&tank0204_steering_t==0){ }else if(tank0204_front_t ==1&&tank0204_steering_t==0){
tank0204_mode_right_flont(tank0204_front_val+10); tank0204_mode_flont(tank0204_front_val+10);
tank0204_mode_lift_flont(0); tank0204_mode_right(0);
}else if(tank0204_front_t ==2&&tank0204_steering_t==0){ }else if(tank0204_front_t ==2&&tank0204_steering_t==0){
tank0204_mode_right_back(tank0204_front_val+10); tank0204_mode_back(tank0204_front_val+10);
tank0204_mode_lift_back(0); tank0204_mode_lift(0);
}else if(tank0204_front_t ==0&&tank0204_steering_t==1){ }else if(tank0204_front_t ==0&&tank0204_steering_t==1){
tank0204_mode_lift_back(tank0204_steering_val + tank0204_count+20); tank0204_mode_lift(tank0204_steering_val + tank0204_count+20);
tank0204_mode_right_back(0); tank0204_mode_back(0);
}else if(tank0204_front_t ==0&&tank0204_steering_t==2){ }else if(tank0204_front_t ==0&&tank0204_steering_t==2){
tank0204_mode_lift_flont(tank0204_steering_val + tank0204_count+20); tank0204_mode_right(tank0204_steering_val + tank0204_count+20);
tank0204_mode_right_back(0); tank0204_mode_back(0);
} }
else if(tank0204_front_t ==1&&tank0204_steering_t==1){ else if(tank0204_front_t ==1&&tank0204_steering_t==1){
tank0204_mode_lift_back(tank0204_steering_val + 10); tank0204_mode_lift(tank0204_steering_val+ 40);
tank0204_mode_right_flont(tank0204_steering_val + 20); tank0204_mode_flont(tank0204_steering_val + 20);
}else if(tank0204_front_t ==1&&tank0204_steering_t==2){ }else if(tank0204_front_t ==1&&tank0204_steering_t==2){
tank0204_mode_lift_flont(tank0204_steering_val +10); tank0204_mode_right(tank0204_steering_val+ 40);
tank0204_mode_right_flont(tank0204_steering_val + 20); tank0204_mode_flont(tank0204_steering_val + 20);
}else if(tank0204_front_t ==2&&tank0204_steering_t==1){ }else if(tank0204_front_t ==2&&tank0204_steering_t==1){
tank0204_mode_lift_back(tank0204_steering_val + 10); tank0204_mode_lift(tank0204_steering_val+ 40);
tank0204_mode_right_back(tank0204_steering_val + 20); tank0204_mode_back(tank0204_steering_val + 20);
}else if(tank0204_front_t ==2&&tank0204_steering_t==2){ }else if(tank0204_front_t ==2&&tank0204_steering_t==2){
tank0204_mode_lift_flont(tank0204_steering_val + 10); tank0204_mode_right(tank0204_steering_val+ 40);
tank0204_mode_right_back(tank0204_steering_val + 20); tank0204_mode_back(tank0204_steering_val + 20);
} }
} }
......
...@@ -145,7 +145,9 @@ int tank_shot_back_stop(unsigned char pin,unsigned char val){ ...@@ -145,7 +145,9 @@ int tank_shot_back_stop(unsigned char pin,unsigned char val){
} }
/*销毁坦克使用的线程池,让其正常销毁,只有在tank相关设备号下才有用,最后销毁都会到device——common.h中*/ /*
* @brief 销毁坦克使用的线程池,让其正常销毁,只有在tank相关设备号下才有用,最后销毁都会到device——common.h中
*/
void tank_thread_close(){ void tank_thread_close(){
thread_pool_destroy(pool_tank_t); thread_pool_destroy(pool_tank_t);
thread_pool_destroy(g_pool_device_gpio_control_t); thread_pool_destroy(g_pool_device_gpio_control_t);
......
...@@ -19,6 +19,7 @@ void car0103_pin_value(int pin,int value); ...@@ -19,6 +19,7 @@ void car0103_pin_value(int pin,int value);
void car0104_pin_value(int pin,int value); void car0104_pin_value(int pin,int value);
void public_pwm_value(int pin ,int value); void public_pwm_value(int pin ,int value);
void car0103_pwm_value(int pin ,int value);
void tank0202_pwm_value(int pin,int value); void tank0202_pwm_value(int pin,int value);
void tank0203_pwm_value(int pin,int value); void tank0203_pwm_value(int pin,int value);
void tank0204_pwm_value(int pin,int value); void tank0204_pwm_value(int pin,int value);
...@@ -32,16 +33,6 @@ uint64_t g_tank_shot_ms=1000; //射击时间 ...@@ -32,16 +33,6 @@ uint64_t g_tank_shot_ms=1000; //射击时间
TankFireControl g_device_shot_t; // 真正的结构体变量 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;
// }
/** /**
* @brief 初始化坦克射击控制器 * @brief 初始化坦克射击控制器
* @param this 控制器指针 * @param this 控制器指针
...@@ -114,7 +105,7 @@ int device_fire_check(TankFireControl* this) { ...@@ -114,7 +105,7 @@ int device_fire_check(TankFireControl* this) {
} }
/* /*
*设备加上冷却射击切换 * @brief 设备加上冷却射击切换
*/ */
int device_shoting_check(int pin,int val){ int device_shoting_check(int pin,int val){
if(device_fire_check(&g_device_shot_t)!=0){ if(device_fire_check(&g_device_shot_t)!=0){
...@@ -124,7 +115,8 @@ int device_shoting_check(int pin,int val){ ...@@ -124,7 +115,8 @@ int device_shoting_check(int pin,int val){
} }
} }
/*坦克限位线程函数*/ /*
* @brief 坦克限位线程函数*/
void tank_angle_limit_function(void *arg_gpio){ void tank_angle_limit_function(void *arg_gpio){
static int limit_log_count=0; static int limit_log_count=0;
if (arg_gpio != NULL) { if (arg_gpio != NULL) {
...@@ -401,14 +393,28 @@ void tank0204_pwm_value(int pin,int value){ ...@@ -401,14 +393,28 @@ void tank0204_pwm_value(int pin,int value){
if(pin == 27){ if(pin == 27){
device_shoting_check(27,30); device_shoting_check(27,30);
} else { }else if(pin == 5) {
softPwmWrite(7, 30);
my_zlog_info("pwm:7,0");
}else if(pin == 7) {
softPwmWrite(5, 30);
my_zlog_info("pwm:5,0");
}else {
softPwmWrite(pin, 30); softPwmWrite(pin, 30);
my_zlog_info("pwm:%d",pin); my_zlog_info("pwm:%d",pin);
} }
}else if(value==0) { }else if(value==0) {
softPwmWrite(pin, 0); if(pin == 5) {
my_zlog_info("pwm:%d,0",pin); softPwmWrite(7, 0);
my_zlog_info("pwm:7,0");
}else if(pin == 7) {
softPwmWrite(5, 0);
my_zlog_info("pwm:5,0",pin);
}else{
softPwmWrite(pin, 0);
my_zlog_info("pwm:%d,0",pin);
}
} }
my_zlog_info("tank0204 pwm"); my_zlog_info("tank0204 pwm");
} }
......
#include "common.h"
#include "self_devicecontrol.h"
#include "modules_common.h"
#include "app_device_common.h"
#include "drivers_common.h"
static ThreadPool_t *g_self_devicecontrol_task_t;
static bool g_self_device_control_switch_index=false;//自控开关。是否打开或者关闭
static int self_control_interval=0;
static int self_control_time_count=0;
/*
* @brief 设置g_self_devicecontrol_task_t
*/
void set_device_tasks(devicecontroltask_t *new_tasks) {
g_self_devicecontrol_task_t = new_tasks;
}
/*
* @brief 自控线程中的任务
*/
void self_device_control_task(){
static unsigned char s_valt[4];
device_walk_control(g_device_type,s_valt);
device_gpio_control(g_device_type,s_valt[1],s_valt[2]);
}
/*
* @brief 自控线程中的计时函数接口,每20ms加一次
* @param[in] self_control_time_count,计时次数
*/
void set_self_control_time_countfuntion(){
self_control_time_count++;
}
/*
* @brief 自控线程
*/
void self_device_control_task_function(){
my_zlog_info("自控线程池循环开始");
while(1){
if(g_self_device_control_switch_index==true){
self_device_control_task();
}else if(g_self_device_control_switch_index==false){
delay_ms(100);
}
}
my_zlog_info("自控线程池循环终止");
return ;
}
/*
* @brief 开启自控线程
*/
void self_device_pthrpoll_task_init(){
g_self_devicecontrol_task_t=thread_pool_init(1,1);
thread_pool_add_task(g_self_devicecontrol_task_t, self_device_control_task_function, NULL);
my_zlog_info("自控线程池打开");
}
/*
* @brief 返回自控是否打开的标识接口
*/
bool get_self_control_index(){
return g_self_device_control_switch_index;
}
/*
* @brief 自控的线程开启标识设置。
* @param[in] 当index为,true为开,false为关
*/
void set_self_control_index(bool index){
g_self_device_control_switch_index =index;
}
/*
* @brief 销毁自控的线程
*/
void self_control_thread_close(){
if(get_self_control_index()==true){
my_zlog_info("Destroy the thread of the automatic control device");
thread_pool_destroy(g_self_devicecontrol_task_t);
}
my_zlog_info("The thread of the automatic control device is not opened");
}
/*
* @brief 返回MQTT自控打开或者关闭的函数
*/
void send_self_contorl_mqtt(){
// 创建根对象
cJSON *root = cJSON_CreateObject();
// 创建head对象
cJSON *head = cJSON_CreateObject();
cJSON_AddNumberToObject(head, "message_type", 3018);
cJSON_AddItemToObject(root, "head", head);
// 创建body对象
cJSON *body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "cmd", "device_mycontrol");
cJSON_AddNumberToObject(body, "switch_reply_status", get_self_control_index());
cJSON_AddItemToObject(root, "body", body);
// 将cJSON对象转换为字符串
char *json_str = cJSON_PrintUnformatted(root);
my_zlog_debug("%s",json_str);
for(int i=0;i<g_mqtt_cam_config_t->mqtt_count;i++){
mosquitto_publish(g_clients_t[i].mosq, NULL, mqtt_topic_pure_number(), strlen(json_str), json_str, 0, false);
}
cJSON_Delete(root); // 释放 cJSON 对象
}
/*
* @brief MQTT接收自控消息的函数
*/
void receive_self_contorl_mqtt(cJSON *body){
if (!body) {
my_zlog_error("JSON error!");
return;
}
cJSON *switch_status = cJSON_GetObjectItem(body, "switch_status");
static int s_switch_status = 0;
static bool s_thread_index=0;
s_switch_status=switch_status->valueint;
if(s_switch_status == DEVICE_SELF_CONTROL_OPEN){
if(s_thread_index==0) self_device_pthrpoll_task_init();
g_self_device_control_switch_index =true;
s_thread_index=1;
}else if(s_switch_status == DEVICE_SELF_CONTROL_CLOSE) {
g_self_device_control_switch_index =false;
}
// 2️ id_run 数组
// cJSON *id_run = cJSON_GetObjectItem(body, "id_run");
// g_self_devicecontrol_task_t->id_run_count = 0;
// if (cJSON_IsArray(id_run)) {
// int size = cJSON_GetArraySize(id_run);
// for (int i = 0; i < size && i < DEVICE_WALK_SIGN_MAX; i++) {
// cJSON *item = cJSON_GetArrayItem(id_run, i);
// g_self_devicecontrol_task_t->id_run[i] = item->valueint;
// g_self_devicecontrol_task_t->id_run_count++;
// }
// }
send_self_contorl_mqtt();
return;
}
\ No newline at end of file
#ifndef SELF_DEVICECONTROL_H
#define SELF_DEVICECONTROL_H
/**
* @file self_devicecontrol.h
* @brief 设备自己控制模块头文件
*/
#define DEVICE_WALK_SIGN_MAX 10
#define DEVICE_SELF_CONTROL_OPEN 1
#define DEVICE_SELF_CONTROL_CLOSE 0
//结构体,用来存放这些
typedef struct {
int id_run[DEVICE_WALK_SIGN_MAX];
int id_run_count;
int run_cool[DEVICE_WALK_SIGN_MAX];
int timed_run[DEVICE_WALK_SIGN_MAX];
} devicecontroltask_t;
void set_self_control_time_countfuntion();//计时
void self_control_thread_close();
void receive_self_contorl_mqtt(cJSON *body);
bool get_self_control_index();
void set_self_control_index(bool index);
#endif
\ No newline at end of file
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
#include "common.h" #include "common.h"
#include "ads1115.h" #include "ads1115.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
double tank_angle(){ double tank_angle(){
double angle=0; double angle=0;
float angle_shot=ads1115_read_channel(2); float angle_shot=ads1115_read_channel(2);
......
...@@ -5,5 +5,6 @@ ...@@ -5,5 +5,6 @@
#include "gpio_common.h" #include "gpio_common.h"
#include "ip_reader.h" #include "ip_reader.h"
#include "sensors_common.h" #include "sensors_common.h"
#include"self_devicecontrol.h"
#endif #endif
\ No newline at end of file
...@@ -7,12 +7,15 @@ ...@@ -7,12 +7,15 @@
int g_heartbeat_count=0; int g_heartbeat_count=0;
/*
*
*/
pthread_mutex_t g_exit_count_mutex = PTHREAD_MUTEX_INITIALIZER;//互斥锁 pthread_mutex_t g_exit_count_mutex = PTHREAD_MUTEX_INITIALIZER;//互斥锁
int g_devcontrol_exit_count=0; int g_devcontrol_exit_count=0;
int g_message_type=0; int g_message_type=0;
unsigned char g_valt[4];//存放mqtt接收的tpye,mode等 static unsigned char g_valt[4];//存放mqtt接收的tpye,mode等
//心跳发送格式*5/2 //心跳发送格式*5/2
void heartbeat_send() { void heartbeat_send() {
...@@ -254,12 +257,19 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息 ...@@ -254,12 +257,19 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
break; break;
case 3: case 3:
message_3_judyverify(body); message_3_judyverify(body);
set_self_control_index(false);
my_zlog_debug("进入pwm控制"); my_zlog_debug("进入pwm控制");
break; break;
case 4: case 4:
message_4_judyverify(body); message_4_judyverify(body);
set_self_control_index(false);
my_zlog_debug("进入引脚控制"); my_zlog_debug("进入引脚控制");
break; break;
case 5:
audio_wheat_init();
audio_speaker_init();
my_zlog_debug("执行麦和喇叭命令");
break;
case 2001: case 2001:
audioplay_mqtt_receive(body); audioplay_mqtt_receive(body);
my_zlog_debug("进入音频播放"); my_zlog_debug("进入音频播放");
...@@ -312,6 +322,10 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息 ...@@ -312,6 +322,10 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
control_pthread_function("close"); control_pthread_function("close");
my_zlog_debug("关闭控制台推送"); my_zlog_debug("关闭控制台推送");
break; break;
case 2025:
receive_self_contorl_mqtt(body);
my_zlog_debug("device self comtrol");
break;
default: default:
break; break;
} }
......
...@@ -180,7 +180,6 @@ int message2006_verify(cJSON *body){ ...@@ -180,7 +180,6 @@ int message2006_verify(cJSON *body){
} }
return 0; return 0;
} }
/*接收到是否打开验证的函数*/ /*接收到是否打开验证的函数*/
...@@ -200,7 +199,7 @@ int message2013_recverigy_open(cJSON *body){ ...@@ -200,7 +199,7 @@ int message2013_recverigy_open(cJSON *body){
my_zlog_debug("verify open"); my_zlog_debug("verify open");
} }
return 0; return 0;
} }
/*发送是否打开验证的mqtt给后端验证*/ /*发送是否打开验证的mqtt给后端验证*/
int message_sendopen_verify(){ int message_sendopen_verify(){
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define PTHRPOLL_H #define PTHRPOLL_H
// 为了让头文件自给自足,直接包含它所需要的依赖 // 为了让头文件自给自足,直接包含它所需要的依赖
#include <common.h> #include "common.h"
// 任务结构体 // 任务结构体
typedef struct Task { typedef struct Task {
......
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