include
dbw_polaris_can
pedal_lut.h
Go to the documentation of this file.
1
/*********************************************************************
2
* Software License Agreement (BSD License)
3
*
4
* Copyright (c) 2020, Dataspeed Inc.
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
*
11
* * Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
* * Redistributions in binary form must reproduce the above
14
* copyright notice, this list of conditions and the following
15
* disclaimer in the documentation and/or other materials provided
16
* with the distribution.
17
* * Neither the name of Dataspeed Inc. nor the names of its
18
* contributors may be used to endorse or promote products derived
19
* from this software without specific prior written permission.
20
*
21
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
* POSSIBILITY OF SUCH DAMAGE.
33
*********************************************************************/
34
35
#ifndef _DBW_POLARIS_CAN_PEDAL_LUT_H
36
#define _DBW_POLARIS_CAN_PEDAL_LUT_H
37
#include <math.h>
38
39
namespace
dbw_polaris_can
40
{
41
42
static
const
struct
{
float
pedal
;
float
percent
;}
THROTTLE_TABLE
[] = {
43
// Duty, %
44
{0.200, 0.000},
45
{0.300, 0.001},
46
{0.800, 1.000},
47
};
48
static
inline
float
throttlePedalFromPercent
(
float
percent
) {
49
const
unsigned
int
size =
sizeof
(
THROTTLE_TABLE
) /
sizeof
(
THROTTLE_TABLE
[0]);
50
if
(
percent
<=
THROTTLE_TABLE
[0].
percent
) {
51
return
THROTTLE_TABLE
[0].pedal;
52
}
else
if
(
percent
>=
THROTTLE_TABLE
[size - 1].
percent
) {
53
return
THROTTLE_TABLE
[size - 1].pedal;
54
}
else
{
55
for
(
unsigned
int
i = 1; i < size; i++) {
56
if
(
percent
<
THROTTLE_TABLE
[i].
percent
) {
57
float
start
=
THROTTLE_TABLE
[i - 1].pedal;
58
float
dinput =
percent
-
THROTTLE_TABLE
[i - 1].percent;
59
float
dpedal =
THROTTLE_TABLE
[i].pedal -
THROTTLE_TABLE
[i - 1].pedal;
60
float
dpercent =
THROTTLE_TABLE
[i].percent -
THROTTLE_TABLE
[i - 1].percent;
61
if
(fabsf(dpercent) > (float)1e-6) {
62
return
start
+ (dinput * dpedal / dpercent);
63
}
else
{
64
return
start
+ (dpedal / 2);
65
}
66
}
67
}
68
}
69
return
0.0;
70
}
71
72
static
inline
float
throttlePercentFromPedal
(
float
pedal
) {
73
const
unsigned
int
size =
sizeof
(
THROTTLE_TABLE
) /
sizeof
(
THROTTLE_TABLE
[0]);
74
if
(
pedal
<=
THROTTLE_TABLE
[0].
pedal
) {
75
return
THROTTLE_TABLE
[0].percent;
76
}
else
if
(
pedal
>=
THROTTLE_TABLE
[size - 1].
pedal
) {
77
return
THROTTLE_TABLE
[size - 1].percent;
78
}
else
{
79
for
(
unsigned
int
i = 1; i < size; i++) {
80
if
(
pedal
<
THROTTLE_TABLE
[i].
pedal
) {
81
float
start
=
THROTTLE_TABLE
[i - 1].percent;
82
float
dinput =
pedal
-
THROTTLE_TABLE
[i - 1].pedal;
83
float
dpercent =
THROTTLE_TABLE
[i].percent -
THROTTLE_TABLE
[i - 1].percent;
84
float
dpedal =
THROTTLE_TABLE
[i].pedal -
THROTTLE_TABLE
[i - 1].pedal;
85
if
(fabsf(dpedal) > (float) 1e-6) {
86
return
start
+ (dinput * dpercent / dpedal);
87
}
else
{
88
return
start
+ (dpercent / 2);
89
}
90
}
91
}
92
}
93
return
0.0;
94
}
95
96
}
// namespace dbw_polaris_can
97
98
#endif // _DBW_POLARIS_CAN_PEDAL_LUT_H
99
dbw_polaris_can::percent
float percent
Definition:
pedal_lut.h:106
dbw_polaris_can::throttlePercentFromPedal
static float throttlePercentFromPedal(float pedal)
Definition:
pedal_lut.h:104
dbw_polaris_can::throttlePedalFromPercent
static float throttlePedalFromPercent(float percent)
Definition:
pedal_lut.h:80
dbw_polaris_can::pedal
float pedal
Definition:
pedal_lut.h:106
dbw_polaris_can::THROTTLE_TABLE
static const struct dbw_polaris_can::@16 THROTTLE_TABLE[]
start
ROSCPP_DECL void start()
dbw_polaris_can
Definition:
dispatch.h:39
dbw_polaris_can
Author(s): Kevin Hallenbeck
autogenerated on Thu Jan 4 2024 03:36:18