Commit 66a5d9c8 authored by root's avatar root

update sg 代码

parent 75a6ad2c
log
loghttp
Deviceld.txt
\ No newline at end of file
File added
......@@ -8,6 +8,7 @@
void car_Init_0101() {
pwm_speed(); //pwm初始化,车为停止
pin_init();
midde_pwm() ;
pin_all_default();//拉低全部引脚
AppExit_pin_pwm=101;//车的异常停止值
}
\ No newline at end of file
#ifndef __LOG_H__
#define __LOG_H__
#define LOG_DIR "/home/orangepi/car/master/log"//日志目录
#define LOG_FILE "/home/orangepi/car/master/log/log.log"//日志文件
#define MAX_LOG_AGE_DAYS 15
#endif
\ No newline at end of file
No preview for this file type
#include <sys/stat.h>
#include <syslog.h>
#include <dirent.h>
#include "common.h"
\ No newline at end of file
......@@ -10,6 +10,8 @@ int count_mode = 0;
const int gpioWPi[] = {5, 6, 7, 10, 16, 20, 22, 23, 24, 25, 26, 27};//车能使用高低引脚
const int gpioWPi_ship[] = {5, 6, 7,10, 16, 20, 22, 23, 24,25,26, 27};//船能使用高低引脚
void pin_init() {//初始化引脚,车和坦克共用
int gpioCount = sizeof(gpioWPi) / sizeof(gpioWPi[0]);
// 设置所有GPIO为输出模式
......@@ -69,9 +71,26 @@ void pwm_speed() {
}
void car_calculate_L_R(int angle) {//将角度转化为对应的舵机pwm值
if (angle < 0) {
angle = 0;
} else if (angle > 180) {
angle = 180;
}
float pulse_width=(2 / 180.0) * angle + 0.5;
// 周期(ms)
float period = 1000.0 / 50;
int val = (int)((pulse_width / period) * 1024);
pwmWrite(PWM_PIN_CHANGE,val);
}
void midde_pwm() {//车停止pwm值
pwmWrite(PWM_PIN_SPEED,75);
pwmWrite(PWM_PIN_CHANGE,70);
car_calculate_L_R(90);
//pwmWrite(PWM_PIN_CHANGE,70);
}
void ship_stop_pwm() {//船停止pwm值
......@@ -89,9 +108,9 @@ void mode_1_flont(unsigned char gval) {
if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 75);
} else if (gval <= 55) {
pwmWrite(PWM_PIN_SPEED, 72);
pwmWrite(PWM_PIN_SPEED, 71);
} else if (gval <= 60) {
pwmWrite(PWM_PIN_SPEED, 72);
pwmWrite(PWM_PIN_SPEED, 70);
} else if (gval <= 65) {
pwmWrite(PWM_PIN_SPEED, 70);
} else if (gval <= 70) {
......@@ -165,51 +184,101 @@ void mode_2_back(unsigned char gval) {
void mode_3_left(unsigned char gval) {
if (gval < 45) {
pwmWrite(PWM_PIN_CHANGE, 70);
car_calculate_L_R(90);
} else if (gval <= 51) {
pwmWrite(PWM_PIN_CHANGE, 80);
car_calculate_L_R(110);
} else if (gval <= 57) {
pwmWrite(PWM_PIN_CHANGE, 83);
car_calculate_L_R(120);
} else if (gval <= 63) {
pwmWrite(PWM_PIN_CHANGE, 85);
car_calculate_L_R(130);
} else if (gval <= 69) {
pwmWrite(PWM_PIN_CHANGE, 90);
car_calculate_L_R(130);
} else if (gval <= 75) {
pwmWrite(PWM_PIN_CHANGE, 95);
car_calculate_L_R(140);
} else if (gval <= 81) {
pwmWrite(PWM_PIN_CHANGE, 98);
car_calculate_L_R(145);
} else if (gval <= 87) {
pwmWrite(PWM_PIN_CHANGE, 100);
car_calculate_L_R(150);
} else if (gval <= 93) {
pwmWrite(PWM_PIN_CHANGE, 102);
car_calculate_L_R(150);
} else if (gval <= 100) {
pwmWrite(PWM_PIN_CHANGE, 105);
car_calculate_L_R(160);
}else if (gval <= 107) {
car_calculate_L_R(170);
}else if (gval <= 120) {
car_calculate_L_R(180);
}
// if (gval < 45) {
// pwmWrite(PWM_PIN_CHANGE, 70);
// } else if (gval <= 51) {
// pwmWrite(PWM_PIN_CHANGE, 80);
// } else if (gval <= 57) {
// pwmWrite(PWM_PIN_CHANGE, 83);
// } else if (gval <= 63) {
// pwmWrite(PWM_PIN_CHANGE, 85);
// } else if (gval <= 69) {
// pwmWrite(PWM_PIN_CHANGE, 90);
// } else if (gval <= 75) {
// pwmWrite(PWM_PIN_CHANGE, 95);
// } else if (gval <= 81) {
// pwmWrite(PWM_PIN_CHANGE, 98);
// } else if (gval <= 87) {
// pwmWrite(PWM_PIN_CHANGE, 100);
// } else if (gval <= 93) {
// pwmWrite(PWM_PIN_CHANGE, 102);
// } else if (gval <= 100) {
// pwmWrite(PWM_PIN_CHANGE, 105);
// }
}
void mode_4_right(unsigned char gval) {
if (gval < 45) {
pwmWrite(PWM_PIN_CHANGE, 70);
car_calculate_L_R(90);
} else if (gval <= 51) {
pwmWrite(PWM_PIN_CHANGE, 60);
car_calculate_L_R(70);
} else if (gval <= 57) {
pwmWrite(PWM_PIN_CHANGE, 57);
car_calculate_L_R(66);
} else if (gval <= 63) {
pwmWrite(PWM_PIN_CHANGE, 54);
car_calculate_L_R(62);
} else if (gval <= 69) {
pwmWrite(PWM_PIN_CHANGE, 50);
car_calculate_L_R(55);
} else if (gval <= 75) {
pwmWrite(PWM_PIN_CHANGE, 45);
car_calculate_L_R(45);
} else if (gval <= 81) {
pwmWrite(PWM_PIN_CHANGE, 42);
car_calculate_L_R(40);
} else if (gval <= 87) {
pwmWrite(PWM_PIN_CHANGE, 40);
car_calculate_L_R(30);
} else if (gval <= 93) {
pwmWrite(PWM_PIN_CHANGE, 38);
car_calculate_L_R(30);
} else if (gval <= 100) {
pwmWrite(PWM_PIN_CHANGE, 35);
}
car_calculate_L_R(20);
} else if (gval <= 107) {
car_calculate_L_R(10);
} else if (gval <= 120) {
car_calculate_L_R(0);
}
// if (gval < 45) {
// pwmWrite(PWM_PIN_CHANGE, 70);
// } else if (gval <= 51) {
// pwmWrite(PWM_PIN_CHANGE, 60);
// } else if (gval <= 57) {
// pwmWrite(PWM_PIN_CHANGE, 57);
// } else if (gval <= 63) {
// pwmWrite(PWM_PIN_CHANGE, 54);
// } else if (gval <= 69) {
// pwmWrite(PWM_PIN_CHANGE, 50);
// } else if (gval <= 75) {
// pwmWrite(PWM_PIN_CHANGE, 45);
// } else if (gval <= 81) {
// pwmWrite(PWM_PIN_CHANGE, 42);
// } else if (gval <= 87) {
// pwmWrite(PWM_PIN_CHANGE, 40);
// } else if (gval <= 93) {
// pwmWrite(PWM_PIN_CHANGE, 38);
// } else if (gval <= 100) {
// pwmWrite(PWM_PIN_CHANGE, 35);
// }
}
void speed_change(unsigned char *buf) {//车速度和转向引脚数值处理函数
......@@ -217,7 +286,7 @@ void speed_change(unsigned char *buf) {//车速度和转向引脚数值处理函
unsigned char val=buf[2];
switch(mode){
case 1:
mode_1_flont(val);
mode_1_flont(val);
break;
case 2:
mode_2_back(val);
......
1.1.0
\ No newline at end of file
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