Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-controlserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenzhongjian
car-controlserver
Commits
7c005c69
Commit
7c005c69
authored
Apr 01, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了云台的逻辑
parent
707083c7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
161 additions
and
6 deletions
+161
-6
gpio_pwm_2.h
lib/gpio_pwm_2.h
+12
-0
main.h
lib/main.h
+1
-0
mqtt.h
lib/mqtt.h
+1
-0
log.txt
log/log.txt
+0
-0
main
main
+0
-0
gpio_pwm_2.c
src/gpio_pwm_2.c
+134
-0
mqtt.c
src/mqtt.c
+3
-2
main.c
usr/main.c
+10
-4
No files found.
lib/gpio_pwm_2.h
0 → 100644
View file @
7c005c69
#ifndef __GPIO_PWM_2_H__
#define __GPIO_PWM_2_H__
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
void
pwm_PTZ_hz
();
void
PTZ_pwm_init
();
void
PTZ_pwm_change
(
unsigned
char
*
buf
)
;
#endif
\ No newline at end of file
lib/main.h
View file @
7c005c69
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
#include <termios.h>
#include <termios.h>
#include <wiringPi.h>
#include <wiringPi.h>
#include "gpio_pwm.h"
#include "gpio_pwm.h"
#include "gpio_pwm_2.h"
#include "ip.h"
#include "ip.h"
#include "mqtt.h"
#include "mqtt.h"
#include "delay.h"
#include "delay.h"
...
...
lib/mqtt.h
View file @
7c005c69
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
#include "gpio_pwm.h"
#include "gpio_pwm.h"
#include "INA226.h"
#include "INA226.h"
#include "pthrpoll.h"
#include "pthrpoll.h"
#include "gpio_pwm_2.h"
extern
char
*
TOPIC
;
//="app2dev/controlcar0004"
extern
char
*
TOPIC
;
//="app2dev/controlcar0004"
extern
char
*
TOPIC2
;
//="dev2app/controlcar0004"
extern
char
*
TOPIC2
;
//="dev2app/controlcar0004"
...
...
log/log.txt
View file @
7c005c69
This diff is collapsed.
Click to expand it.
main
View file @
7c005c69
No preview for this file type
src/gpio_pwm_2.c
0 → 100644
View file @
7c005c69
#include "gpio_pwm_2.h"
#define PWM_PIN_up 21
#define PWM_PIN_down 2
// 舵机最小脉冲宽度(ms)
#define MIN_PULSE_WIDTH 0.5
// 舵机最大脉冲宽度(ms)
#define MAX_PULSE_WIDTH 2.5
float
Initial_value
=
90
;
static
int
val_change
=
90
;
static
int
val_up_down
=
90
;
static
unsigned
char
change_index
=
0
;
static
unsigned
char
up_down_index
=
0
;
void
pwm_PTZ_hz
()
{
int
pwm_clock
=
24000000
/
(
50
*
1000
);
// 定义 PWM 频率为 50Hz
pinMode
(
PWM_PIN_up
,
PWM_OUTPUT
);
pinMode
(
PWM_PIN_down
,
PWM_OUTPUT
);
pwmSetClock
(
PWM_PIN_up
,
pwm_clock
);
//=19200*1000/(hz*2000)
pwmSetRange
(
PWM_PIN_up
,
1024
);
//占空比范围
pwmSetClock
(
PWM_PIN_down
,
pwm_clock
);
//=19200*1000/(hz*2000)
pwmSetRange
(
PWM_PIN_down
,
1024
);
//占空比范围
}
float
calculate_pulse_width
(
int
angle
)
{
if
(
angle
<
0
)
{
angle
=
0
;
}
else
if
(
angle
>
270
)
{
angle
=
270
;
}
return
((
MAX_PULSE_WIDTH
-
MIN_PULSE_WIDTH
)
/
270
.
0
)
*
angle
+
MIN_PULSE_WIDTH
;
}
int
calculate_duty_cycle
(
float
pulse_width
)
{
// 周期(ms)
float
period
=
1000
.
0
/
50
;
return
(
int
)((
pulse_width
/
period
)
*
1024
);
}
void
PTZ_pwm_init
()
{
float
pulse_width
=
calculate_pulse_width
(
Initial_value
);
int
pulse
=
calculate_duty_cycle
(
pulse_width
);
pwmWrite
(
PWM_PIN_up
,
pulse
);
pwmWrite
(
PWM_PIN_down
,
pulse
);
}
void
PTZ_pwm_left
()
{
float
pulse_width
;
int
pulse
;
change_index
++
;
if
(
change_index
>=
1
)
{
change_index
=
0
;
val_change
-=
3
;
if
(
val_change
<=
0
)
val_change
=
0
;
pulse_width
=
calculate_pulse_width
(
val_change
);
pulse
=
calculate_duty_cycle
(
pulse_width
);
}
printf
(
"%d
\n
"
,
pulse
);
pwmWrite
(
PWM_PIN_down
,
pulse
);
}
void
PTZ_pwm_right
()
{
float
pulse_width
;
int
pulse
;
change_index
++
;
if
(
change_index
>=
1
)
{
change_index
=
0
;
val_change
+=
3
;
if
(
val_change
>=
270
)
val_change
=
270
;
pulse_width
=
calculate_pulse_width
(
val_change
);
pulse
=
calculate_duty_cycle
(
pulse_width
);
}
printf
(
"%d
\n
"
,
pulse
);
pwmWrite
(
PWM_PIN_down
,
pulse
);
}
void
PTZ_pwm_up
()
{
float
pulse_width
;
int
pulse
;
up_down_index
++
;
if
(
up_down_index
>=
1
)
{
up_down_index
=
0
;
val_up_down
+=
3
;
if
(
val_up_down
>=
110
)
val_up_down
=
110
;
pulse_width
=
calculate_pulse_width
(
val_up_down
);
pulse
=
calculate_duty_cycle
(
pulse_width
);
}
printf
(
"%d
\n
"
,
pulse
);
pwmWrite
(
PWM_PIN_up
,
pulse
);
}
void
PTZ_pwm_down
()
{
float
pulse_width
;
int
pulse
;
up_down_index
++
;
if
(
up_down_index
>=
1
)
{
up_down_index
=
0
;
val_up_down
-=
3
;
if
(
val_up_down
<=
70
)
val_up_down
=
70
;
pulse_width
=
calculate_pulse_width
(
val_up_down
);
pulse
=
calculate_duty_cycle
(
pulse_width
);
}
printf
(
"%d
\n
"
,
pulse
);
pwmWrite
(
PWM_PIN_up
,
pulse
);
}
void
PTZ_pwm_change
(
unsigned
char
*
buf
)
{
unsigned
char
mode
=
buf
[
1
];
unsigned
char
val
=
buf
[
2
];
if
(
val
!=
0
)
{
switch
(
mode
)
{
case
1
:
PTZ_pwm_up
();
break
;
case
2
:
PTZ_pwm_down
();
break
;
case
3
:
PTZ_pwm_right
();
break
;
case
4
:
PTZ_pwm_left
();
break
;
default:
break
;
}
}
}
\ No newline at end of file
src/mqtt.c
View file @
7c005c69
...
@@ -100,9 +100,10 @@ void message_3(cJSON *body,cJSON *pwm_ctrl){//message_type为3,控制pwm
...
@@ -100,9 +100,10 @@ void message_3(cJSON *body,cJSON *pwm_ctrl){//message_type为3,控制pwm
if
(
AppExit_pin_pwm
==
3
)
{
if
(
AppExit_pin_pwm
==
3
)
{
if
(
thread_pool_add_task
(
pool
,
ship_speed_change
,
gvalt
)
!=
0
)
{
if
(
thread_pool_add_task
(
pool
,
ship_speed_change
,
gvalt
)
!=
0
)
{
printf
(
"Failed to add task
\n
"
);
printf
(
"Failed to add task
\n
"
);
}
}
}
if
(
AppExit_pin_pwm
==
4
)
{
PTZ_pwm_change
(
gvalt
);
}
}
}
}
...
...
usr/main.c
View file @
7c005c69
...
@@ -10,10 +10,10 @@ int Device_File_Init() {
...
@@ -10,10 +10,10 @@ int Device_File_Init() {
printf
(
"开始初始化了"
);
printf
(
"开始初始化了"
);
if
(
strcmp
(
sub_str
,
"01"
)
==
0
){
//车的编码
if
(
strcmp
(
sub_str
,
"01"
)
==
0
){
//车的编码
pwm_speed
();
//pwm初始化,车为停止
pwm_speed
();
//pwm初始化,车为停止
pin_init
();
pin_init
();
AppExit_pin_pwm
=
1
;
//车的异常停止值
AppExit_pin_pwm
=
1
;
//车的异常停止值
free
(
sub_str
);
free
(
sub_str
);
}
else
if
(
strcmp
(
sub_str
,
"02"
)
==
0
){
//坦克的编码
}
else
if
(
strcmp
(
sub_str
,
"02"
)
==
0
){
//坦克的编码
pin_init
();
pin_init
();
pinMode
(
2
,
OUTPUT
);
//pwm引脚改为普通引脚
pinMode
(
2
,
OUTPUT
);
//pwm引脚改为普通引脚
...
@@ -28,6 +28,12 @@ int Device_File_Init() {
...
@@ -28,6 +28,12 @@ int Device_File_Init() {
pool
=
thread_pool_init
(
1
,
1
);
pool
=
thread_pool_init
(
1
,
1
);
AppExit_pin_pwm
=
3
;
//车的异常停止值
AppExit_pin_pwm
=
3
;
//车的异常停止值
free
(
sub_str
);
free
(
sub_str
);
}
else
if
(
strcmp
(
sub_str
,
"04"
)
==
0
){
//船的编码
pin_init
();
pwm_PTZ_hz
();
PTZ_pwm_init
();
AppExit_pin_pwm
=
4
;
//车的异常停止值
free
(
sub_str
);
}
}
Delay_Ms
(
20
,
0
);
Delay_Ms
(
20
,
0
);
TOPIC
=
malloc
(
24
);
TOPIC
=
malloc
(
24
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment