Commit 67dda630 authored by 957dd's avatar 957dd

加入了小车0102的方向盘控制,修改了变量的类型

parent c7920af7
...@@ -80,7 +80,7 @@ int main() ...@@ -80,7 +80,7 @@ int main()
int thread_rc = thread_start_init(thread_exit_time, thread_mqtt_beat, int thread_rc = thread_start_init(thread_exit_time, thread_mqtt_beat,
thread_open_browser, thread_mqtt_reconnect, thread_time_calculation, thread_play_mp3); thread_open_browser, thread_mqtt_reconnect, thread_time_calculation, thread_play_mp3, thread_steering_control);
if (thread_rc != 0) if (thread_rc != 0)
{ {
my_zlog_warn("多线程初始化失败"); my_zlog_warn("多线程初始化失败");
......
...@@ -34,7 +34,8 @@ int device_shot_cooling_init(); ...@@ -34,7 +34,8 @@ int device_shot_cooling_init();
/*线程初始化函数*/ /*线程初始化函数*/
int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat, int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat,
ThreadFunc thread_open_browser, ThreadFunc thread_mqtt_reconnect, ThreadFunc thread_open_browser, ThreadFunc thread_mqtt_reconnect,
ThreadFunc thread_time_calculation, ThreadFunc thread_play_mp3); ThreadFunc thread_time_calculation, ThreadFunc thread_play_mp3,
ThreadFunc thread_steering_control);
/*像服务器请求*/ /*像服务器请求*/
int request_date(); int request_date();
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "pthread_open.h" #include "pthread_open.h"
#include "go_deploy.h" #include "go_deploy.h"
#define PTHREAD_MAX 6 #define PTHREAD_MAX 7
pthread_t g_thread[PTHREAD_MAX]; // 全局线程句柄数组(或传参) pthread_t g_thread[PTHREAD_MAX]; // 全局线程句柄数组(或传参)
...@@ -17,7 +17,7 @@ void *g_args[PTHREAD_MAX] = {NULL}; ...@@ -17,7 +17,7 @@ void *g_args[PTHREAD_MAX] = {NULL};
int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat, int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat,
ThreadFunc thread_open_browser, ThreadFunc thread_mqtt_reconnect, ThreadFunc thread_open_browser, ThreadFunc thread_mqtt_reconnect,
ThreadFunc thread_time_calculation, ThreadFunc thread_play_mp3) ThreadFunc thread_time_calculation, ThreadFunc thread_play_mp3,ThreadFunc thread_steering_control)
{ {
ThreadFunc thread_funcs[] = { ThreadFunc thread_funcs[] = {
...@@ -26,7 +26,8 @@ int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat, ...@@ -26,7 +26,8 @@ int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat,
thread_open_browser, thread_open_browser,
thread_mqtt_reconnect, thread_mqtt_reconnect,
thread_time_calculation, thread_time_calculation,
thread_play_mp3}; thread_play_mp3,
thread_steering_control};
for (int i = 0; i < PTHREAD_MAX; i++) for (int i = 0; i < PTHREAD_MAX; i++)
{ {
...@@ -298,6 +299,17 @@ void *thread_play_mp3(void *arg) ...@@ -298,6 +299,17 @@ void *thread_play_mp3(void *arg)
return NULL; return NULL;
} }
// 方向盘控制线程:100ms周期调用平滑处理
void *thread_steering_control(void *arg)
{
my_zlog_info("steering_pthread");
while(1) {
steering_control_process();
delay_ms(25);
}
return NULL;
}
// 等待线程结束 // 等待线程结束
void thread_end_close() void thread_end_close()
{ {
......
...@@ -6,13 +6,16 @@ typedef void *(*ThreadFunc)(void *); ...@@ -6,13 +6,16 @@ typedef void *(*ThreadFunc)(void *);
int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat, int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat,
ThreadFunc thread_open_browser, ThreadFunc thread_mqtt_reconnect, ThreadFunc thread_open_browser, ThreadFunc thread_mqtt_reconnect,
ThreadFunc thread_time_calculation, ThreadFunc thread_play_mp3); ThreadFunc thread_time_calculation, ThreadFunc thread_play_mp3,
ThreadFunc thread_steering_control);
void *thread_exit_time(void *arg) ;//异常停止线程 void *thread_exit_time(void *arg) ;//异常停止线程
void *thread_mqtt_beat(void *arg) ;//心跳线程 void *thread_mqtt_beat(void *arg) ;//心跳线程
void *thread_open_browser(void *arg) ;//启动游览器线程 void *thread_open_browser(void *arg) ;//启动游览器线程
void *thread_mqtt_reconnect(void *arg) ;//mqtt自带重连线程 void *thread_mqtt_reconnect(void *arg) ;//mqtt自带重连线程
void *thread_time_calculation(void *arg) ;//延时计算延迟 void *thread_time_calculation(void *arg) ;//延时计算延迟
void *thread_play_mp3(void* arg);//等待播放音频线程 void *thread_play_mp3(void* arg);//等待播放音频线程
void *thread_steering_control(void *arg);//方向盘控制线程
void thread_end_close() ; void thread_end_close() ;
......
...@@ -809,6 +809,30 @@ drivers/devicecontrol/ship0301_control.c.s: ...@@ -809,6 +809,30 @@ drivers/devicecontrol/ship0301_control.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/devicecontrol/ship0301_control.c.s $(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/devicecontrol/ship0301_control.c.s
.PHONY : drivers/devicecontrol/ship0301_control.c.s .PHONY : drivers/devicecontrol/ship0301_control.c.s
drivers/devicecontrol/steering_control.o: drivers/devicecontrol/steering_control.c.o
.PHONY : drivers/devicecontrol/steering_control.o
# target to build an object file
drivers/devicecontrol/steering_control.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/devicecontrol/steering_control.c.o
.PHONY : drivers/devicecontrol/steering_control.c.o
drivers/devicecontrol/steering_control.i: drivers/devicecontrol/steering_control.c.i
.PHONY : drivers/devicecontrol/steering_control.i
# target to preprocess a source file
drivers/devicecontrol/steering_control.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/devicecontrol/steering_control.c.i
.PHONY : drivers/devicecontrol/steering_control.c.i
drivers/devicecontrol/steering_control.s: drivers/devicecontrol/steering_control.c.s
.PHONY : drivers/devicecontrol/steering_control.s
# target to generate assembly for a file
drivers/devicecontrol/steering_control.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/devicecontrol/steering_control.c.s
.PHONY : drivers/devicecontrol/steering_control.c.s
drivers/devicecontrol/tank0202_control.o: drivers/devicecontrol/tank0202_control.c.o drivers/devicecontrol/tank0202_control.o: drivers/devicecontrol/tank0202_control.c.o
.PHONY : drivers/devicecontrol/tank0202_control.o .PHONY : drivers/devicecontrol/tank0202_control.o
...@@ -2189,6 +2213,9 @@ help: ...@@ -2189,6 +2213,9 @@ help:
@echo "... drivers/devicecontrol/ship0301_control.o" @echo "... drivers/devicecontrol/ship0301_control.o"
@echo "... drivers/devicecontrol/ship0301_control.i" @echo "... drivers/devicecontrol/ship0301_control.i"
@echo "... drivers/devicecontrol/ship0301_control.s" @echo "... drivers/devicecontrol/ship0301_control.s"
@echo "... drivers/devicecontrol/steering_control.o"
@echo "... drivers/devicecontrol/steering_control.i"
@echo "... drivers/devicecontrol/steering_control.s"
@echo "... drivers/devicecontrol/tank0202_control.o" @echo "... drivers/devicecontrol/tank0202_control.o"
@echo "... drivers/devicecontrol/tank0202_control.i" @echo "... drivers/devicecontrol/tank0202_control.i"
@echo "... drivers/devicecontrol/tank0202_control.s" @echo "... drivers/devicecontrol/tank0202_control.s"
......
No preview for this file type
...@@ -6,9 +6,9 @@ CMAKE_PROGRESS_5 = ...@@ -6,9 +6,9 @@ CMAKE_PROGRESS_5 =
CMAKE_PROGRESS_6 = CMAKE_PROGRESS_6 =
CMAKE_PROGRESS_7 = 83 CMAKE_PROGRESS_7 = 83
CMAKE_PROGRESS_8 = CMAKE_PROGRESS_8 =
CMAKE_PROGRESS_9 = CMAKE_PROGRESS_9 = 84
CMAKE_PROGRESS_10 = 84 CMAKE_PROGRESS_10 =
CMAKE_PROGRESS_11 = CMAKE_PROGRESS_11 =
CMAKE_PROGRESS_12 = CMAKE_PROGRESS_12 = 85
CMAKE_PROGRESS_13 = 85 CMAKE_PROGRESS_13 =
...@@ -41,5 +41,5 @@ CMAKE_PROGRESS_40 = ...@@ -41,5 +41,5 @@ CMAKE_PROGRESS_40 =
CMAKE_PROGRESS_41 = CMAKE_PROGRESS_41 =
CMAKE_PROGRESS_42 = 14 CMAKE_PROGRESS_42 = 14
CMAKE_PROGRESS_43 = CMAKE_PROGRESS_43 =
CMAKE_PROGRESS_44 = 15 CMAKE_PROGRESS_44 =
CMAKE_PROGRESS_1 = CMAKE_PROGRESS_1 = 15
CMAKE_PROGRESS_2 = CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3 = 16 CMAKE_PROGRESS_3 =
CMAKE_PROGRESS_4 = CMAKE_PROGRESS_4 = 16
CMAKE_PROGRESS_5 = CMAKE_PROGRESS_5 =
CMAKE_PROGRESS_6 = 17 CMAKE_PROGRESS_6 = 17
CMAKE_PROGRESS_7 = CMAKE_PROGRESS_7 =
...@@ -38,8 +38,8 @@ CMAKE_PROGRESS_37 = ...@@ -38,8 +38,8 @@ CMAKE_PROGRESS_37 =
CMAKE_PROGRESS_38 = CMAKE_PROGRESS_38 =
CMAKE_PROGRESS_39 = 28 CMAKE_PROGRESS_39 = 28
CMAKE_PROGRESS_40 = CMAKE_PROGRESS_40 =
CMAKE_PROGRESS_41 = 29 CMAKE_PROGRESS_41 =
CMAKE_PROGRESS_42 = CMAKE_PROGRESS_42 = 29
CMAKE_PROGRESS_43 = CMAKE_PROGRESS_43 =
CMAKE_PROGRESS_44 = 30 CMAKE_PROGRESS_44 =
CMAKE_PROGRESS_1 = CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 = CMAKE_PROGRESS_2 = 56
CMAKE_PROGRESS_3 = 56 CMAKE_PROGRESS_3 =
CMAKE_PROGRESS_4 = CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = CMAKE_PROGRESS_5 = 57
CMAKE_PROGRESS_6 = 57 CMAKE_PROGRESS_6 =
CMAKE_PROGRESS_7 = CMAKE_PROGRESS_7 =
CMAKE_PROGRESS_8 = 58 CMAKE_PROGRESS_8 = 58
CMAKE_PROGRESS_9 = CMAKE_PROGRESS_9 =
...@@ -31,20 +31,20 @@ CMAKE_PROGRESS_30 = ...@@ -31,20 +31,20 @@ CMAKE_PROGRESS_30 =
CMAKE_PROGRESS_31 = CMAKE_PROGRESS_31 =
CMAKE_PROGRESS_32 = 66 CMAKE_PROGRESS_32 = 66
CMAKE_PROGRESS_33 = CMAKE_PROGRESS_33 =
CMAKE_PROGRESS_34 = CMAKE_PROGRESS_34 = 67
CMAKE_PROGRESS_35 = 67 CMAKE_PROGRESS_35 =
CMAKE_PROGRESS_36 = CMAKE_PROGRESS_36 =
CMAKE_PROGRESS_37 = CMAKE_PROGRESS_37 = 68
CMAKE_PROGRESS_38 = 68 CMAKE_PROGRESS_38 =
CMAKE_PROGRESS_39 = CMAKE_PROGRESS_39 =
CMAKE_PROGRESS_40 = CMAKE_PROGRESS_40 = 69
CMAKE_PROGRESS_41 = 69 CMAKE_PROGRESS_41 =
CMAKE_PROGRESS_42 = CMAKE_PROGRESS_42 =
CMAKE_PROGRESS_43 = CMAKE_PROGRESS_43 = 70
CMAKE_PROGRESS_44 = 70 CMAKE_PROGRESS_44 =
CMAKE_PROGRESS_45 = CMAKE_PROGRESS_45 =
CMAKE_PROGRESS_46 = CMAKE_PROGRESS_46 = 71
CMAKE_PROGRESS_47 = 71 CMAKE_PROGRESS_47 =
CMAKE_PROGRESS_48 = CMAKE_PROGRESS_48 =
CMAKE_PROGRESS_49 = 72 CMAKE_PROGRESS_49 = 72
CMAKE_PROGRESS_50 = CMAKE_PROGRESS_50 =
......
...@@ -24,7 +24,7 @@ void car0101_middle_pwm() {//车停止pwm值 ...@@ -24,7 +24,7 @@ void car0101_middle_pwm() {//车停止pwm值
} }
/*车的速度转向函数*/ /*车的速度转向函数*/
void car0101_mode_1_flont(unsigned char gval) { void car0101_mode_1_flont(int gval) {
int a=0,b=1; int a=0,b=1;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -38,7 +38,7 @@ void car0101_mode_1_flont(unsigned char gval) { ...@@ -38,7 +38,7 @@ void car0101_mode_1_flont(unsigned char gval) {
} }
} }
void car0101_mode_2_back(unsigned char gval) { void car0101_mode_2_back(int gval) {
int b=0,a=1; int b=0,a=1;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -54,7 +54,7 @@ void car0101_mode_2_back(unsigned char gval) { ...@@ -54,7 +54,7 @@ void car0101_mode_2_back(unsigned char gval) {
} }
void car0101_mode_3_left(unsigned char gval) { void car0101_mode_3_left(int gval) {
int b=15; int b=15;
if(gval<45){ if(gval<45){
car_calculate_L_R(90); car_calculate_L_R(90);
...@@ -65,7 +65,7 @@ void car0101_mode_3_left(unsigned char gval) { ...@@ -65,7 +65,7 @@ void car0101_mode_3_left(unsigned char gval) {
} }
} }
void car0101_mode_4_right(unsigned char gval) { void car0101_mode_4_right(int gval) {
int b=10; int b=10;
if(gval<45){ if(gval<45){
car_calculate_L_R(90); car_calculate_L_R(90);
...@@ -76,9 +76,9 @@ void car0101_mode_4_right(unsigned char gval) { ...@@ -76,9 +76,9 @@ void car0101_mode_4_right(unsigned char gval) {
} }
} }
void car0101_control_change(unsigned char *buf) {//车速度和转向引脚数值处理函数 void car0101_control_change(int *buf) {//车速度和转向引脚数值处理函数
unsigned char mode=buf[1]; int mode=buf[1];
unsigned char val=buf[2]; int val=buf[2];
switch(mode){ switch(mode){
case 1: case 1:
car0101_mode_1_flont(val); car0101_mode_1_flont(val);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define CAR0101_CONTROL_H #define CAR0101_CONTROL_H
void car0101_control_change(unsigned char *buf); void car0101_control_change(int *buf);
void car0101_middle_pwm(); void car0101_middle_pwm();
#endif #endif
\ No newline at end of file
...@@ -3,6 +3,34 @@ ...@@ -3,6 +3,34 @@
#include "modules_common.h" #include "modules_common.h"
#include "gpio_common.h" #include "gpio_common.h"
// 控制源: 谁在控制硬件
#define CTRL_NONE 0
#define CTRL_PHONE 1
#define CTRL_STEERING 2
static pthread_mutex_t car0102_hw_mutex = PTHREAD_MUTEX_INITIALIZER;
static int control_source = CTRL_NONE;
// 转向控制变量(方向盘专用)
static int target_angle = 90;
static int current_angle = 90;
static int steering_mode = 0;
static int steering_timeout = 0;
static int steering_cmd_timeout = 0; // 仅由转向消息续期,避免转向残留
// 速度控制变量(方向盘专用)
static int target_speed = 0;
static int current_speed = 0;
static int speed_mode = 0; // 0=停止, 1=前进, 2=后退
static int speed_timeout = 0;
// ===== 方向盘调参区(只建议改这里4个参数) =====
#define STEER_STEP_TURN 10 // 转向时每次变化角度(越大越快)
#define STEER_STEP_RETURN 15 // 回正时每次变化角度(一般略大于转向)
#define REV_TARGET_SCALE_NUM 6 // 后退目标速度比例: 分子
#define REV_TARGET_SCALE_DEN 10 // 后退目标速度比例: 分母 => 6/10=0.6(慢40%)
#define REV_PWM_GAIN 2 // 后退PWM斜率(越小后退越柔和)
//将角度转化为对应的舵机pwm值 //将角度转化为对应的舵机pwm值
void car0102_calculate_L_R(int angle) { void car0102_calculate_L_R(int angle) {
if (angle < 0) { if (angle < 0) {
...@@ -18,11 +46,23 @@ void car0102_calculate_L_R(int angle) { ...@@ -18,11 +46,23 @@ void car0102_calculate_L_R(int angle) {
} }
void car0102_speed_stop() { void car0102_speed_stop() {
pwmWrite(PWM_PIN_SPEED,0); pthread_mutex_lock(&car0102_hw_mutex);
control_source = CTRL_NONE;
target_speed = 0;
current_speed = 0;
speed_mode = 0;
target_angle = 90;
current_angle = 90;
steering_mode = 0;
steering_cmd_timeout = 0;
speed_timeout = 0;
steering_timeout = 0;
pwmWrite(PWM_PIN_SPEED, 0);
car0102_calculate_L_R(90); car0102_calculate_L_R(90);
pthread_mutex_unlock(&car0102_hw_mutex);
} }
void car0102_mode_1_flont(unsigned char gval) { void car0102_mode_1_flont(int gval) {
device_gpio_control(g_device_type,26,1); device_gpio_control(g_device_type,26,1);
if(gval == 0) { if(gval == 0) {
device_gpio_control(g_device_type,26,0); device_gpio_control(g_device_type,26,0);
...@@ -66,7 +106,7 @@ void car0102_mode_1_flont(unsigned char gval) { ...@@ -66,7 +106,7 @@ void car0102_mode_1_flont(unsigned char gval) {
} }
} }
void car0102_mode_2_back(unsigned char gval) { void car0102_mode_2_back(int gval) {
int k = 5; int k = 5;
int b = 100; int b = 100;
device_gpio_control(g_device_type,26,0); device_gpio_control(g_device_type,26,0);
...@@ -109,7 +149,7 @@ void car0102_mode_2_back(unsigned char gval) { ...@@ -109,7 +149,7 @@ void car0102_mode_2_back(unsigned char gval) {
} }
} }
void car0102_mode_3_left(unsigned char gval) { void car0102_mode_3_left(int gval) {
int b=7; int b=7;
if(gval<45){ if(gval<45){
car0102_calculate_L_R(90); car0102_calculate_L_R(90);
...@@ -120,7 +160,7 @@ void car0102_mode_3_left(unsigned char gval) { ...@@ -120,7 +160,7 @@ void car0102_mode_3_left(unsigned char gval) {
} }
} }
void car0102_mode_4_right(unsigned char gval) { void car0102_mode_4_right(int gval) {
int b=7; int b=7;
if(gval<45){ if(gval<45){
car0102_calculate_L_R(90); car0102_calculate_L_R(90);
...@@ -132,24 +172,219 @@ void car0102_mode_4_right(unsigned char gval) { ...@@ -132,24 +172,219 @@ void car0102_mode_4_right(unsigned char gval) {
} }
//车速度和转向引脚数值处理函数 // 手机控制:MQTT线程调用,直接写硬件
void car0102_speed_change(unsigned char *buf) { void car0102_speed_change(int *buf) {
unsigned char mode=buf[1]; int mode = buf[1];
unsigned char val=buf[2]; int val = buf[2];
switch(mode){
case 1: pthread_mutex_lock(&car0102_hw_mutex);
car0102_mode_1_flont(val); control_source = CTRL_PHONE;
break; current_speed = 0;
case 2: speed_timeout = 0;
car0102_mode_2_back(val); steering_timeout = 0;
break;
case 3: switch(mode) {
car0102_mode_3_left(val); case 1: car0102_mode_1_flont(val); break;
break; case 2: car0102_mode_2_back(val); break;
case 4: case 3: car0102_mode_3_left(val); break;
car0102_mode_4_right(val); case 4: car0102_mode_4_right(val); break;
break; default: break;
default: }
break; pthread_mutex_unlock(&car0102_hw_mutex);
}
// 方向盘线程:速度平滑处理(前进后退都慢慢加速,后退最大速度慢一点)
static void car0102_speed_smooth_process() {
if (control_source != CTRL_STEERING) {
return;
}
speed_timeout--;
if (speed_timeout <= 0) {
current_speed = 0;
device_gpio_control(g_device_type, 26, 0);
pwmWrite(PWM_PIN_SPEED, 0);
if (steering_timeout <= 0) {
control_source = CTRL_NONE;
}
return;
}
// 后退目标速度按比例缩小(默认0.6,即比前进慢40%)
int limited_target = target_speed;
if (speed_mode == 2) {
limited_target = (limited_target * REV_TARGET_SCALE_NUM) / REV_TARGET_SCALE_DEN;
}
// 平滑加速/减速步长(减小使加速更平缓)
#define ACCEL_STEP 5
#define DECEL_STEP 6
if (speed_mode == 0) {
if (current_speed > 0) {
current_speed -= DECEL_STEP;
if (current_speed < 0) current_speed = 0;
}
} else if (speed_mode == 1) {
if (current_speed < limited_target) {
current_speed += ACCEL_STEP;
} else if (current_speed > limited_target) {
current_speed -= DECEL_STEP;
}
} else if (speed_mode == 2) {
if (current_speed < limited_target) {
current_speed += ACCEL_STEP;
} else if (current_speed > limited_target) {
current_speed -= DECEL_STEP;
}
}
if (current_speed <= 0) {
device_gpio_control(g_device_type, 26, 0);
pwmWrite(PWM_PIN_SPEED, 0);
} else if (speed_mode == 1) {
device_gpio_control(g_device_type, 26, 1);
pwmWrite(PWM_PIN_SPEED, 1000 - current_speed * 5);
} else if (speed_mode == 2) {
device_gpio_control(g_device_type, 26, 0);
pwmWrite(PWM_PIN_SPEED, 100 + current_speed * REV_PWM_GAIN);
}
}
// 方向盘线程:转向角度平滑处理
static void car0102_steering_angle_smooth_process() {
if (control_source != CTRL_STEERING) {
return;
}
steering_timeout--;
if (steering_timeout <= 0) {
if (speed_timeout <= 0) {
control_source = CTRL_NONE;
}
steering_mode = 0;
target_angle = 90;
return;
}
// 只由转向消息续期。若长时间没有转向输入,则自动回中,避免仅前后控制时残留旧方向
if (steering_cmd_timeout > 0) {
steering_cmd_timeout--;
}
if (steering_cmd_timeout <= 0) {
steering_mode = 0;
target_angle = 90;
}
int wanted_angle = 90;
int input_angle = target_angle;
int smooth_step = STEER_STEP_TURN;
if (input_angle < 0) input_angle = 0;
if (input_angle > 180) input_angle = 180;
if (steering_mode == 3) {
// 左转: 90 -> 130
wanted_angle = 90 + (input_angle * 40) / 180;
} else if (steering_mode == 4) {
// 右转: 90 -> 50
wanted_angle = 90 - (input_angle * 40) / 180;
} else {
wanted_angle = 90;
smooth_step = STEER_STEP_RETURN; // 回正阶段使用更大的步长
}
if (wanted_angle > 130) wanted_angle = 130;
if (wanted_angle < 50) wanted_angle = 50;
// 平滑逼近目标角度,避免持续MQTT造成抖动
if (current_angle < wanted_angle) {
current_angle += smooth_step;
if (current_angle > wanted_angle) current_angle = wanted_angle;
} else if (current_angle > wanted_angle) {
current_angle -= smooth_step;
if (current_angle < wanted_angle) current_angle = wanted_angle;
}
car0102_calculate_L_R(current_angle);
}
// 方向盘线程入口:合并速度+转向平滑,加锁保护
void car0102_steering_smooth_all(void) {
pthread_mutex_lock(&car0102_hw_mutex);
car0102_speed_smooth_process();
car0102_steering_angle_smooth_process();
pthread_mutex_unlock(&car0102_hw_mutex);
}
// MQTT接收处理函数(方向盘专用)
void car0102_control_steering_change_process(int *buf) {
int mode = buf[1];
int val = buf[2];
pthread_mutex_lock(&car0102_hw_mutex);
control_source = CTRL_STEERING;
steering_timeout = 200;
speed_timeout = 200;
if (mode == 1) {
speed_mode = 1;
if (val < 50) {
// 油门置0:立即停车(不走平滑)
target_speed = 0;
current_speed = 0;
speed_mode = 0;
device_gpio_control(g_device_type, 26, 0);
pwmWrite(PWM_PIN_SPEED, 0);
} else if (val <= 200) {
target_speed = val - 40;
} else {
target_speed = 160;
}
} else if (mode == 2) {
speed_mode = 2;
if (val < 50) {
// 刹车/后退置0:立即停车(不走平滑)
target_speed = 0;
current_speed = 0;
speed_mode = 0;
device_gpio_control(g_device_type, 26, 0);
pwmWrite(PWM_PIN_SPEED, 0);
} else if (val <= 200) {
target_speed = (val - 40) * 3 / 4;
} else {
target_speed = 80;
}
} else if (mode == 3) {
if (val == 0) {
// 转向置0:立即回正(不走平滑)
steering_mode = 0;
target_angle = 90;
current_angle = 90;
steering_cmd_timeout = 0;
car0102_calculate_L_R(90);
} else {
steering_cmd_timeout = 60;
target_angle = val;
steering_mode = 3;
if (target_angle < 0) target_angle = 0;
if (target_angle > 180) target_angle = 180;
}
} else if (mode == 4) {
if (val == 0) {
// 转向置0:立即回正(不走平滑)
steering_mode = 0;
target_angle = 90;
current_angle = 90;
steering_cmd_timeout = 0;
car0102_calculate_L_R(90);
} else {
steering_cmd_timeout = 60;
target_angle = val;
steering_mode = 4;
if (target_angle < 0) target_angle = 0;
if (target_angle > 180) target_angle = 180;
}
} }
pthread_mutex_unlock(&car0102_hw_mutex);
} }
\ No newline at end of file
#ifndef CAR0102_CONTROL_H__ #ifndef CAR0102_CONTROL_H__
#define CAR0102_CONTROL_H__ #define CAR0102_CONTROL_H__
void car0102_speed_stop();//小车的停止 void car0102_speed_stop(void);
void car0102_speed_change(int *buf);
void car0102_speed_change(unsigned char *buf);//小车的改变值 void car0102_control_steering_change_process(int *buf);
void car0102_steering_smooth_all(void);
#endif #endif
\ No newline at end of file
...@@ -8,7 +8,7 @@ void car0103_middle() { ...@@ -8,7 +8,7 @@ void car0103_middle() {
pwmWrite(PWM_PIN_CHANGE,75); pwmWrite(PWM_PIN_CHANGE,75);
} }
void mode_car0103_lift_flont(unsigned char gval) { void mode_car0103_lift_flont(int gval) {
int b=1; int b=1;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -23,7 +23,7 @@ void mode_car0103_lift_flont(unsigned char gval) { ...@@ -23,7 +23,7 @@ void mode_car0103_lift_flont(unsigned char gval) {
} }
} }
void mode_car0103_lift_back(unsigned char gval) { void mode_car0103_lift_back(int gval) {
int b=1; int b=1;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -37,7 +37,7 @@ void mode_car0103_lift_back(unsigned char gval) { ...@@ -37,7 +37,7 @@ void mode_car0103_lift_back(unsigned char gval) {
} }
} }
void mode_car0103_right_flont(unsigned char gval) { void mode_car0103_right_flont(int gval) {
int b=1; int b=1;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -51,7 +51,7 @@ void mode_car0103_right_flont(unsigned char gval) { ...@@ -51,7 +51,7 @@ void mode_car0103_right_flont(unsigned char gval) {
} }
} }
void mode_car0103_right_back(unsigned char gval) { void mode_car0103_right_back(int gval) {
int b=1; int b=1;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -66,9 +66,9 @@ void mode_car0103_right_back(unsigned char gval) { ...@@ -66,9 +66,9 @@ void mode_car0103_right_back(unsigned char gval) {
} }
/*挖机的速度处理接口*/ /*挖机的速度处理接口*/
void car0103_change(unsigned char *buf) { void car0103_change(int *buf) {
unsigned char mode = buf[1]; int mode = buf[1];
unsigned char val = buf[2]; int val = buf[2];
static int modecount_car0103=0; static int modecount_car0103=0;
if(mode == 1 ) { if(mode == 1 ) {
//mode_lift_flont(val); //mode_lift_flont(val);
......
...@@ -5,6 +5,6 @@ ...@@ -5,6 +5,6 @@
void car0103_middle(); void car0103_middle();
/*挖机的速度处理接口*/ /*挖机的速度处理接口*/
void car0103_change(unsigned char *buf); void car0103_change(int *buf);
#endif #endif
\ No newline at end of file
...@@ -9,7 +9,7 @@ void car0104_stop() { ...@@ -9,7 +9,7 @@ void car0104_stop() {
} }
//铲车后退 //铲车后退
void car0104_back(unsigned char gval) { void car0104_back(int gval) {
int b=7; int b=7;
int c=2; int c=2;
if (gval < 50) { if (gval < 50) {
...@@ -27,7 +27,7 @@ void car0104_back(unsigned char gval) { ...@@ -27,7 +27,7 @@ void car0104_back(unsigned char gval) {
} }
//铲车前进 //铲车前进
void car0104_flont(unsigned char gval) { void car0104_flont(int gval) {
int b=7; int b=7;
int c=2; int c=2;
if (gval < 50) { if (gval < 50) {
...@@ -44,7 +44,7 @@ void car0104_flont(unsigned char gval) { ...@@ -44,7 +44,7 @@ void car0104_flont(unsigned char gval) {
} }
//铲车右 //铲车右
void car0104_right(unsigned char gval) { void car0104_right(int gval) {
int b=5; int b=5;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -61,7 +61,7 @@ void car0104_right(unsigned char gval) { ...@@ -61,7 +61,7 @@ void car0104_right(unsigned char gval) {
} }
//铲车左 //铲车左
void car0104_lift(unsigned char gval) { void car0104_lift(int gval) {
int b=5; int b=5;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -76,9 +76,9 @@ void car0104_lift(unsigned char gval) { ...@@ -76,9 +76,9 @@ void car0104_lift(unsigned char gval) {
} }
} }
void car0104_change(unsigned char *buf) { void car0104_change(int *buf) {
unsigned char mode = buf[1]; int mode = buf[1];
unsigned char val = buf[2]; int val = buf[2];
if(mode == 1 ) { if(mode == 1 ) {
car0104_flont(val+10); car0104_flont(val+10);
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
void car0104_stop(); void car0104_stop();
void car0104_change(unsigned char *buf); void car0104_change(int *buf);
#endif #endif
\ No newline at end of file
...@@ -308,7 +308,7 @@ void car0105_serial_stop(){ ...@@ -308,7 +308,7 @@ void car0105_serial_stop(){
/*车的速度转向函数*/ /*车的速度转向函数*/
void car0105_mode_1_flont(unsigned char gval) { void car0105_mode_1_flont(int gval) {
if (gval < 50) { if (gval < 50) {
my_zlog_info("val:%d",gval); my_zlog_info("val:%d",gval);
serial_send(&car_serial, forward_close_command, sizeof(forward_close_command)); serial_send(&car_serial, forward_close_command, sizeof(forward_close_command));
...@@ -318,7 +318,7 @@ void car0105_mode_1_flont(unsigned char gval) { ...@@ -318,7 +318,7 @@ void car0105_mode_1_flont(unsigned char gval) {
} }
} }
void car0105_mode_2_back(unsigned char gval) { void car0105_mode_2_back(int gval) {
if (gval < 50) { if (gval < 50) {
serial_send(&car_serial, forward_close_command, sizeof(forward_close_command)); serial_send(&car_serial, forward_close_command, sizeof(forward_close_command));
serial_send(&car_serial, back_close_command, sizeof(back_close_command)); serial_send(&car_serial, back_close_command, sizeof(back_close_command));
...@@ -329,7 +329,7 @@ void car0105_mode_2_back(unsigned char gval) { ...@@ -329,7 +329,7 @@ void car0105_mode_2_back(unsigned char gval) {
} }
void car0105_mode_3_left(unsigned char gval) { void car0105_mode_3_left(int gval) {
if(gval<45){ if(gval<45){
serial_send(&car_serial, left_close_command, sizeof(left_close_command)); serial_send(&car_serial, left_close_command, sizeof(left_close_command));
serial_send(&car_serial, right_close_command, sizeof(right_close_command)); serial_send(&car_serial, right_close_command, sizeof(right_close_command));
...@@ -338,7 +338,7 @@ void car0105_mode_3_left(unsigned char gval) { ...@@ -338,7 +338,7 @@ void car0105_mode_3_left(unsigned char gval) {
} }
} }
void car0105_mode_4_right(unsigned char gval) { void car0105_mode_4_right(int gval) {
if(gval<45){ if(gval<45){
serial_send(&car_serial, left_close_command, sizeof(left_close_command)); serial_send(&car_serial, left_close_command, sizeof(left_close_command));
serial_send(&car_serial, right_close_command, sizeof(right_close_command)); serial_send(&car_serial, right_close_command, sizeof(right_close_command));
...@@ -347,9 +347,9 @@ void car0105_mode_4_right(unsigned char gval) { ...@@ -347,9 +347,9 @@ void car0105_mode_4_right(unsigned char gval) {
} }
} }
void car0105_control_change(unsigned char *buf) {//车速度和转向引脚数值处理函数 void car0105_control_change(int *buf) {//车速度和转向引脚数值处理函数
unsigned char mode=buf[1]; int mode=buf[1];
unsigned char val=buf[2]; int val=buf[2];
serial_stop_index=true; serial_stop_index=true;
switch(mode){ switch(mode){
case 1: case 1:
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
int car0105_serial_run(); int car0105_serial_run();
void car0105_control_change(unsigned char *buf); void car0105_control_change(int *buf);
void car0105_serial_stop(); void car0105_serial_stop();
......
...@@ -222,7 +222,7 @@ void device_end_close(int device_id) { ...@@ -222,7 +222,7 @@ void device_end_close(int device_id) {
} }
void device_walk_control(int device_id,unsigned char *valt) { void device_walk_control(int device_id,int *valt) {
const device_didrive *config = NULL; const device_didrive *config = NULL;
// 查找设备配置 // 查找设备配置
......
...@@ -56,7 +56,7 @@ typedef struct { ...@@ -56,7 +56,7 @@ typedef struct {
typedef struct { typedef struct {
int device_id; // 设备ID (101, 102等) int device_id; // 设备ID (101, 102等)
void (*device_didrive_control)(unsigned char *valt); // PWM初始化函数指针 void (*device_didrive_control)(int *valt); // PWM初始化函数指针
} device_didrive; } device_didrive;
...@@ -65,7 +65,7 @@ void device_stop(int device_id); ...@@ -65,7 +65,7 @@ void device_stop(int device_id);
void device_end_close(int device_id); void device_end_close(int device_id);
void device_walk_control(int device_id,unsigned char *valt); void device_walk_control(int device_id,int *valt);
void device_serial_exit_run(); void device_serial_exit_run();
......
...@@ -208,7 +208,7 @@ void ptz_pwm_stop(void) ...@@ -208,7 +208,7 @@ void ptz_pwm_stop(void)
} }
/* ===================== 指令解析 ===================== */ /* ===================== 指令解析 ===================== */
void PTZ_pwm_change(unsigned char *buf) void PTZ_pwm_change(int *buf)
{ {
// 假设 buf[1] 是命令字,通常协议里会有停止命令(例如 0 或 5) // 假设 buf[1] 是命令字,通常协议里会有停止命令(例如 0 或 5)
// 如果收到 0 或者未定义的命令,应该调用 stop // 如果收到 0 或者未定义的命令,应该调用 stop
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
void ptz0401_pwm_task_function(void *arg); void ptz0401_pwm_task_function(void *arg);
void pwm_PTZ_hz(); void pwm_PTZ_hz();
void PTZ_pwm_init(); void PTZ_pwm_init();
void PTZ_pwm_change(unsigned char *buf); void PTZ_pwm_change(int *buf);
void ptz_pwm_stop(); void ptz_pwm_stop();
#endif #endif
\ No newline at end of file
...@@ -207,7 +207,7 @@ void ptz0404_pwm_stop(void) ...@@ -207,7 +207,7 @@ void ptz0404_pwm_stop(void)
} }
/* ===================== 指令解析 ===================== */ /* ===================== 指令解析 ===================== */
void ptz0404_pwm_change(unsigned char *buf) void ptz0404_pwm_change(int *buf)
{ {
// 假设 buf[1] 是命令字,通常协议里会有停止命令(例如 0 或 5) // 假设 buf[1] 是命令字,通常协议里会有停止命令(例如 0 或 5)
// 如果收到 0 或者未定义的命令,应该调用 stop // 如果收到 0 或者未定义的命令,应该调用 stop
......
...@@ -5,7 +5,7 @@ void ptz0404_pwm_task_function(void *arg); ...@@ -5,7 +5,7 @@ void ptz0404_pwm_task_function(void *arg);
void pwm_ptz0404_hz(); void pwm_ptz0404_hz();
void ptz0404_pwm_init(); void ptz0404_pwm_init();
void ptz0404_pwm_change(unsigned char *buf); void ptz0404_pwm_change(int *buf);
void ptz0404_pwm_stop(); void ptz0404_pwm_stop();
#endif #endif
\ No newline at end of file
...@@ -8,7 +8,7 @@ void ship0301_stop() { ...@@ -8,7 +8,7 @@ void ship0301_stop() {
pwmWrite(PWM_PIN_CHANGE,75); pwmWrite(PWM_PIN_CHANGE,75);
} }
void ship0301_mode_lift_flont(unsigned char gval) { void ship0301_mode_lift_flont(int 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 ship0301_mode_lift_flont(unsigned char gval) { ...@@ -24,7 +24,7 @@ void ship0301_mode_lift_flont(unsigned char gval) {
} }
} }
void ship0301_mode_lift_back(unsigned char gval) { void ship0301_mode_lift_back(int 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 ship0301_mode_lift_back(unsigned char gval) { ...@@ -39,7 +39,7 @@ void ship0301_mode_lift_back(unsigned char gval) {
} }
} }
void ship0301_mode_right_back(unsigned char gval) { void ship0301_mode_right_back(int 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 ship0301_mode_right_back(unsigned char gval) { ...@@ -54,7 +54,7 @@ void ship0301_mode_right_back(unsigned char gval) {
} }
} }
void ship0301_mode_right_flont(unsigned char gval) { void ship0301_mode_right_flont(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -91,10 +91,10 @@ int ship0301_change_grading(int mode){ ...@@ -91,10 +91,10 @@ int ship0301_change_grading(int mode){
} }
void ship0301_change(unsigned char *buf) { void ship0301_change(int *buf) {
unsigned char type = buf[0]; int type = buf[0];
unsigned char mode = buf[1]; int mode = buf[1];
unsigned char val = buf[2]; int val = buf[2];
static int ship0301_steering_t=0; static int ship0301_steering_t=0;
static int ship0301_front_t =0; static int ship0301_front_t =0;
......
...@@ -5,5 +5,5 @@ ...@@ -5,5 +5,5 @@
void ship0301_stop(); void ship0301_stop();
void ship0301_change(unsigned char *buf); void ship0301_change(int *buf);
#endif #endif
\ No newline at end of file
#include "steering_control.h"
#include "devcontrol_common.h"
#include "gpio_common.h"
static SteeringControl s_steering_devices[] = {
{DEVICE_CAR0101, "car0101", NULL, NULL},
{DEVICE_CAR0102, "car0102", car0102_control_steering_change_process, car0102_steering_smooth_all},
{DEVICE_CAR0103, "car0103", NULL, NULL},
{DEVICE_CAR0104, "car0104", NULL, NULL},
{DEVICE_CAR0105, "car0105", NULL, NULL},
{DEVICE_TANK0202, "tank0202", NULL, NULL},
{DEVICE_TANK0203, "tank0203", NULL, NULL},
{DEVICE_TANK0204, "tank0204", NULL, NULL},
{DEVICE_TANK0206, "tank0206", NULL, NULL},
{DEVICE_TANK0207, "tank0207", NULL, NULL},
{0, "unknown", NULL, NULL}
};
SteeringControl* get_steering_control(void)
{
int i = 0;
while (s_steering_devices[i].id != 0) {
if (s_steering_devices[i].id == g_device_type) {
return &s_steering_devices[i];
}
i++;
}
return NULL;
}
// 线程调用:通过结构体分发到对应设备的平滑处理函数
void steering_control_process(void) {
static SteeringControl *ctrl = NULL;
if (ctrl == NULL) {
my_zlog_info("steering_control_process: ctrl is NULL");
ctrl = get_steering_control();
}
if (ctrl && ctrl->smooth_process_func) {
ctrl->smooth_process_func();
}
}
// MQTT调用:通过结构体分发到对应设备的方向盘接收函数
void steering_mqtt_recv(cJSON *body) {
static SteeringControl *ctrl = NULL;
if (ctrl == NULL) {
ctrl = get_steering_control();
}
if (ctrl && ctrl->mqtt_recv_func) {
cJSON *pwm_ctrl = cJSON_GetObjectItem(body, "pwm_ctrl");
cJSON *pin_setctrl = cJSON_GetObjectItem(body, "pin_setctrl");
if (pwm_ctrl == NULL || pin_setctrl == NULL)
{
return;
}
cJSON *mode = cJSON_GetObjectItem(pwm_ctrl, "mode"); // mode=1 速度,mode=2 转向(unsigned char)
cJSON *type = cJSON_GetObjectItem(pwm_ctrl, "type");
cJSON *val = cJSON_GetObjectItem(pwm_ctrl, "val"); // val为pwm的值 0~100(unsigned char)(unsigned char)
int modeTemp = mode->valueint;
int typeTemp = type->valueint;
int valTemp = val->valueint;
int buf[3]={typeTemp,modeTemp,valTemp};
my_zlog_debug("typeTemp:%d,modeTemp:%d,valTemp:%d", buf[0], buf[1], buf[2]);
ctrl->mqtt_recv_func(buf);
}
}
#ifndef STEERING_CONTROL_H__
#define STEERING_CONTROL_H__
#include "common.h"
typedef struct {
int id;
char name[32];
void (*mqtt_recv_func)(int *buf); // 方向盘MQTT数据处理(buf[0]=mode, buf[1]=val)
void (*smooth_process_func)(void); // 线程平滑处理(速度+转向合并)
} SteeringControl;
SteeringControl* get_steering_control(void);
void steering_control_process(void);
void steering_mqtt_recv(cJSON *body);
#endif
...@@ -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_right(unsigned char gval) { void mode_right(int 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_right(unsigned char gval) { ...@@ -26,7 +26,7 @@ void mode_right(unsigned char gval) {
} }
} }
void mode_lift(unsigned char gval) { void mode_lift(int 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(unsigned char gval) { ...@@ -41,7 +41,7 @@ void mode_lift(unsigned char gval) {
} }
} }
void mode_flont(unsigned char gval) { void mode_flont(int 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_flont(unsigned char gval) { ...@@ -56,7 +56,7 @@ void mode_flont(unsigned char gval) {
} }
} }
void mode_back(unsigned char gval) { void mode_back(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -97,10 +97,10 @@ int tank0202_change_grading(int mode){ ...@@ -97,10 +97,10 @@ int tank0202_change_grading(int mode){
return mode_val; return mode_val;
} }
void tank0202_change(unsigned char *buf) { void tank0202_change(int *buf) {
unsigned char type = buf[0]; int type = buf[0];
unsigned char mode = buf[1]; int mode = buf[1];
unsigned char val = buf[2]; int val = buf[2];
static int tank0202_steering_t=0; static int tank0202_steering_t=0;
static int tank0202_front_t =0; static int tank0202_front_t =0;
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
void tank0202_middle(); void tank0202_middle();
void tank0202_change(unsigned char *buf); void tank0202_change(int *buf);
#endif #endif
\ No newline at end of file
...@@ -12,7 +12,7 @@ void tank0203_middle() { ...@@ -12,7 +12,7 @@ void tank0203_middle() {
pwmWrite(PWM_PIN_CHANGE,75); pwmWrite(PWM_PIN_CHANGE,75);
} }
void tank0203_mode_lift_flont(unsigned char gval) { void tank0203_mode_lift_flont(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -28,7 +28,7 @@ void tank0203_mode_lift_flont(unsigned char gval) { ...@@ -28,7 +28,7 @@ void tank0203_mode_lift_flont(unsigned char gval) {
} }
} }
void tank0203_mode_lift_back(unsigned char gval) { void tank0203_mode_lift_back(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -43,7 +43,7 @@ void tank0203_mode_lift_back(unsigned char gval) { ...@@ -43,7 +43,7 @@ void tank0203_mode_lift_back(unsigned char gval) {
} }
} }
void tank0203_mode_right_back(unsigned char gval) { void tank0203_mode_right_back(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -58,7 +58,7 @@ void tank0203_mode_right_back(unsigned char gval) { ...@@ -58,7 +58,7 @@ void tank0203_mode_right_back(unsigned char gval) {
} }
} }
void tank0203_mode_right_flont(unsigned char gval) { void tank0203_mode_right_flont(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -100,10 +100,10 @@ int tank0203_change_grading(int mode){ ...@@ -100,10 +100,10 @@ int tank0203_change_grading(int mode){
//tank0203控制函数 //tank0203控制函数
void tank0203_change(unsigned char *buf) { void tank0203_change(int *buf) {
unsigned char type = buf[0]; int type = buf[0];
unsigned char mode = buf[1]; int mode = buf[1];
unsigned char val = buf[2]; int val = buf[2];
static int tank0203_steering_t=0; static int tank0203_steering_t=0;
static int tank0203_front_t =0; static int tank0203_front_t =0;
static int tank0203_front_val=0; static int tank0203_front_val=0;
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
void tank0203_middle(); void tank0203_middle();
void tank0203_change(unsigned char *buf); void tank0203_change(int *buf);
#endif #endif
\ No newline at end of file
...@@ -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(unsigned char gval) { void tank0204_mode_lift(int 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(unsigned char gval) { ...@@ -24,7 +24,7 @@ void tank0204_mode_lift(unsigned char gval) {
} }
} }
void tank0204_mode_right(unsigned char gval) { void tank0204_mode_right(int 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_right(unsigned char gval) { ...@@ -39,7 +39,7 @@ void tank0204_mode_right(unsigned char gval) {
} }
} }
void tank0204_mode_flont(unsigned char gval) { void tank0204_mode_flont(int 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_flont(unsigned char gval) { ...@@ -54,7 +54,7 @@ void tank0204_mode_flont(unsigned char gval) {
} }
} }
void tank0204_mode_back(unsigned char gval) { void tank0204_mode_back(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -94,10 +94,10 @@ int tank0204_change_grading(int mode){ ...@@ -94,10 +94,10 @@ int tank0204_change_grading(int mode){
return mode_val; return mode_val;
} }
void tank0204_change(unsigned char *buf) { void tank0204_change(int *buf) {
unsigned char type = buf[0]; int type = buf[0];
unsigned char mode = buf[1]; int mode = buf[1];
unsigned char val = buf[2]; int val = buf[2];
static int tank0204_steering_t=0; static int tank0204_steering_t=0;
static int tank0204_front_t =0; static int tank0204_front_t =0;
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
void tank0204_stop(); void tank0204_stop();
void tank0204_change(unsigned char *buf); void tank0204_change(int *buf);
#endif #endif
\ No newline at end of file
...@@ -8,7 +8,7 @@ void tank0206_middle() { ...@@ -8,7 +8,7 @@ void tank0206_middle() {
pwmWrite(PWM_PIN_CHANGE,75); pwmWrite(PWM_PIN_CHANGE,75);
} }
void tank0206_mode_lift_flont(unsigned char gval) { void tank0206_mode_lift_flont(int 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 tank0206_mode_lift_flont(unsigned char gval) { ...@@ -26,7 +26,7 @@ void tank0206_mode_lift_flont(unsigned char gval) {
} }
} }
void tank0206_mode_lift_back(unsigned char gval) { void tank0206_mode_lift_back(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -43,7 +43,7 @@ void tank0206_mode_lift_back(unsigned char gval) { ...@@ -43,7 +43,7 @@ void tank0206_mode_lift_back(unsigned char gval) {
} }
} }
void tank0206_mode_right_flont(unsigned char gval) { void tank0206_mode_right_flont(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
...@@ -62,7 +62,7 @@ void tank0206_mode_right_flont(unsigned char gval) { ...@@ -62,7 +62,7 @@ void tank0206_mode_right_flont(unsigned char gval) {
} }
} }
void tank0206_mode_right_back(unsigned char gval) { void tank0206_mode_right_back(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -110,10 +110,10 @@ int tank0206_change_grading(int mode){ ...@@ -110,10 +110,10 @@ int tank0206_change_grading(int mode){
return mode_val; return mode_val;
} }
void tank0206_change(unsigned char *buf) { void tank0206_change(int *buf) {
unsigned char type = buf[0]; int type = buf[0];
unsigned char mode = buf[1]; int mode = buf[1];
unsigned char val = buf[2]; int val = buf[2];
static int tank0206_steering_t=0; static int tank0206_steering_t=0;
static int tank0206_front_t =0; static int tank0206_front_t =0;
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
void tank0206_middle(); void tank0206_middle();
void tank0206_change(unsigned char *buf); void tank0206_change(int *buf);
#endif #endif
\ No newline at end of file
...@@ -8,7 +8,7 @@ void tank0207_middle() { ...@@ -8,7 +8,7 @@ void tank0207_middle() {
pwmWrite(PWM_PIN_CHANGE,75); pwmWrite(PWM_PIN_CHANGE,75);
} }
void tank0207_mode_lift_flont(unsigned char gval) { void tank0207_mode_lift_flont(int 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 tank0207_mode_lift_flont(unsigned char gval) { ...@@ -26,7 +26,7 @@ void tank0207_mode_lift_flont(unsigned char gval) {
} }
} }
void tank0207_mode_lift_back(unsigned char gval) { void tank0207_mode_lift_back(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75); pwmWrite(PWM_PIN_SPEED, 75);
...@@ -43,7 +43,7 @@ void tank0207_mode_lift_back(unsigned char gval) { ...@@ -43,7 +43,7 @@ void tank0207_mode_lift_back(unsigned char gval) {
} }
} }
void tank0207_mode_right_flont(unsigned char gval) { void tank0207_mode_right_flont(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
...@@ -62,7 +62,7 @@ void tank0207_mode_right_flont(unsigned char gval) { ...@@ -62,7 +62,7 @@ void tank0207_mode_right_flont(unsigned char gval) {
} }
} }
void tank0207_mode_right_back(unsigned char gval) { void tank0207_mode_right_back(int gval) {
int b=0; int b=0;
if (gval < 50) { if (gval < 50) {
pwmWrite(PWM_PIN_CHANGE, 75); pwmWrite(PWM_PIN_CHANGE, 75);
...@@ -110,10 +110,10 @@ int tank0207_change_grading(int mode){ ...@@ -110,10 +110,10 @@ int tank0207_change_grading(int mode){
return mode_val; return mode_val;
} }
void tank0207_change(unsigned char *buf) { void tank0207_change(int *buf) {
unsigned char type = buf[0]; int type = buf[0];
unsigned char mode = buf[1]; int mode = buf[1];
unsigned char val = buf[2]; int val = buf[2];
static int tank0207_steering_t=0; static int tank0207_steering_t=0;
static int tank0207_front_t =0; static int tank0207_front_t =0;
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
void tank0207_middle(); void tank0207_middle();
void tank0207_change(unsigned char *buf); void tank0207_change(int *buf);
#endif #endif
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "modules_common.h" #include "modules_common.h"
#include "gpio_common.h" #include "gpio_common.h"
int tank_shot_back_stop(unsigned char pin,unsigned char val); int tank_shot_back_stop(int pin,int val);
const tank_common_back *g_tank_common_config_t = NULL; const tank_common_back *g_tank_common_config_t = NULL;
...@@ -11,10 +11,10 @@ int g_tank_shot_index=0;//状态机,用于状态机,坦克接收射击倒退 ...@@ -11,10 +11,10 @@ int g_tank_shot_index=0;//状态机,用于状态机,坦克接收射击倒退
static bool s_tank_shot_index_cool=1;//状态机,用于冷却状态机,坦克接收射击倒退状态机全局变量 static bool s_tank_shot_index_cool=1;//状态机,用于冷却状态机,坦克接收射击倒退状态机全局变量
/*击打后退速度设置,混空模式下为单路,单独模式下为双路控制,后续需要优化*/ /*击打后退速度设置,混空模式下为单路,单独模式下为双路控制,后续需要优化*/
void tank_shot_back(unsigned char gval) { void tank_shot_back(int gval) {
int b=0; int b=0;
unsigned char valt[3]={0}; int valt[3]={0};
valt[1]=2; valt[1]=2;
if(gval==0) valt[2]=0; if(gval==0) valt[2]=0;
else valt[2]=gval; else valt[2]=gval;
...@@ -197,7 +197,7 @@ void tank_shot_pthrpoll_task_init(){ ...@@ -197,7 +197,7 @@ void tank_shot_pthrpoll_task_init(){
} }
/*坦克后退射击*/ /*坦克后退射击*/
int tank_shot_back_stop(unsigned char pin,unsigned char val){ int tank_shot_back_stop(int pin,int val){
if(pin !=27){ if(pin !=27){
my_zlog_debug("非27引脚"); my_zlog_debug("非27引脚");
...@@ -235,7 +235,7 @@ void device_poilthread_close(){ ...@@ -235,7 +235,7 @@ void device_poilthread_close(){
} }
/*坦克射击接口,只有在特定设备号下使用*/ /*坦克射击接口,只有在特定设备号下使用*/
void tank_shot_stop_control(int device_id,unsigned char pin,unsigned char val) { void tank_shot_stop_control(int device_id,int pin,int val) {
if (!g_tank_common_config_t || g_tank_common_config_t->device_id != device_id) { if (!g_tank_common_config_t || g_tank_common_config_t->device_id != device_id) {
// 查找设备配置 // 查找设备配置
......
...@@ -8,7 +8,7 @@ typedef struct { ...@@ -8,7 +8,7 @@ typedef struct {
int back_time; int back_time;
int back_interval_back; int back_interval_back;
int shot_back_speed; int shot_back_speed;
int(*shot_back)(unsigned char pin,unsigned char val); int(*shot_back)(int pin,int val);
} tank_common_back; } tank_common_back;
typedef enum { typedef enum {
...@@ -17,7 +17,7 @@ typedef enum { ...@@ -17,7 +17,7 @@ typedef enum {
}shot_state; }shot_state;
/*坦克射击接口,只有在特定设备号下使用*/ /*坦克射击接口,只有在特定设备号下使用*/
void tank_shot_stop_control(int device_id,unsigned char pin,unsigned char val); void tank_shot_stop_control(int device_id,int pin,int val);
/*设置后退的时间重置s*/ /*设置后退的时间重置s*/
void set_tank_shot_index_cool(bool index); void set_tank_shot_index_cool(bool index);
......
...@@ -64,7 +64,7 @@ void set_self_control_time_countfuntion(){ ...@@ -64,7 +64,7 @@ void set_self_control_time_countfuntion(){
void self_device_control_task(){ void self_device_control_task(){
static int i=0; static int i=0;
static unsigned char valt[3]; static int valt[3];
int time_now = g_self_control_time_count*20; int time_now = g_self_control_time_count*20;
......
...@@ -6,5 +6,6 @@ ...@@ -6,5 +6,6 @@
#include "ip_reader.h" #include "ip_reader.h"
#include "sensors_common.h" #include "sensors_common.h"
#include"self_devicecontrol.h" #include"self_devicecontrol.h"
#include "steering_control.h"
#endif #endif
\ No newline at end of file
...@@ -15,7 +15,7 @@ int g_devcontrol_exit_count = 0; ...@@ -15,7 +15,7 @@ int g_devcontrol_exit_count = 0;
int g_message_type = 0; // 接收的mqtt的g_message_type int g_message_type = 0; // 接收的mqtt的g_message_type
static unsigned char g_valt[4]; // 存放mqtt接收的tpye,mode等 static int g_valt[4]; // 存放mqtt接收的tpye,mode等
// 心跳发送格式*5/2 // 心跳发送格式*5/2
void heartbeat_send() void heartbeat_send()
...@@ -155,9 +155,9 @@ void message_3(cJSON *body) ...@@ -155,9 +155,9 @@ void message_3(cJSON *body)
cJSON *type = cJSON_GetObjectItem(pwm_ctrl, "type"); cJSON *type = cJSON_GetObjectItem(pwm_ctrl, "type");
cJSON *val = cJSON_GetObjectItem(pwm_ctrl, "val"); // val为pwm的值 0~100(unsigned char)(unsigned char) cJSON *val = cJSON_GetObjectItem(pwm_ctrl, "val"); // val为pwm的值 0~100(unsigned char)(unsigned char)
unsigned char modeTemp = mode->valueint; int modeTemp = mode->valueint;
unsigned char typeTemp = type->valueint; int typeTemp = type->valueint;
unsigned char valTemp = val->valueint; int valTemp = val->valueint;
g_valt[0] = typeTemp; g_valt[0] = typeTemp;
g_valt[1] = modeTemp; g_valt[1] = modeTemp;
...@@ -182,8 +182,8 @@ void message_4(cJSON *body) ...@@ -182,8 +182,8 @@ void message_4(cJSON *body)
cJSON *pin = cJSON_GetObjectItem(pin_setctrl, "pin"); cJSON *pin = cJSON_GetObjectItem(pin_setctrl, "pin");
cJSON *val = cJSON_GetObjectItem(pin_setctrl, "val"); // val为pwm的值 0~100(unsigned char)(unsigned char) cJSON *val = cJSON_GetObjectItem(pin_setctrl, "val"); // val为pwm的值 0~100(unsigned char)(unsigned char)
unsigned char pinTemp = pin->valueint; int pinTemp = pin->valueint;
unsigned char valTemp = val->valueint; int valTemp = val->valueint;
if (valTemp >= 1) if (valTemp >= 1)
{ {
...@@ -265,6 +265,27 @@ void message_4_judyverify(cJSON *body) ...@@ -265,6 +265,27 @@ void message_4_judyverify(cJSON *body)
} }
} }
void message_6_steering_judyverify(cJSON *body)
{
if (VERIFIED_MODE == FALSE)
{
steering_mqtt_recv(body);
my_zlog_warn("不使用验证");
return;
}
receive_jwt(body);
if (g_verify_index == 0)
{
steering_mqtt_recv(body);
}
else
{
my_zlog_warn("验证不通过");
}
}
// 接收到设备改名函数 // 接收到设备改名函数
int device_mqttchange_name(cJSON *device_id) int device_mqttchange_name(cJSON *device_id)
{ {
...@@ -323,6 +344,10 @@ int device_message_receive(cJSON *json) ...@@ -323,6 +344,10 @@ int device_message_receive(cJSON *json)
audio_speaker_init(); audio_speaker_init();
my_zlog_debug("执行麦和喇叭命令"); my_zlog_debug("执行麦和喇叭命令");
break; break;
case 6:
message_6_steering_judyverify(body);
my_zlog_debug("执行方向盘命令");
break;
case 2001: case 2001:
audioplay_mqtt_receive(body); audioplay_mqtt_receive(body);
my_zlog_debug("进入音频播放"); my_zlog_debug("进入音频播放");
......
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