Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
Skyward Boardcore
Commits
4ed0f4c9
Commit
4ed0f4c9
authored
1 year ago
by
Lorenzo Cucchi
Committed by
Emilio Corigliano
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
[VN300] modified read control, timed wait
Added the clearBuffer function, fixed CRC function
parent
c1784995
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/shared/sensors/VN300/VN300.cpp
+88
-75
88 additions, 75 deletions
src/shared/sensors/VN300/VN300.cpp
src/shared/sensors/VN300/VN300.h
+13
-12
13 additions, 12 deletions
src/shared/sensors/VN300/VN300.h
src/tests/sensors/test-vn300.cpp
+2
-2
2 additions, 2 deletions
src/tests/sensors/test-vn300.cpp
with
103 additions
and
89 deletions
src/shared/sensors/VN300/VN300.cpp
+
88
−
75
View file @
4ed0f4c9
...
@@ -27,11 +27,11 @@
...
@@ -27,11 +27,11 @@
namespace
Boardcore
namespace
Boardcore
{
{
VN300
::
VN300
(
USART
&
usart
,
int
b
audRate
,
CRCOptions
crc
,
uint16_t
samplePeriod
,
VN300
::
VN300
(
USART
&
usart
,
int
userB
audRate
,
CRCOptions
crc
,
const
AntennaPosition
antPosA
,
const
AntennaPosition
antPos
B
,
uint16_t
samplePeriod
,
const
AntennaPosition
antPos
A
,
const
Eigen
::
Matrix3f
rotMat
)
const
AntennaPosition
antPosB
,
const
Eigen
::
Matrix3f
rotMat
)
:
usart
(
usart
),
b
audRate
(
b
audRate
),
samplePeriod
(
samplePeriod
),
crc
(
crc
),
:
usart
(
usart
),
userB
audRate
(
userB
audRate
),
samplePeriod
(
samplePeriod
),
antPosA
(
antPosA
),
antPosB
(
antPosB
),
rotMat
(
rotMat
)
crc
(
crc
),
antPosA
(
antPosA
),
antPosB
(
antPosB
),
rotMat
(
rotMat
)
{
{
}
}
...
@@ -84,15 +84,15 @@ bool VN300::init()
...
@@ -84,15 +84,15 @@ bool VN300::init()
return
false
;
return
false
;
}
}
if
(
!
configDefaultSerialPort
(
))
if
(
!
setCrc
(
true
))
{
{
LOG_ERR
(
logger
,
"Unable to
config the default
VN300 ser
ial port
"
);
LOG_ERR
(
logger
,
"Unable to
set the
VN300
u
ser
selected CRC
"
);
return
false
;
return
false
;
}
}
if
(
!
setCrc
(
fals
e
))
if
(
!
configBaudRate
(
defaultBaudRat
e
))
{
{
LOG_ERR
(
logger
,
"Unable to
set the
VN300
u
ser
selected CRC
"
);
LOG_ERR
(
logger
,
"Unable to
config the default
VN300 ser
ial port
"
);
return
false
;
return
false
;
}
}
...
@@ -125,14 +125,14 @@ bool VN300::init()
...
@@ -125,14 +125,14 @@ bool VN300::init()
LOG_ERR
(
logger
,
"Unable to save settings to non-volatile memory"
);
LOG_ERR
(
logger
,
"Unable to save settings to non-volatile memory"
);
return
false
;
return
false
;
}
}
miosix
::
Thread
::
sleep
(
2000
);
if
(
!
config
UserSerialPort
(
))
if
(
!
config
BaudRate
(
userBaudRate
))
{
{
LOG_ERR
(
logger
,
"Unable to config the user VN300 serial port"
);
LOG_ERR
(
logger
,
"Unable to config the user VN300 serial port"
);
return
false
;
return
false
;
}
}
// I need to repeat this in case of a non default
// serial port communication at the beginning
// serial port communication at the beginning
if
(
!
setCrc
(
true
))
if
(
!
setCrc
(
true
))
{
{
...
@@ -183,14 +183,18 @@ bool VN300::closeAndReset()
...
@@ -183,14 +183,18 @@ bool VN300::closeAndReset()
bool
VN300
::
writeSettingsCommand
()
bool
VN300
::
writeSettingsCommand
()
{
{
miosix
::
Thread
::
sleep
(
50
);
miosix
::
Thread
::
sleep
(
50
);
clearBuffer
();
if
(
!
sendStringCommand
(
"VNWNV"
))
if
(
!
sendStringCommand
(
"VNWNV"
))
{
{
LOG_WARN
(
logger
,
"Impossible to save settings"
);
LOG_WARN
(
logger
,
"Impossible to save settings"
);
}
}
miosix
::
Thread
::
sleep
(
5
00
);
miosix
::
Thread
::
sleep
(
10
00
);
// Read the answer
// Read the answer
recvStringCommand
(
recvString
,
recvStringMaxDimension
);
if
(
!
recvStringCommand
(
recvString
,
recvStringMaxDimension
))
{
return
false
;
}
if
(
checkErrorVN
(
recvString
))
if
(
checkErrorVN
(
recvString
))
return
false
;
return
false
;
...
@@ -205,7 +209,11 @@ bool VN300::writeSettingsCommand()
...
@@ -205,7 +209,11 @@ bool VN300::writeSettingsCommand()
miosix
::
Thread
::
sleep
(
500
);
miosix
::
Thread
::
sleep
(
500
);
// Read the answer
// Read the answer
recvStringCommand
(
recvString
,
recvStringMaxDimension
);
if
(
!
recvStringCommand
(
recvString
,
recvStringMaxDimension
))
{
LOG_WARN
(
logger
,
"Impossible to reset the VN300"
);
return
false
;
}
if
(
checkErrorVN
(
recvString
))
if
(
checkErrorVN
(
recvString
))
return
false
;
return
false
;
...
@@ -305,6 +313,7 @@ bool VN300::disableAsyncMessages(bool waitResponse)
...
@@ -305,6 +313,7 @@ bool VN300::disableAsyncMessages(bool waitResponse)
miosix
::
Thread
::
sleep
(
50
);
miosix
::
Thread
::
sleep
(
50
);
// Send the command
// Send the command
clearBuffer
();
if
(
!
sendStringCommand
(
command
))
if
(
!
sendStringCommand
(
command
))
{
{
return
false
;
return
false
;
...
@@ -322,37 +331,10 @@ bool VN300::disableAsyncMessages(bool waitResponse)
...
@@ -322,37 +331,10 @@ bool VN300::disableAsyncMessages(bool waitResponse)
return
true
;
return
true
;
}
}
bool
VN300
::
configDefaultSerialPort
()
{
miosix
::
Thread
::
sleep
(
50
);
// I can send the command
if
(
!
sendStringCommand
(
"VNWRG,5,115200"
))
{
return
false
;
}
if
(
!
recvStringCommand
(
recvString
,
recvStringMaxDimension
))
{
LOG_WARN
(
logger
,
"Unable to sample due to serial communication error"
);
return
false
;
}
if
(
checkErrorVN
(
recvString
))
{
LOG_WARN
(
logger
,
"Unable to change serial port baudrate"
);
return
false
;
}
// I can open the serial with user's baud rate
usart
.
setBaudrate
(
115200
);
return
true
;
}
bool
VN300
::
findBaudrate
()
bool
VN300
::
findBaudrate
()
{
{
char
modelNumber
[]
=
"VN
-300T-CR
"
;
char
modelNumber
[]
=
"VN"
;
const
int
modelNumberOffset
=
1
0
;
const
int
modelNumberOffset
=
1
;
for
(
uint32_t
i
=
0
;
i
<
BaudrateList
.
size
();
i
++
)
for
(
uint32_t
i
=
0
;
i
<
BaudrateList
.
size
();
i
++
)
{
{
...
@@ -363,9 +345,6 @@ bool VN300::findBaudrate()
...
@@ -363,9 +345,6 @@ bool VN300::findBaudrate()
// I pause the async messages, we don't know if they are present.
// I pause the async messages, we don't know if they are present.
asyncPause
();
asyncPause
();
// removing junk
usart
.
clearQueue
();
// I check the model number
// I check the model number
// if (!sendStringCommand("VNRRG,01"))
// if (!sendStringCommand("VNRRG,01"))
//{
//{
...
@@ -373,12 +352,13 @@ bool VN300::findBaudrate()
...
@@ -373,12 +352,13 @@ bool VN300::findBaudrate()
// return false;
// return false;
//}
//}
miosix
::
Thread
::
sleep
(
50
);
miosix
::
Thread
::
sleep
(
50
);
usart
.
writeString
(
"$VNRRG,01*XX
\n
"
);
usart
.
writeString
(
"$VNRRG,01*XX
\n
"
);
if
(
recvStringCommand
(
recvString
,
recvStringMaxDimension
))
if
(
recvStringCommand
(
recvString
,
recvStringMaxDimension
))
{
{
if
(
strncmp
(
modelNumber
,
recvString
+
modelNumberOffset
,
if
(
strncmp
(
modelNumber
,
recvString
+
modelNumberOffset
,
strlen
(
modelNumber
))
!
=
0
)
strlen
(
modelNumber
))
=
=
0
)
{
{
return
true
;
return
true
;
}
}
...
@@ -393,15 +373,17 @@ bool VN300::findBaudrate()
...
@@ -393,15 +373,17 @@ bool VN300::findBaudrate()
* Even if the user configured baudrate is the default, I want to reset the
* Even if the user configured baudrate is the default, I want to reset the
* buffer to clean the junk.
* buffer to clean the junk.
*/
*/
bool
VN300
::
config
UserSerialPort
(
)
bool
VN300
::
config
BaudRate
(
int
baudRate
)
{
{
std
::
string
command
;
std
::
string
command
;
// I format the command to change baud rate
// I format the command to change baud rate
command
=
fmt
::
format
(
"{}{}"
,
"VNWRG,5,"
,
baudRate
);
command
=
fmt
::
format
(
"{}{}"
,
"VNWRG,05,"
,
baudRate
);
const
int
modelNumberOffset
=
1
;
miosix
::
Thread
::
sleep
(
50
);
miosix
::
Thread
::
sleep
(
50
);
clearBuffer
();
// I can send the command
// I can send the command
if
(
!
sendStringCommand
(
command
))
if
(
!
sendStringCommand
(
command
))
{
{
...
@@ -413,10 +395,10 @@ bool VN300::configUserSerialPort()
...
@@ -413,10 +395,10 @@ bool VN300::configUserSerialPort()
LOG_WARN
(
logger
,
"Unable to sample due to serial communication error"
);
LOG_WARN
(
logger
,
"Unable to sample due to serial communication error"
);
return
false
;
return
false
;
}
}
if
(
strncmp
(
command
.
c_str
(),
recvString
+
modelNumberOffset
,
if
(
checkErrorVN
(
recvString
)
)
strlen
(
command
.
c_str
()))
!=
0
)
{
{
LOG_WARN
(
logger
,
"
Unable to change serial port baudrate"
);
LOG_WARN
(
logger
,
"
The message is wrong {}"
,
recvString
);
return
false
;
return
false
;
}
}
...
@@ -426,7 +408,7 @@ bool VN300::configUserSerialPort()
...
@@ -426,7 +408,7 @@ bool VN300::configUserSerialPort()
return
true
;
return
true
;
}
}
bool
VN300
::
resetFactorySettings
()
[[
maybe_unused
]]
bool
VN300
::
resetFactorySettings
()
{
{
// Command string
// Command string
std
::
string
command
=
std
::
string
command
=
...
@@ -475,6 +457,7 @@ bool VN300::setCrc(bool waitResponse)
...
@@ -475,6 +457,7 @@ bool VN300::setCrc(bool waitResponse)
crc
=
CRCOptions
::
CRC_ENABLE_8
;
crc
=
CRCOptions
::
CRC_ENABLE_8
;
miosix
::
Thread
::
sleep
(
50
);
miosix
::
Thread
::
sleep
(
50
);
clearBuffer
();
// Send the command
// Send the command
if
(
!
sendStringCommand
(
command
))
if
(
!
sendStringCommand
(
command
))
{
{
...
@@ -484,19 +467,32 @@ bool VN300::setCrc(bool waitResponse)
...
@@ -484,19 +467,32 @@ bool VN300::setCrc(bool waitResponse)
// Read the answer
// Read the answer
if
(
waitResponse
)
if
(
waitResponse
)
{
{
recvStringCommand
(
recvString
,
recvStringMaxDimension
);
if
(
recvStringCommand
(
recvString
,
recvStringMaxDimension
))
{
uint8_t
error
=
checkErrorVN
(
recvString
);
uint8_t
error
=
checkErrorVN
(
recvString
);
if
(
error
==
3
)
if
(
error
==
3
)
{
{
crc
=
CRCOptions
::
CRC_ENABLE_16
;
crc
=
CRCOptions
::
CRC_ENABLE_16
;
miosix
::
Thread
::
sleep
(
50
);
clearBuffer
();
// Send the command
// Send the command
if
(
!
sendStringCommand
(
command
))
if
(
!
sendStringCommand
(
command
))
{
{
return
false
;
return
false
;
}
}
recvStringCommand
(
recvString
,
recvStringMaxDimension
);
if
(
!
recvStringCommand
(
recvString
,
recvStringMaxDimension
))
checkErrorVN
(
recvString
);
{
return
false
;
}
uint8_t
error2
=
checkErrorVN
(
recvString
);
if
(
error2
!=
0
)
{
return
false
;
}
}
}
else
if
(
error
!=
0
)
else
if
(
error
!=
0
)
{
{
...
@@ -507,6 +503,7 @@ bool VN300::setCrc(bool waitResponse)
...
@@ -507,6 +503,7 @@ bool VN300::setCrc(bool waitResponse)
return
true
;
return
true
;
}
}
}
}
}
else
else
{
{
crc
=
CRCOptions
::
CRC_ENABLE_16
;
crc
=
CRCOptions
::
CRC_ENABLE_16
;
...
@@ -539,6 +536,7 @@ bool VN300::setAntennaA(AntennaPosition antPos)
...
@@ -539,6 +536,7 @@ bool VN300::setAntennaA(AntennaPosition antPos)
antPos
.
posZ
);
antPos
.
posZ
);
miosix
::
Thread
::
sleep
(
50
);
miosix
::
Thread
::
sleep
(
50
);
clearBuffer
();
if
(
!
sendStringCommand
(
command
))
if
(
!
sendStringCommand
(
command
))
{
{
return
false
;
return
false
;
...
@@ -563,6 +561,7 @@ bool VN300::setCompassBaseline(AntennaPosition antPos)
...
@@ -563,6 +561,7 @@ bool VN300::setCompassBaseline(AntennaPosition antPos)
antPos
.
uncZ
);
antPos
.
uncZ
);
miosix
::
Thread
::
sleep
(
50
);
miosix
::
Thread
::
sleep
(
50
);
clearBuffer
();
if
(
!
sendStringCommand
(
command
))
if
(
!
sendStringCommand
(
command
))
{
{
return
false
;
return
false
;
...
@@ -588,7 +587,7 @@ bool VN300::setReferenceFrame(Eigen::Matrix3f rotMat)
...
@@ -588,7 +587,7 @@ bool VN300::setReferenceFrame(Eigen::Matrix3f rotMat)
rotMat
(
1
,
2
),
rotMat
(
2
,
0
),
rotMat
(
2
,
1
),
rotMat
(
2
,
2
));
rotMat
(
1
,
2
),
rotMat
(
2
,
0
),
rotMat
(
2
,
1
),
rotMat
(
2
,
2
));
miosix
::
Thread
::
sleep
(
50
);
miosix
::
Thread
::
sleep
(
50
);
// I can send the command
clearBuffer
();
if
(
!
sendStringCommand
(
command
))
if
(
!
sendStringCommand
(
command
))
{
{
return
false
;
return
false
;
...
@@ -844,8 +843,10 @@ bool VN300::recvStringCommand(char *command, int maxLength)
...
@@ -844,8 +843,10 @@ bool VN300::recvStringCommand(char *command, int maxLength)
char
initChar
;
char
initChar
;
int
j
=
1
;
int
j
=
1
;
bool
read
=
false
;
bool
read
=
false
;
command
[
0
]
=
'\0'
;
for
(
int
i
=
0
;
i
<
10000
;
i
++
)
int
i
=
0
;
while
(
read
==
false
&&
i
<
10000
)
{
{
// Read the first char
// Read the first char
if
(
usart
.
read
(
&
initChar
,
1
)
&&
initChar
==
'$'
)
if
(
usart
.
read
(
&
initChar
,
1
)
&&
initChar
==
'$'
)
...
@@ -857,17 +858,21 @@ bool VN300::recvStringCommand(char *command, int maxLength)
...
@@ -857,17 +858,21 @@ bool VN300::recvStringCommand(char *command, int maxLength)
{
{
command
[
j
]
=
initChar
;
command
[
j
]
=
initChar
;
j
++
;
j
++
;
}
read
=
true
;
read
=
true
;
}
break
;
break
;
}
}
i
++
;
}
}
if
(
read
)
if
(
read
)
{
{
command
[
j
]
=
'\0'
;
command
[
j
]
=
'\0'
;
}
}
else
{
return
false
;
}
recvStringLength
=
j
-
1
;
recvStringLength
=
j
-
1
;
...
@@ -1025,4 +1030,12 @@ uint16_t VN300::calculateChecksum16(uint8_t *message, int length)
...
@@ -1025,4 +1030,12 @@ uint16_t VN300::calculateChecksum16(uint8_t *message, int length)
return
result
;
return
result
;
}
}
void
VN300
::
clearBuffer
()
{
char
c
;
while
(
usart
.
read
(
&
c
,
1
))
{
}
}
}
// namespace Boardcore
}
// namespace Boardcore
This diff is collapsed.
Click to expand it.
src/shared/sensors/VN300/VN300.h
+
13
−
12
View file @
4ed0f4c9
...
@@ -74,7 +74,6 @@ class VN300 : public Sensor<VN300Data>
...
@@ -74,7 +74,6 @@ class VN300 : public Sensor<VN300Data>
public:
public:
enum
class
CRCOptions
:
uint8_t
enum
class
CRCOptions
:
uint8_t
{
{
CRC_NO
=
0x00
,
CRC_ENABLE_8
=
0x08
,
CRC_ENABLE_8
=
0x08
,
CRC_ENABLE_16
=
0x10
CRC_ENABLE_16
=
0x10
};
};
...
@@ -92,8 +91,8 @@ public:
...
@@ -92,8 +91,8 @@ public:
* @param samplePeriod Sampling period in ms
* @param samplePeriod Sampling period in ms
* @param antPos antenna A position
* @param antPos antenna A position
*/
*/
VN300
(
USART
&
usart
,
int
b
aud
r
ate
,
CRCOptions
crc
=
CRCOptions
::
CRC_ENABLE_8
,
VN300
(
USART
&
usart
,
int
userB
aud
R
ate
,
uint16_t
samplePeriod
=
15
,
CRCOptions
crc
=
CRCOptions
::
CRC_ENABLE_8
,
uint16_t
samplePeriod
=
15
,
AntennaPosition
antPosA
=
{
0.0
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
},
AntennaPosition
antPosA
=
{
0.0
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
},
AntennaPosition
antPosB
=
{
1.0
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
},
AntennaPosition
antPosB
=
{
1.0
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
},
Eigen
::
Matrix3f
rotMat
=
Eigen
::
Matrix3f
::
Identity
());
Eigen
::
Matrix3f
rotMat
=
Eigen
::
Matrix3f
::
Identity
());
...
@@ -140,19 +139,12 @@ private:
...
@@ -140,19 +139,12 @@ private:
*/
*/
bool
disableAsyncMessages
(
bool
waitResponse
=
true
);
bool
disableAsyncMessages
(
bool
waitResponse
=
true
);
/**
* @brief Configures the default serial communication.
*
* @return True if operation succeeded.
*/
bool
configDefaultSerialPort
();
/**
/**
* @brief Configures the user defined serial communication.
* @brief Configures the user defined serial communication.
*
*
* @return True if operation succeeded.
* @return True if operation succeeded.
*/
*/
bool
config
UserSerialPort
(
);
bool
config
BaudRate
(
int
baud
);
/**
/**
* @brief reset to factory settings.
* @brief reset to factory settings.
...
@@ -288,12 +280,21 @@ private:
...
@@ -288,12 +280,21 @@ private:
*/
*/
uint16_t
calculateChecksum16
(
uint8_t
*
message
,
int
length
);
uint16_t
calculateChecksum16
(
uint8_t
*
message
,
int
length
);
/**
* @brief Clear the buffer of the serial interface.
*
* This is a placeholder function for the serial interface.
* When the usart driver is corrected this must be changed.
*/
void
clearBuffer
();
/**
/**
* @brief Serial interface that is needed to communicate
* @brief Serial interface that is needed to communicate
* with the sensor via ASCII codes.
* with the sensor via ASCII codes.
*/
*/
USART
&
usart
;
USART
&
usart
;
int
baudRate
;
int
userBaudRate
;
const
int
defaultBaudRate
=
115200
;
uint16_t
samplePeriod
;
uint16_t
samplePeriod
;
CRCOptions
crc
;
CRCOptions
crc
;
...
...
This diff is collapsed.
Click to expand it.
src/tests/sensors/test-vn300.cpp
+
2
−
2
View file @
4ed0f4c9
...
@@ -45,7 +45,7 @@ int main()
...
@@ -45,7 +45,7 @@ int main()
u6tx1
.
mode
(
Mode
::
ALTERNATE
);
u6tx1
.
mode
(
Mode
::
ALTERNATE
);
USART
usart
(
USART6
,
115200
);
USART
usart
(
USART6
,
115200
);
VN300
sensor
(
usart
,
1152
00
,
VN300
::
CRCOptions
::
CRC_ENABLE_8
);
VN300
sensor
(
usart
,
2304
00
,
VN300
::
CRCOptions
::
CRC_ENABLE_8
);
// Let the sensor start up
// Let the sensor start up
Thread
::
sleep
(
1000
);
Thread
::
sleep
(
1000
);
...
@@ -106,7 +106,7 @@ int main()
...
@@ -106,7 +106,7 @@ int main()
CpuMeterData
cpuData
=
Boardcore
::
CpuMeter
::
getCpuStats
();
CpuMeterData
cpuData
=
Boardcore
::
CpuMeter
::
getCpuStats
();
printf
(
"CPU: %f
\n
"
,
cpuData
.
mean
);
printf
(
"CPU: %f
\n
"
,
cpuData
.
mean
);
//
sensor.closeAndReset();
sensor
.
closeAndReset
();
printf
(
"Sensor communication closed!
\n
"
);
printf
(
"Sensor communication closed!
\n
"
);
return
0
;
return
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment