Commit 8d4e52b7 authored by 957dd's avatar 957dd

修改了船的射击根水坦克一样

parent 634d5df3
#define PROJECT_VERSION_MAJOR 1 #define PROJECT_VERSION_MAJOR 1
#define PROJECT_VERSION_MINOR 2 #define PROJECT_VERSION_MINOR 2
#define PROJECT_VERSION_PATCH 11 #define PROJECT_VERSION_PATCH 12
#define GIT_HASH "" #define GIT_HASH ""
#define BUILD_TIMESTAMP "" #define BUILD_TIMESTAMP ""
#define BUILD_USER "" #define BUILD_USER ""
No preview for this file type
...@@ -68,43 +68,93 @@ void ship0301_mode_right_flont(unsigned char gval) { ...@@ -68,43 +68,93 @@ void ship0301_mode_right_flont(unsigned char gval) {
} }
} }
int ship0301_change_grading(int mode){
int mode_val=0;
switch(mode){
case 2:
mode_val=10;
break;
case 3:
mode_val=20;
break;
case 4:
mode_val=30;
break;
case 5:
mode_val=50;
break;
default:
break;
}
return mode_val;
}
void ship0301_change(unsigned char *buf) { void ship0301_change(unsigned char *buf) {
unsigned char type = buf[0];
unsigned char mode = buf[1]; unsigned char mode = buf[1];
unsigned char val = buf[2]; unsigned char val = buf[2];
static int modecount_ship0301;
static bool ship0301_steer_t=0; static int ship0301_steering_t=0;
if(mode == 1 ) { static int ship0301_front_t =0;
//mode_lift_flont(val);
ship0301_mode_lift_flont(val); static int ship0301_front_val=0;
ship0301_mode_right_flont(val); static int ship0301_steering_val=0;
modecount_ship0301=0;
ship0301_steer_t=1;
}else if(mode == 2 ) {
//mode_lift_back(val);
ship0301_mode_lift_flont(val);
ship0301_mode_right_back(val);
modecount_ship0301=1;
ship0301_steer_t=1;
}
if((mode == 1||mode ==2)&&val == 0) { int ship0301_count=40;
modecount_ship0301=0;
ship0301_steer_t=0; if(type != 1) ship0301_count=ship0301_change_grading(type);
if((mode == 1 ||mode == 2)&&val == 0) ship0301_front_t =0;
if((mode == 3 ||mode == 4)&&val == 0) ship0301_steering_t=0;
if(mode == 1&&val != 0) {
ship0301_front_val=val;
ship0301_front_t =1;
}else if(mode == 2&&val != 0) {
ship0301_front_t =2;
ship0301_front_val=val;
} }
if(mode == 3) { if(mode == 3&&val != 0) {
if(modecount_ship0301 == 0) { ship0301_steering_t =1;
if(ship0301_steer_t==0)ship0301_mode_right_flont(val+35); ship0301_steering_val = val;
ship0301_mode_lift_flont(0); }else if(mode == 4&&val != 0) {
} ship0301_steering_t =2;
if(modecount_ship0301 == 1) ship0301_mode_right_back(0); ship0301_steering_val = val;
}else if(mode == 4) { }
if(modecount_ship0301 == 0) {
if(ship0301_steer_t==0)ship0301_mode_lift_flont(val+35); if(ship0301_front_t ==0&&ship0301_steering_t==0){
ship0301_mode_right_flont(0); ship0301_mode_lift_flont(0);
} ship0301_mode_right_flont(0);
if(modecount_ship0301 == 1) ship0301_mode_lift_back(0); }else if(ship0301_front_t ==1&&ship0301_steering_t==0){
} ship0301_mode_lift_flont(ship0301_front_val);
ship0301_mode_right_flont(ship0301_front_val);
}else if(ship0301_front_t ==2&&ship0301_steering_t==0){
ship0301_mode_lift_back(ship0301_front_val);
ship0301_mode_right_back(ship0301_front_val);
}else if(ship0301_front_t ==0&&ship0301_steering_t==1){
ship0301_mode_right_flont(ship0301_steering_val+ship0301_count);
ship0301_mode_lift_flont(0);
}else if(ship0301_front_t ==0&&ship0301_steering_t==2){
ship0301_mode_right_flont(0);
ship0301_mode_lift_flont(ship0301_steering_val+ship0301_count+10);
}else if(ship0301_front_t ==1&&ship0301_steering_t==1){
ship0301_mode_right_flont(ship0301_steering_val+ship0301_count+10);
ship0301_mode_lift_flont(ship0301_count+15);
}else if(ship0301_front_t ==1&&ship0301_steering_t==2){
ship0301_mode_right_flont(ship0301_count+15);
ship0301_mode_lift_flont(ship0301_steering_val+ship0301_count+10);
}else if(ship0301_front_t ==2&&ship0301_steering_t==1){
ship0301_mode_lift_back(ship0301_count+15);
ship0301_mode_right_back(ship0301_steering_val+ship0301_count+10);
}else if(ship0301_front_t ==2&&ship0301_steering_t==2){
ship0301_mode_lift_back(ship0301_steering_val+ship0301_count+10);
ship0301_mode_right_back(ship0301_count+15);
}
} }
\ No newline at end of file
...@@ -452,17 +452,18 @@ void ship0301_pwm_value(int pin,int value) { //软件陪我们控制调速 ...@@ -452,17 +452,18 @@ void ship0301_pwm_value(int pin,int value) { //软件陪我们控制调速
if(value==1) { if(value==1) {
if(pin == 27){ if(pin == 27){
softPwmWrite(pin, 50); softPwmWrite(26, 35);
} else { } else {
softPwmWrite(pin, 35); softPwmWrite(pin, 35);
my_zlog_debug("pwm:%d",pin); my_zlog_debug("pwm:%d",pin);
} }
}else if(value==0) { }else if(value==0) {
if(pin == 27) softPwmWrite(26, 0);
softPwmWrite(pin, 0); softPwmWrite(pin, 0);
my_zlog_debug("pwm:%d,0",pin); my_zlog_debug("pwm:%d,0",pin);
} }
my_zlog_debug("ship0301 pwm"); my_zlog_debug("tank0301 pwm");
} }
......
...@@ -86,6 +86,7 @@ void heartbeat_send() { ...@@ -86,6 +86,7 @@ void heartbeat_send() {
//角度发送 //角度发送
void angle_mqtt_send() { void angle_mqtt_send() {
static int angle_i=0; static int angle_i=0;
static double record_angle_t=0;
cJSON *root = cJSON_CreateObject(); cJSON *root = cJSON_CreateObject();
char TOPIC_send_angle[26]; char TOPIC_send_angle[26];
double rounded_angle = tank_angle(); double rounded_angle = tank_angle();
...@@ -98,7 +99,11 @@ void angle_mqtt_send() { ...@@ -98,7 +99,11 @@ void angle_mqtt_send() {
my_zlog_debug("%s",payload); my_zlog_debug("%s",payload);
angle_i=0; angle_i=0;
} }
mosquitto_publish(mosq, NULL, TOPIC_send_angle, strlen(payload), payload, 0, false); if(fabs(rounded_angle - record_angle_t) >3){
mosquitto_publish(mosq, NULL, TOPIC_send_angle, strlen(payload), payload, 0, false);
}
record_angle_t=rounded_angle;
cJSON_Delete(root); // 释放 cJSON 对象 cJSON_Delete(root); // 释放 cJSON 对象
} }
...@@ -110,7 +115,16 @@ void mqtt_beat_wirte(){ ...@@ -110,7 +115,16 @@ void mqtt_beat_wirte(){
heartbeat_send(); heartbeat_send();
g_heartbeat_count=0; g_heartbeat_count=0;
} }
if( g_device_type == DEVICE_TANK0202||g_device_type == DEVICE_TANK0203) angle_mqtt_send();
switch (g_device_type) {
case DEVICE_TANK0202:
case DEVICE_TANK0203:
case DEVICE_TANK0204:
angle_mqtt_send();
break;
default:
break;
}
} }
......
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