Commit 00e9e89a authored by 957dd's avatar 957dd

小车加入击打

parent 29e01fc4
...@@ -93,6 +93,7 @@ int hash_insert_init(HashTable_t *HashTable_t) { ...@@ -93,6 +93,7 @@ int hash_insert_init(HashTable_t *HashTable_t) {
insert(HashTable_t, "0104", CAR_0104); insert(HashTable_t, "0104", CAR_0104);
insert(HashTable_t, "0105", CAR_0105); insert(HashTable_t, "0105", CAR_0105);
insert(HashTable_t, "0106", CAR_0106); insert(HashTable_t, "0106", CAR_0106);
insert(HashTable_t, "0107", CAR_0107);
insert(HashTable_t, "0201", TANK_0201); insert(HashTable_t, "0201", TANK_0201);
insert(HashTable_t, "0202", TANK_0202); insert(HashTable_t, "0202", TANK_0202);
insert(HashTable_t, "0203", TANK_0203); insert(HashTable_t, "0203", TANK_0203);
...@@ -130,6 +131,9 @@ int device_judg(CodeEnum_t code,char *sub_str) { ...@@ -130,6 +131,9 @@ int device_judg(CodeEnum_t code,char *sub_str) {
}else if (code == CAR_0106) { }else if (code == CAR_0106) {
device_init(DEVICE_CAR0106); device_init(DEVICE_CAR0106);
my_zlog_info("使用F1赛车(双电机大板),型号%s", sub_str); my_zlog_info("使用F1赛车(双电机大板),型号%s", sub_str);
}else if (code == CAR_0107) {
device_init(DEVICE_CAR0107);
my_zlog_info("使用大众POLO R,型号%s", sub_str);
}else if(code == TANK_0202) { }else if(code == TANK_0202) {
device_init(DEVICE_TANK0202); device_init(DEVICE_TANK0202);
my_zlog_info("使用型号%s",sub_str); my_zlog_info("使用型号%s",sub_str);
......
...@@ -14,6 +14,7 @@ typedef enum { ...@@ -14,6 +14,7 @@ typedef enum {
CAR_0104, CAR_0104,
CAR_0105, CAR_0105,
CAR_0106, CAR_0106,
CAR_0107,
TANK_0201, TANK_0201,
TANK_0202, TANK_0202,
TANK_0203, TANK_0203,
......
No preview for this file type
...@@ -3,6 +3,7 @@ file(GLOB_RECURSE DRIVERS_SOURCES ...@@ -3,6 +3,7 @@ file(GLOB_RECURSE DRIVERS_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/network/*.c ${CMAKE_CURRENT_SOURCE_DIR}/network/*.c
${CMAKE_CURRENT_SOURCE_DIR}/sensors/*.c ${CMAKE_CURRENT_SOURCE_DIR}/sensors/*.c
${CMAKE_CURRENT_SOURCE_DIR}/devicecontrol/*.c ${CMAKE_CURRENT_SOURCE_DIR}/devicecontrol/*.c
${CMAKE_CURRENT_SOURCE_DIR}/devicecontrol/*/*.c
${CMAKE_CURRENT_SOURCE_DIR}/selfcontrol/*.c ${CMAKE_CURRENT_SOURCE_DIR}/selfcontrol/*.c
) )
...@@ -16,6 +17,13 @@ set(DRIVERS_INCLUDE_DIRS ...@@ -16,6 +17,13 @@ set(DRIVERS_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/network ${CMAKE_CURRENT_SOURCE_DIR}/network
${CMAKE_CURRENT_SOURCE_DIR}/sensors ${CMAKE_CURRENT_SOURCE_DIR}/sensors
${CMAKE_CURRENT_SOURCE_DIR}/devicecontrol ${CMAKE_CURRENT_SOURCE_DIR}/devicecontrol
${CMAKE_CURRENT_SOURCE_DIR}/devicecontrol/common
${CMAKE_CURRENT_SOURCE_DIR}/devicecontrol/car
${CMAKE_CURRENT_SOURCE_DIR}/devicecontrol/tank
${CMAKE_CURRENT_SOURCE_DIR}/devicecontrol/ship
${CMAKE_CURRENT_SOURCE_DIR}/devicecontrol/ptz
${CMAKE_CURRENT_SOURCE_DIR}/devicecontrol/robot
${CMAKE_CURRENT_SOURCE_DIR}/devicecontrol/gps
${CMAKE_CURRENT_SOURCE_DIR}/selfcontrol ${CMAKE_CURRENT_SOURCE_DIR}/selfcontrol
PARENT_SCOPE PARENT_SCOPE
) )
#include "car0102_pin27_common.h"
#include "devcontrol_common.h"
#include "modules_common.h"
#include "gpio_common.h"
#define CAR0102_PIN27_PWM_DUTY 60
#define CAR0102_PIN27_STEP_MS 1000
#define CAR0102_PIN27_PIN_FWD 5
#define CAR0102_PIN27_PIN_REV 7
#define CAR0102_PIN27_IDLE_POLL_MS 10
#define CAR0102_PIN27_WAIT_SLICE_MS 10
typedef struct {
pthread_mutex_t mutex;
ThreadPool_t *pool;
car0102_pin27_runtime_t runtime;
} car0102_pin27_ctx_t;
static car0102_pin27_ctx_t s_pin27_ctx = {
.mutex = PTHREAD_MUTEX_INITIALIZER,
.pool = NULL,
.runtime.v = {
.fsm = CAR0102_PIN27_FSM_NONE,
.active = false,
},
};
static void car0102_pin27_lock(void)
{
pthread_mutex_lock(&s_pin27_ctx.mutex);
}
static void car0102_pin27_unlock(void)
{
pthread_mutex_unlock(&s_pin27_ctx.mutex);
}
static car0102_pin27_runtime_t car0102_pin27_runtime_get(void)
{
car0102_pin27_runtime_t rt;
car0102_pin27_lock();
rt = s_pin27_ctx.runtime;
car0102_pin27_unlock();
return rt;
}
static void car0102_pin27_pwm_stop_locked(void)
{
softPwmWrite(CAR0102_PIN27_PIN_FWD, 0);
softPwmWrite(CAR0102_PIN27_PIN_REV, 0);
}
static void car0102_pin27_pwm_stop(void)
{
car0102_pin27_lock();
car0102_pin27_pwm_stop_locked();
car0102_pin27_unlock();
}
static void car0102_pin27_pwm_apply_locked(int fwd_duty, int rev_duty)
{
if (!s_pin27_ctx.runtime.v.active) {
car0102_pin27_pwm_stop_locked();
return;
}
softPwmWrite(CAR0102_PIN27_PIN_FWD, fwd_duty);
softPwmWrite(CAR0102_PIN27_PIN_REV, rev_duty);
}
static void car0102_pin27_pwm_apply(int fwd_duty, int rev_duty)
{
car0102_pin27_lock();
car0102_pin27_pwm_apply_locked(fwd_duty, rev_duty);
car0102_pin27_unlock();
}
/*
* 可中断等待:每 10ms 睡眠一次并检查 active,避免忙等占满 CPU。
* 序列执行期间不持锁,防止长时间阻塞 MQTT 线程。
*/
static void car0102_pin27_delay_ms_interruptible(int ms)
{
car0102_pin27_runtime_t rt;
int elapsed = 0;
while (elapsed < ms) {
rt = car0102_pin27_runtime_get();
if (!rt.v.active) {
return;
}
delay_ms(CAR0102_PIN27_WAIT_SLICE_MS);
elapsed += CAR0102_PIN27_WAIT_SLICE_MS;
}
}
static void car0102_pin27_sequence_run(void)
{
my_zlog_info("car0102 pin27 sequence start: pin%d %d%% %dms",
CAR0102_PIN27_PIN_FWD, CAR0102_PIN27_PWM_DUTY, CAR0102_PIN27_STEP_MS);
car0102_pin27_pwm_apply(CAR0102_PIN27_PWM_DUTY, 0);
car0102_pin27_delay_ms_interruptible(CAR0102_PIN27_STEP_MS);
if (!car0102_pin27_runtime_get().v.active) {
car0102_pin27_pwm_stop();
return;
}
car0102_pin27_pwm_apply(0, CAR0102_PIN27_PWM_DUTY);
my_zlog_info("car0102 pin27 sequence step2: pin%d %d%% %dms",
CAR0102_PIN27_PIN_REV, CAR0102_PIN27_PWM_DUTY, CAR0102_PIN27_STEP_MS);
car0102_pin27_delay_ms_interruptible(CAR0102_PIN27_STEP_MS);
car0102_pin27_pwm_stop();
my_zlog_info("car0102 pin27 sequence done");
}
static void car0102_pin27_task_function(void *arg)
{
if (arg != NULL) {
free(arg);
}
my_zlog_info("car0102 pin27 thread task start");
while (1) {
bool run_sequence = false;
car0102_pin27_lock();
if (s_pin27_ctx.runtime.v.fsm == CAR0102_PIN27_FSM_PENDING &&
s_pin27_ctx.runtime.v.active) {
s_pin27_ctx.runtime.v.fsm = CAR0102_PIN27_FSM_RUNNING;
run_sequence = true;
}
car0102_pin27_unlock();
if (run_sequence) {
car0102_pin27_sequence_run();
car0102_pin27_lock();
if (s_pin27_ctx.runtime.v.fsm == CAR0102_PIN27_FSM_RUNNING) {
s_pin27_ctx.runtime.v.fsm = CAR0102_PIN27_FSM_IDLE;
}
car0102_pin27_unlock();
}
delay_ms(CAR0102_PIN27_IDLE_POLL_MS);
}
}
static int car0102_pin27_pthrpoll_task_init(void)
{
int *arg;
ThreadPool_t *pool;
car0102_pin27_lock();
if (s_pin27_ctx.pool != NULL) {
car0102_pin27_unlock();
return 0;
}
car0102_pin27_unlock();
arg = malloc(sizeof(int));
if (arg == NULL) {
my_zlog_error("car0102 pin27 thread arg alloc failed");
return -1;
}
*arg = 1;
pool = thread_pool_init(1, 1);
if (pool == NULL) {
my_zlog_error("car0102 pin27 thread_pool_init failed");
free(arg);
return -1;
}
if (thread_pool_add_task(pool, car0102_pin27_task_function, arg) != 0) {
my_zlog_error("car0102 pin27 thread_pool_add_task failed");
thread_pool_destroy(pool);
free(arg);
return -1;
}
car0102_pin27_lock();
s_pin27_ctx.pool = pool;
car0102_pin27_unlock();
my_zlog_info("car0102 pin27 thread pool opened");
return 0;
}
static int car0102_pin27_handle(int pin, int val)
{
bool need_init = false;
int rc = 0;
if (pin != 27) {
return 1;
}
car0102_pin27_lock();
if (val == 0) {
s_pin27_ctx.runtime.v.active = false;
car0102_pin27_pwm_stop_locked();
car0102_pin27_unlock();
return 0;
}
s_pin27_ctx.runtime.v.active = true;
if (s_pin27_ctx.runtime.v.fsm == CAR0102_PIN27_FSM_NONE) {
need_init = true;
s_pin27_ctx.runtime.v.fsm = CAR0102_PIN27_FSM_IDLE;
}
if (s_pin27_ctx.runtime.v.fsm == CAR0102_PIN27_FSM_IDLE) {
s_pin27_ctx.runtime.v.fsm = CAR0102_PIN27_FSM_PENDING;
}
car0102_pin27_unlock();
if (need_init) {
rc = car0102_pin27_pthrpoll_task_init();
if (rc != 0) {
car0102_pin27_lock();
s_pin27_ctx.runtime.v.fsm = CAR0102_PIN27_FSM_NONE;
s_pin27_ctx.runtime.v.active = false;
car0102_pin27_unlock();
}
}
return rc;
}
void car0102_pin27_stop_control(int device_id, int pin, int val)
{
if (device_id != DEVICE_CAR0102) {
return;
}
car0102_pin27_handle(pin, val);
}
void car0102_pin27_thread_close(void)
{
ThreadPool_t *pool = NULL;
car0102_pin27_lock();
s_pin27_ctx.runtime.v.active = false;
car0102_pin27_pwm_stop_locked();
pool = s_pin27_ctx.pool;
s_pin27_ctx.pool = NULL;
s_pin27_ctx.runtime.v.fsm = CAR0102_PIN27_FSM_NONE;
car0102_pin27_unlock();
if (pool != NULL) {
thread_pool_destroy(pool);
}
my_zlog_info("car0102 pin27 thread pool closed");
}
#ifndef CAR0102_PIN27_COMMON_H__
#define CAR0102_PIN27_COMMON_H__
#include "common.h"
/* pin27 正反转序列状态机 */
typedef enum {
CAR0102_PIN27_FSM_NONE = 0, /* 未创建线程池 */
CAR0102_PIN27_FSM_IDLE, /* 线程空闲,可接收新触发 */
CAR0102_PIN27_FSM_PENDING, /* 已入队,待工作线程执行 */
CAR0102_PIN27_FSM_RUNNING, /* 正反转序列执行中 */
} car0102_pin27_fsm_t;
/* 受互斥锁保护的运行态(fsm + active 成组读写) */
typedef union {
struct {
car0102_pin27_fsm_t fsm;
bool active;
} v;
} car0102_pin27_runtime_t;
/* 0102 收到 pin27 时触发正反转序列(仿坦克 shot_back 接口) */
void car0102_pin27_stop_control(int device_id, int pin, int val);
/* 程序退出时销毁 pin27 线程池 */
void car0102_pin27_thread_close(void);
#endif
#include "common.h"
#include "car0107_control.h"
#include "modules_common.h"
#include "gpio_common.h"
#define CTRL_NONE 0
#define CTRL_PHONE 1
#define CTRL_STEERING 2
static pthread_mutex_t s_car0107_hw_mutex = PTHREAD_MUTEX_INITIALIZER;
static int s_control_source = CTRL_NONE;
static int s_target_angle = 90;
static int s_current_angle = 90;
static int s_steering_mode = 0;
static int s_steering_timeout = 0;
static int s_steering_cmd_timeout = 0;
static int s_target_speed = 0;
static int s_current_speed = 0;
static int s_speed_mode = 0;
static int s_speed_timeout = 0;
#define STEER_STEP_TURN 60
#define STEER_STEP_RETURN 90
#define REV_TARGET_SCALE_NUM 6
#define REV_TARGET_SCALE_DEN 10
#define ACCEL_STEP 5
#define DECEL_STEP 6
#define STEER_GVAL_MAX 150
static void car0107_calculate_L_R(int angle) {
if (angle < 0) {
angle = 0;
} else if (angle > 180) {
angle = 180;
}
float pulse_width=( angle / 180.0) *2 + 0.5;
float period = 1000.0 / 50;
int val = (int)((pulse_width / period) * 1000);
pwmWrite(PWM_PIN_CHANGE,val);
}
static void car0107_reset_steering_state(void) {
s_control_source = CTRL_NONE;
s_target_speed = 0;
s_current_speed = 0;
s_speed_mode = 0;
s_target_angle = 90;
s_current_angle = 90;
s_steering_mode = 0;
s_steering_cmd_timeout = 0;
s_speed_timeout = 0;
s_steering_timeout = 0;
}
static int car0107_speed_to_gval(int speed) {
if (speed <= 0) {
return 0;
}
int gval = 50 + (speed * 100) / 160;
if (gval > STEER_GVAL_MAX) {
gval = STEER_GVAL_MAX;
}
return gval;
}
static void car0107_apply_stop(void) {
pwmWrite(PWM_PIN_SPEED, 75);
car0107_calculate_L_R(90);
}
/*车中间值,停止舵机中间函数*/
void car0107_middle_pwm() {
pthread_mutex_lock(&s_car0107_hw_mutex);
car0107_reset_steering_state();
car0107_apply_stop();
pthread_mutex_unlock(&s_car0107_hw_mutex);
}
static void car0107_mode_1_flont(int gval) {
int a=0,b=1;
if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75);
} else if (gval <= 60) {
pwmWrite(PWM_PIN_SPEED, 71-b+a);
}else if (gval <= 70) {
pwmWrite(PWM_PIN_SPEED, 70-b+a);
} else if(gval >70){
int back_speed = 70 - (gval-70)/10-b+a;
pwmWrite(PWM_PIN_SPEED, back_speed);
}
}
static void car0107_mode_2_back(int gval) {
int b=0,a=1;
if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75);
}
else if (gval <= 60) {
pwmWrite(PWM_PIN_SPEED, 79+b-a);
}else if (gval <= 70) {
pwmWrite(PWM_PIN_SPEED, 80+b-a);
}else if(gval >70){
int flont_speed = 80+(gval-70)/10+b-a;
pwmWrite(PWM_PIN_SPEED, flont_speed);
}
}
static void car0107_mode_3_left(int gval) {
int b=15;
if(gval<45){
car0107_calculate_L_R(90);
}else if(gval<70){
car0107_calculate_L_R(50+gval+b);
}else if(gval>=70){
car0107_calculate_L_R(135);
}
}
static void car0107_mode_4_right(int gval) {
int b=10;
if(gval<45){
car0107_calculate_L_R(90);
}else if(gval<70){
car0107_calculate_L_R(130-gval-b);
}else if(gval>=70){
car0107_calculate_L_R(35);
}
}
void car0107_control_change(int *buf) {
int mode=buf[1];
int val=buf[2];
pthread_mutex_lock(&s_car0107_hw_mutex);
s_control_source = CTRL_PHONE;
s_current_speed = 0;
s_speed_timeout = 0;
s_steering_timeout = 0;
switch(mode){
case 1:
car0107_mode_2_back(val);
break;
case 2:
car0107_mode_1_flont(val);
break;
case 3:
car0107_mode_3_left(val);
break;
case 4:
car0107_mode_4_right(val);
break;
default:
break;
}
pthread_mutex_unlock(&s_car0107_hw_mutex);
}
static void car0107_speed_smooth_process(void) {
if (s_control_source != CTRL_STEERING) {
return;
}
s_speed_timeout--;
if (s_speed_timeout <= 0) {
s_current_speed = 0;
car0107_apply_stop();
if (s_steering_timeout <= 0) {
s_control_source = CTRL_NONE;
}
return;
}
int limited_target = s_target_speed;
if (s_speed_mode == 2) {
limited_target = (limited_target * REV_TARGET_SCALE_NUM) / REV_TARGET_SCALE_DEN;
}
if (s_speed_mode == 0) {
if (s_current_speed > 0) {
s_current_speed -= DECEL_STEP;
if (s_current_speed < 0) {
s_current_speed = 0;
}
}
} else if (s_speed_mode == 1 || s_speed_mode == 2) {
if (s_current_speed < limited_target) {
s_current_speed += ACCEL_STEP;
} else if (s_current_speed > limited_target) {
s_current_speed -= DECEL_STEP;
}
}
if (s_current_speed <= 0 || s_speed_mode == 0) {
pwmWrite(PWM_PIN_SPEED, 75);
} else if (s_speed_mode == 1) {
car0107_mode_2_back(car0107_speed_to_gval(s_current_speed));
} else if (s_speed_mode == 2) {
car0107_mode_1_flont(car0107_speed_to_gval(s_current_speed));
}
}
static void car0107_steering_angle_smooth_process(void) {
if (s_control_source != CTRL_STEERING) {
return;
}
s_steering_timeout--;
if (s_steering_timeout <= 0) {
if (s_speed_timeout <= 0) {
s_control_source = CTRL_NONE;
}
s_steering_mode = 0;
s_target_angle = 90;
return;
}
if (s_steering_cmd_timeout > 0) {
s_steering_cmd_timeout--;
}
if (s_steering_cmd_timeout <= 0) {
s_steering_mode = 0;
s_target_angle = 90;
}
int wanted_angle = 90;
int input_angle = s_target_angle;
int smooth_step = STEER_STEP_TURN;
if (input_angle < 0) input_angle = 0;
if (input_angle > 180) input_angle = 180;
if (s_steering_mode == 3) {
wanted_angle = 90 + (input_angle * 37) / 180;
} else if (s_steering_mode == 4) {
wanted_angle = 90 - (input_angle * 37) / 180;
} else {
wanted_angle = 90;
smooth_step = STEER_STEP_RETURN;
}
if (wanted_angle > 130) wanted_angle = 130;
if (wanted_angle < 50) wanted_angle = 50;
if (s_current_angle < wanted_angle) {
s_current_angle += smooth_step;
if (s_current_angle > wanted_angle) s_current_angle = wanted_angle;
} else if (s_current_angle > wanted_angle) {
s_current_angle -= smooth_step;
if (s_current_angle < wanted_angle) s_current_angle = wanted_angle;
}
car0107_calculate_L_R(s_current_angle);
}
void car0107_steering_smooth_all(void) {
pthread_mutex_lock(&s_car0107_hw_mutex);
car0107_speed_smooth_process();
car0107_steering_angle_smooth_process();
pthread_mutex_unlock(&s_car0107_hw_mutex);
}
void car0107_control_steering_change_process(int *buf) {
int mode = buf[1];
int val = buf[2];
pthread_mutex_lock(&s_car0107_hw_mutex);
s_control_source = CTRL_STEERING;
s_steering_timeout = 200;
s_speed_timeout = 200;
if (mode == 1) {
s_speed_mode = 1;
if (val < 50) {
s_target_speed = 0;
s_current_speed = 0;
s_speed_mode = 0;
car0107_apply_stop();
} else if (val <= 200) {
s_target_speed = val - 40;
} else {
s_target_speed = 160;
}
} else if (mode == 2) {
s_speed_mode = 2;
if (val < 50) {
s_target_speed = 0;
s_current_speed = 0;
s_speed_mode = 0;
car0107_apply_stop();
} else if (val <= 200) {
s_target_speed = (val - 40) * 3 / 4;
} else {
s_target_speed = 80;
}
} else if (mode == 3) {
if (val == 0) {
s_steering_mode = 0;
s_target_angle = 90;
s_current_angle = 90;
s_steering_cmd_timeout = 0;
car0107_calculate_L_R(90);
} else {
s_steering_cmd_timeout = 60;
s_target_angle = val;
s_steering_mode = 3;
if (s_target_angle < 0) s_target_angle = 0;
if (s_target_angle > 180) s_target_angle = 180;
}
} else if (mode == 4) {
if (val == 0) {
s_steering_mode = 0;
s_target_angle = 90;
s_current_angle = 90;
s_steering_cmd_timeout = 0;
car0107_calculate_L_R(90);
} else {
s_steering_cmd_timeout = 60;
s_target_angle = val;
s_steering_mode = 4;
if (s_target_angle < 0) s_target_angle = 0;
if (s_target_angle > 180) s_target_angle = 180;
}
}
pthread_mutex_unlock(&s_car0107_hw_mutex);
}
#ifndef CAR0107_CONTROL_H__
#define CAR0107_CONTROL_H__
void car0107_control_change(int *buf);
void car0107_middle_pwm(void);
void car0107_control_steering_change_process(int *buf);
void car0107_steering_smooth_all(void);
#endif
...@@ -28,6 +28,10 @@ static const device_didrive s_didrive_control_config[]={ ...@@ -28,6 +28,10 @@ static const device_didrive s_didrive_control_config[]={
.device_didrive_control = car0106_control_change .device_didrive_control = car0106_control_change
}, },
{ {
.device_id = DEVICE_CAR0107,
.device_didrive_control = car0107_control_change
},
{
.device_id = DEVICE_TANK0202, .device_id = DEVICE_TANK0202,
.device_didrive_control = tank0202_change .device_didrive_control = tank0202_change
}, },
...@@ -92,7 +96,7 @@ static const device_abnormal_close_t s_devcontrol_config[]= { ...@@ -92,7 +96,7 @@ static const device_abnormal_close_t s_devcontrol_config[]= {
{ {
.device_id = DEVICE_CAR0102, .device_id = DEVICE_CAR0102,
.device_abnormal_stop = car0102_speed_stop, .device_abnormal_stop = car0102_speed_stop,
.device_close = NULL, // TANK0206没有单独的关闭函数 .device_close = car0102_pin27_thread_close,
.gpio_pin_pulled=pin_all_default, .gpio_pin_pulled=pin_all_default,
.gpio_pwm_pulled=pwm_all_default .gpio_pwm_pulled=pwm_all_default
}, },
...@@ -130,6 +134,14 @@ static const device_abnormal_close_t s_devcontrol_config[]= { ...@@ -130,6 +134,14 @@ static const device_abnormal_close_t s_devcontrol_config[]= {
}, },
{ {
.device_id = DEVICE_CAR0107,
.device_abnormal_stop = car0107_middle_pwm,
.device_close = NULL,
.gpio_pin_pulled=pin_all_default,
.gpio_pwm_pulled=pwm_all_default
},
{
.device_id = DEVICE_TANK0202, .device_id = DEVICE_TANK0202,
.device_abnormal_stop = tank0202_middle, .device_abnormal_stop = tank0202_middle,
.device_close = device_poilthread_close, .device_close = device_poilthread_close,
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "car0104_control.h" #include "car0104_control.h"
#include "car0105_control.h" #include "car0105_control.h"
#include "car0106_control.h" #include "car0106_control.h"
#include "car0107_control.h"
#include "ptz_common.h" #include "ptz_common.h"
#include "tank0202_control.h" #include "tank0202_control.h"
#include "tank0203_control.h" #include "tank0203_control.h"
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
#include "pg0403_serial.h" #include "pg0403_serial.h"
#include "arm0502_control.h" #include "arm0502_control.h"
#include "tank_common.h" #include "tank_common.h"
#include "car0102_pin27_common.h"
#include "common.h" #include "common.h"
#define DEVICE_CAR0101 101 //莽牛大车 #define DEVICE_CAR0101 101 //莽牛大车
...@@ -28,6 +30,7 @@ ...@@ -28,6 +30,7 @@
#define DEVICE_CAR0104 104 //挖机 #define DEVICE_CAR0104 104 //挖机
#define DEVICE_CAR0105 105 //做人超大车 #define DEVICE_CAR0105 105 //做人超大车
#define DEVICE_CAR0106 106 //F1赛车(双电机大板) #define DEVICE_CAR0106 106 //F1赛车(双电机大板)
#define DEVICE_CAR0107 107 //大众POLO R(前后与0101相反)
#define DEVICE_TANK0201 201 //废弃坦克 #define DEVICE_TANK0201 201 //废弃坦克
#define DEVICE_TANK0202 202 // #define DEVICE_TANK0202 202 //
#define DEVICE_TANK0203 203 //M1A2美国坦克 #define DEVICE_TANK0203 203 //M1A2美国坦克
......
#include "steering_control.h" #include "steering_control.h"
#include "devcontrol_common.h" #include "devcontrol_common.h"
#include "car0107_control.h"
#include "gpio_common.h" #include "gpio_common.h"
static SteeringControl s_steering_devices[] = { static SteeringControl s_steering_devices[] = {
{DEVICE_CAR0102, "car0102", car0102_control_steering_change_process, car0102_steering_smooth_all}, {DEVICE_CAR0102, "car0102", car0102_control_steering_change_process, car0102_steering_smooth_all},
{DEVICE_CAR0107, "car0107", car0107_control_steering_change_process, car0107_steering_smooth_all},
{DEVICE_SHIP0302, "ship0302", ship0302_control_steering_change_process, ship0302_steering_smooth_all}, {DEVICE_SHIP0302, "ship0302", ship0302_control_steering_change_process, ship0302_steering_smooth_all},
{0, "unknown", NULL, NULL} {0, "unknown", NULL, NULL}
}; };
......
...@@ -24,7 +24,7 @@ static const deviceconfig_t s_device_configs[] = { ...@@ -24,7 +24,7 @@ static const deviceconfig_t s_device_configs[] = {
.device_id = DEVICE_CAR0102, .device_id = DEVICE_CAR0102,
.device_name = "car0102", .device_name = "car0102",
.gpio_pins = {5, 6, 7, 10, 16, 20, 22, 23, 24, 25, 26, 27, -1}, .gpio_pins = {5, 6, 7, 10, 16, 20, 22, 23, 24, 25, 26, 27, -1},
.gpio_pwms = {-1}, .gpio_pwms = {5, 7, -1},
.gpio_inputs={-1}, .gpio_inputs={-1},
.device_pwm_init = physics_pwm_init, .device_pwm_init = physics_pwm_init,
.device_control_stop = car0102_speed_stop, .device_control_stop = car0102_speed_stop,
...@@ -74,6 +74,17 @@ static const deviceconfig_t s_device_configs[] = { ...@@ -74,6 +74,17 @@ static const deviceconfig_t s_device_configs[] = {
.device_control_stop = car0106_stop, .device_control_stop = car0106_stop,
.emergency_code = 106 .emergency_code = 106
}, },
// car0107 大众POLO R(与0101相同硬件,前后方向相反)
{
.device_id = DEVICE_CAR0107,
.device_name = "car0107",
.gpio_pins = {5, 6, 7, 10, 16, 20, 22, 23, 24, 25, 26, 27, -1},
.gpio_pwms = {-1},
.gpio_inputs={-1},
.device_pwm_init = physics_pwm_init,
.device_control_stop = car0107_middle_pwm,
.emergency_code = 107
},
// tank0202配置(根据您的需求补充) // tank0202配置(根据您的需求补充)
{ {
.device_id = DEVICE_TANK0202, .device_id = DEVICE_TANK0202,
......
...@@ -280,6 +280,12 @@ static const gpiocontrol_t s_gpio_configs[] = { ...@@ -280,6 +280,12 @@ static const gpiocontrol_t s_gpio_configs[] = {
.device_pwm_value =public_pwm_value .device_pwm_value =public_pwm_value
}, },
{ {
.device_id = DEVICE_CAR0107,
.category_id=LAND_CAR,
.device_pin_value =public_pin_value,
.device_pwm_value =public_pwm_value
},
{
.device_id = DEVICE_TANK0202, .device_id = DEVICE_TANK0202,
.category_id=MARINE_TANK, .category_id=MARINE_TANK,
.device_pin_value =public_pin_value, .device_pin_value =public_pin_value,
...@@ -445,6 +451,10 @@ void car0102_pin_value(int pin,int value) { //引脚控制 ...@@ -445,6 +451,10 @@ void car0102_pin_value(int pin,int value) { //引脚控制
if (!device_gpio_pin_allowed(pin)) { if (!device_gpio_pin_allowed(pin)) {
return; return;
} }
if (pin == 27) {
/* pin27 正反转序列由 car0102_pin27_stop_control 线程处理,不做 digitalWrite */
return;
}
if(value==1) { if(value==1) {
digitalWrite(pin, HIGH); digitalWrite(pin, HIGH);
if(pin==26){ if(pin==26){
......
...@@ -91,7 +91,10 @@ void self_device_control_task(){ ...@@ -91,7 +91,10 @@ void self_device_control_task(){
valt[2]=s_automatic_data[s_self_device_control_data->id_run[i]].val[j]; valt[2]=s_automatic_data[s_self_device_control_data->id_run[i]].val[j];
if(valt[2]>2) device_walk_control(g_device_type,valt); if(valt[2]>2) device_walk_control(g_device_type,valt);
else if(valt[2]<=2) device_gpio_control(g_device_type,valt[1],valt[2]); else if(valt[2]<=2) {
device_gpio_control(g_device_type,valt[1],valt[2]);
car0102_pin27_stop_control(g_device_type, valt[1], valt[2]);
}
} }
......
...@@ -196,6 +196,7 @@ void message_4(cJSON *body) ...@@ -196,6 +196,7 @@ void message_4(cJSON *body)
device_gpio_control(g_device_type, s_valt[1], s_valt[2]); device_gpio_control(g_device_type, s_valt[1], s_valt[2]);
tank_shot_stop_control(g_device_type, s_valt[1], s_valt[2]); tank_shot_stop_control(g_device_type, s_valt[1], s_valt[2]);
car0102_pin27_stop_control(g_device_type, s_valt[1], s_valt[2]);
} }
// 当接收到2时候验证 // 当接收到2时候验证
......
...@@ -9,4 +9,4 @@ file perms = 600 ...@@ -9,4 +9,4 @@ file perms = 600
millisecond = "%d(%Y-%m-%d %H:%M:%S).%ms [%V] %m%n" millisecond = "%d(%Y-%m-%d %H:%M:%S).%ms [%V] %m%n"
[rules] [rules]
my_log.* "/home/orangepi/car/master/log/log_2026-06-24.log"; millisecond my_log.* "/home/orangepi/car/master/log/log_2026-06-25.log"; millisecond
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