MotorFineTuning.c
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <stdio.h>
#include "JZsdkLib.h"
#include "./MotorFineTuning.h"
#define MOTOR_FILE_PATH "/root/motor"
/************************
*
* 云台微调初始化
*
*
* *************************/
T_JZsdkReturnCode MotorFineTuning_Init(int *pitch, int *yaw, int *roll)
{
Read_MotorFineTuning_Pitch(pitch);
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/************************************************************************************************************
*
* pitch轴
*
*
*/
/*******
*
* pitch轴微调值的读取
*
*
* ************/
T_JZsdkReturnCode Read_MotorFineTuning_Pitch(int *value)
{
FILE *motor_file = NULL;
int MotorFineTuningPitch = 0;
motor_file = fopen(MOTOR_FILE_PATH, "rb+");
if (motor_file == NULL)
{
motor_file = fopen(MOTOR_FILE_PATH, "wb+");
if (motor_file == NULL)
{
*value = 0;
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
}
else
{
int ret = fseek(motor_file, 0, SEEK_SET);
if (ret != 0)
{
printf("Seek log count file error, ret: %d.\r\n", ret);
}
ret = fread((int *) &MotorFineTuningPitch, 1, sizeof(int), motor_file);
if (ret != sizeof(int))
{
printf("Read motor weitiao error.\r\n");
*value = 0;
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
else
{
printf("Read motor weitiao=%d\n",MotorFineTuningPitch);
*value = 0;
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
}
if (motor_file != NULL)
{
fclose(motor_file);
}
*value = MotorFineTuningPitch;
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/*******
*
* pitch轴微调值的写入
*
*
* ************/
T_JZsdkReturnCode MotorFineTuning_WritePitch(int Pitch)
{
//写入文件
FILE *motor_file;
motor_file = fopen(MOTOR_FILE_PATH, "wb+");
if (motor_file == NULL)
{
return JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
int ret = fwrite((int *) &Pitch, 1, sizeof(unsigned int),motor_file);
if (ret != sizeof(unsigned int))
{
JZSDK_LOG_ERROR("MotorFineTuning_WritePitch error.");
}
else
{
JZSDK_LOG_DEBUG("MotorFineTuning_WritePitch=%d\n",Pitch);
}
fclose(motor_file);
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}