This repository was archived by the owner on Jan 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
[feature] DW1000 Driver, 802.15.4 Frame & Ranging #361
Open
Maju-Ketchup
wants to merge
6
commits into
roboterclubaachen:develop
Choose a base branch
from
Maju-Ketchup:feature/DecaWaveDWM1000Driver
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3f28c3f
[examples] STM32F4 Discovery: move NRF24 examples to subdir
077c67d
[examples] STM32F4 Discovery: add dw1000 examples
bf1308b
[examples] generic: add dw1000 examples
f94ae76
[positioning] add multilateration and ranging
9262656
[communication] add Frame802154
935ca59
[driver] add Decawave DW1000 driver
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
...s/stm32f4_discovery/radio/dw1000/double-sided_two-way_ranging_dw1000/initiator/SConstruct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # path to the xpcc root directory | ||
| xpccpath = '../../../../../..' | ||
| # execute the common SConstruct file | ||
| exec(compile(open(xpccpath + '/scons/SConstruct', "rb").read(), xpccpath + '/scons/SConstruct', 'exec')) |
192 changes: 192 additions & 0 deletions
192
...les/stm32f4_discovery/radio/dw1000/double-sided_two-way_ranging_dw1000/initiator/main.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| /* This is an Example application for one STM32F4 in combination with a Decawave DM1000 Chip | ||
| * Connections are the following: | ||
| * | ||
| * USART: STM32 Pin | ||
| * TXD -> PA2 | ||
| * RXD -> PA3 (not used in this example) | ||
| * | ||
| * DM1000: | ||
| * SPI: STM32 Pin | ||
| * Miso -> PB15 | ||
| * Mosi -> PC2 | ||
| * Clock -> PB10 | ||
| * | ||
| * RES -> PA8 | ||
| * Chipselect -> PE8 | ||
| * IRQ -> PD10 (not used in this example) | ||
| * | ||
| * What this program does is: | ||
| * 1) Sends out a DSTW-Ranging Frame on Broadcast | ||
| * 2) Waits for an Answer and Computes the Range between the both | ||
| * | ||
| * For 1 Ranging there will be 4 messages but this technique is more precise than SSTW | ||
| * | ||
| * | ||
| * Init -> Resp |Payload{init DSTWR} | ||
| * Resp -> Init |Payload{receive and transmittime of Resp} | ||
| * Init -> Resp |Payload{receive and transmittime of Init} | ||
| * Resp -> Init |Payload{Time of flight of second ranging round} | ||
| */ | ||
|
|
||
|
|
||
| #include <xpcc/architecture/platform.hpp> // include for platform | ||
| #include <xpcc/debug/logger.hpp> // include for DW1000 Error/Debug Messaging | ||
| #include <xpcc/driver/radio/dw1000/dw1000.hpp> // DW1000 Driver | ||
| #include <xpcc/communication/Frame802154/Frame802154.hpp> // MAC Frame for IEEE 802.15.4 | ||
| #include <xpcc/positioning/ranging.hpp> // ranging operations for DW1000 | ||
| #include <xpcc/processing/timer.hpp> // Timer and Timeouts | ||
|
|
||
|
|
||
| // ------------------------------XPCC---------------------------------------------- | ||
| xpcc::IODeviceWrapper< Usart2, xpcc::IOBuffer::BlockIfFull > loggerDevice; | ||
|
|
||
| // // Set all four logger streams to use the UART | ||
| xpcc::log::Logger xpcc::log::debug(loggerDevice); | ||
| xpcc::log::Logger xpcc::log::info(loggerDevice); | ||
| xpcc::log::Logger xpcc::log::warning(loggerDevice); | ||
| xpcc::log::Logger xpcc::log::error(loggerDevice); | ||
|
|
||
| //Namespaces and renaming | ||
| using namespace Board; | ||
| using SPI = SpiMaster2; | ||
| using RES = GpioOutputA8; | ||
| using CS = GpioOutputE8; | ||
| using IRQ = GpioInputD10; | ||
|
|
||
| using dwm = xpcc::Dw1000 < SPI, CS, RES, IRQ >; | ||
| using ranging = xpcc::Ranging < dwm >; | ||
|
|
||
|
|
||
| //------------------------------DWM Config------------------------------------------------ | ||
|
|
||
| static xpcc::dw1000::config_t config = | ||
| { | ||
| 2, /* Channel number. */ | ||
| xpcc::dw1000::PRF_64M, /* Pulse repetition frequency. */ | ||
| xpcc::dw1000::PLEN_128, /* Preamble length. Used in TX only. */ | ||
| xpcc::dw1000::PAC8, /* Preamble acquisition chunk size. Used in RX only. */ | ||
| 9, /* TX preamble code. Used in TX only. */ | ||
| 9, /* RX preamble code. Used in RX only. */ | ||
| 0, /* 0 to use standard SFD, 1 to use non-standard SFD. */ | ||
| xpcc::dw1000::BR_6M8, /* Data rate. */ | ||
| xpcc::dw1000::PHRMODE_STD, /* PHY header mode. */ | ||
| (129 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ | ||
| }; | ||
|
|
||
| /* Default antenna delay values for 64 MHz PRF*/ | ||
| static constexpr int TX_ANT_DLY = 16436; | ||
| static constexpr int RX_ANT_DLY = 16436; | ||
| static constexpr uint16_t hostaddress= 0xBBBB; | ||
|
|
||
|
|
||
| xpcc::Frame802154 receiveframe; | ||
| xpcc::ShortTimeout timeout; | ||
| bool isrx = false; | ||
| uint32_t responserx, responsetx; | ||
| uint64_t owntx,ownrx; | ||
| double distance; | ||
| uint8_t buffer[1024]; | ||
|
|
||
|
|
||
| //-------------------------------MAIN----------------------------------------------------- | ||
| int | ||
| main() | ||
| { | ||
| //setup USART | ||
| GpioOutputA2::connect(Usart2::Tx); | ||
| GpioInputA3::connect(Usart2::Rx, Gpio::InputType::PullUp); | ||
| Usart2::initialize<Board::systemClock, 115200>(12); | ||
| //initialize the board | ||
| Board::initialize(); | ||
| //activate the CS on the DW1000 | ||
| CS::setOutput(xpcc::Gpio::High); | ||
| //setup SPI | ||
| GpioOutputB15::connect(SPI::Mosi); | ||
| GpioInputC2::connect(SPI::Miso); | ||
| GpioOutputB10::connect(SPI::Sck); | ||
| SPI::initialize<Board::systemClock, 1312500ul>(); | ||
| SPI::setDataMode(SPI::DataMode::Mode0); | ||
| //Init with the config | ||
| while (!(dwm::init(config))) | ||
| {LedRed::set();} | ||
| LedRed::reset(); | ||
| /* Apply antenna delay value.*/ | ||
| dwm::setRXAntennaDelay(RX_ANT_DLY); | ||
| dwm::setTXAntennaDelay(TX_ANT_DLY); | ||
|
|
||
| dwm::hostaddress = hostaddress; | ||
|
|
||
| while (true) | ||
| { | ||
| LedBlue::set(); | ||
|
|
||
| //--------------------------------------- Start sending init --------------------------------------------------------------- | ||
| XPCC_LOG_DEBUG << "Send init"<< xpcc::endl; | ||
| ranging::sendDSTWRinit(); | ||
| timeout.restart(5); | ||
| while(not(dwm::isFrameSent()||timeout.isExpired())){} | ||
| LedBlue::reset(); | ||
|
|
||
| //------------------------------------------------------------ Receive Message-------------------------------------------------------------------- | ||
| timeout.restart(5); | ||
| dwm::rxEnable(); | ||
| LedOrange::set(); | ||
| while(not(dwm::checkForRXError() || (isrx = dwm::checkForRX()) || timeout.isExpired())){} | ||
| LedOrange::reset(); | ||
| if (isrx) | ||
| { | ||
| dwm::readrx(dwm::rxlength(),buffer); | ||
| receiveframe.loadFrame(dwm::rxlength(),buffer); | ||
| if (receiveframe.getDestinationAddress16() == hostaddress) | ||
| { | ||
| if (ranging::IsRangingFrame(receiveframe)) | ||
| { | ||
| //--------------------------------------- Start get distance and send return --------------------------------------------------------------- | ||
| distance = ranging::computeSsTwrDistance(receiveframe); | ||
| dwm::rxdisable(); | ||
| ranging::sendAnswer(receiveframe); | ||
| //---------------------------------------Wait for TOF from other device--------------------------------------------------------------------- | ||
| timeout.restart(5); | ||
| while(not(dwm::isFrameSent()||timeout.isExpired())){} | ||
| dwm::rxreset(); | ||
| dwm::rxEnable(); | ||
| isrx = false; | ||
| timeout.restart(150); | ||
| LedOrange::set(); | ||
| while(not(dwm::checkForRXError() || (isrx = dwm::checkForRX()) || timeout.isExpired())){} | ||
| LedOrange::reset(); | ||
| if (isrx) | ||
| { | ||
| LedGreen::toggle(); | ||
| dwm::readrx(dwm::rxlength(),buffer); | ||
| receiveframe.loadFrame(dwm::rxlength(),buffer); | ||
| if (receiveframe.getDestinationAddress16() == hostaddress) | ||
| { | ||
| if (ranging::IsRangingFrame(receiveframe)) | ||
| { | ||
| distance = ranging::computeDsTwrDistance(distance,receiveframe); | ||
| XPCC_LOG_INFO.printf("DISTANCE TO %0x IS %5.2fm \n",receiveframe.getSourceAddress16(),distance); | ||
| timeout.restart(5); | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| dwm::frame_seq_nb = receiveframe.getSequenceNumber() + 1 ; | ||
| XPCC_LOG_DEBUG << "Wrong Answer --- Address was wrong"<< xpcc::endl; | ||
| } | ||
| } | ||
|
|
||
| else if (dwm::checkForRXError()) | ||
| { | ||
| XPCC_LOG_ERROR<< "RX--ERROR!"<< xpcc::endl; | ||
| timeout.restart(10); | ||
| } | ||
| dwm::rxdisable(); | ||
| while(not(timeout.isExpired())){} | ||
|
|
||
| } | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
.../stm32f4_discovery/radio/dw1000/double-sided_two-way_ranging_dw1000/initiator/project.cfg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [build] | ||
| board = stm32f4_discovery | ||
| buildpath = ${xpccpath}/build/stm32f4_discovery/radio/${name} | ||
|
|
||
| [parameters] | ||
| uart.stm32.2.tx_buffer = 1024 |
4 changes: 4 additions & 0 deletions
4
...s/stm32f4_discovery/radio/dw1000/double-sided_two-way_ranging_dw1000/responder/SConstruct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # path to the xpcc root directory | ||
| xpccpath = '../../../../../..' | ||
| # execute the common SConstruct file | ||
| exec(compile(open(xpccpath + '/scons/SConstruct', "rb").read(), xpccpath + '/scons/SConstruct', 'exec')) |
154 changes: 154 additions & 0 deletions
154
...les/stm32f4_discovery/radio/dw1000/double-sided_two-way_ranging_dw1000/responder/main.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| /* This is an Example application for one STM32F4 in combination with a Decawave DM1000 Chip | ||
| * Connections are the following: | ||
| * | ||
| * USART: STM32 Pin | ||
| * TXD -> PA2 | ||
| * RXD -> PA3 (not used in this example) | ||
| * | ||
| * DM1000: | ||
| * SPI: STM32 Pin | ||
| * Miso -> PB15 | ||
| * Mosi -> PC2 | ||
| * Clock -> PB10 | ||
| * | ||
| * RES -> PA8 | ||
| * Chipselect -> PE8 | ||
| * IRQ -> PD10 (not used in this example) | ||
| * | ||
| * What this program does is: | ||
| * 1) Waits for any ranging Frame on the channel and sends a corrosponding answer | ||
| */ | ||
|
|
||
|
|
||
| #include <xpcc/architecture/platform.hpp> // include for platform | ||
| #include <xpcc/debug/logger.hpp> // include for DW1000 Error/Debug Messaging | ||
| #include <xpcc/driver/radio/dw1000/dw1000.hpp> // DW1000 Driver | ||
| #include <xpcc/communication/Frame802154/Frame802154.hpp> // MAC Frame for IEEE 802.15.4 | ||
| #include <xpcc/positioning/ranging.hpp> // ranging operations for DW1000 | ||
| #include <xpcc/processing/timer.hpp> // Timer and Timeouts | ||
|
|
||
|
|
||
| // ------------------------------XPCC---------------------------------------------- | ||
| xpcc::IODeviceWrapper< Usart2, xpcc::IOBuffer::BlockIfFull > loggerDevice; | ||
|
|
||
| // // Set all four logger streams to use the UART | ||
| xpcc::log::Logger xpcc::log::debug(loggerDevice); | ||
| xpcc::log::Logger xpcc::log::info(loggerDevice); | ||
| xpcc::log::Logger xpcc::log::warning(loggerDevice); | ||
| xpcc::log::Logger xpcc::log::error(loggerDevice); | ||
|
|
||
| //Namespaces and renaming | ||
| using namespace Board; | ||
| using SPI = SpiMaster2; | ||
| using RES = GpioOutputA8; | ||
| using CS = GpioOutputE8; | ||
| using IRQ = GpioInputD10; | ||
|
|
||
| using dwm = xpcc::Dw1000 < SPI, CS, RES, IRQ >; | ||
| using ranging = xpcc::Ranging < dwm >; | ||
|
|
||
|
|
||
| //------------------------------DWM Config------------------------------------------------ | ||
|
|
||
| static xpcc::dw1000::config_t config = | ||
| { | ||
| 2, /* Channel number. */ | ||
| xpcc::dw1000::PRF_64M, /* Pulse repetition frequency. */ | ||
| xpcc::dw1000::PLEN_128, /* Preamble length. Used in TX only. */ | ||
| xpcc::dw1000::PAC8, /* Preamble acquisition chunk size. Used in RX only. */ | ||
| 9, /* TX preamble code. Used in TX only. */ | ||
| 9, /* RX preamble code. Used in RX only. */ | ||
| 0, /* 0 to use standard SFD, 1 to use non-standard SFD. */ | ||
| xpcc::dw1000::BR_6M8, /* Data rate. */ | ||
| xpcc::dw1000::PHRMODE_STD, /* PHY header mode. */ | ||
| (129 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ | ||
| }; | ||
|
|
||
|
|
||
| /* Default antenna delay values for 64 MHz PRF*/ | ||
| static constexpr int TX_ANT_DLY = 16436; | ||
| static constexpr int RX_ANT_DLY = 16436; | ||
| static constexpr uint16_t hostaddress= 0xAAAA; | ||
|
|
||
|
|
||
| xpcc::Frame802154 receiveframe; | ||
| xpcc::ShortTimeout timeout; | ||
| uint8_t buffer[256]; | ||
| bool isrx = false; | ||
| uint32_t length; | ||
|
|
||
|
|
||
| //-------------------------------MAIN----------------------------------------------------- | ||
| int | ||
| main() | ||
| { | ||
| //setup USART | ||
| GpioOutputA2::connect(Usart2::Tx); | ||
| GpioInputA3::connect(Usart2::Rx, Gpio::InputType::PullUp); | ||
| Usart2::initialize<Board::systemClock, 115200>(12); | ||
| //initialize the board | ||
| Board::initialize(); | ||
| //activate the CS on the DW1000 | ||
| CS::setOutput(xpcc::Gpio::High); | ||
| //setup SPI | ||
| GpioOutputB15::connect(SPI::Mosi); | ||
| GpioInputC2::connect(SPI::Miso); | ||
| GpioOutputB10::connect(SPI::Sck); | ||
| SPI::initialize<Board::systemClock, 1312500ul>(); | ||
| SPI::setDataMode(SPI::DataMode::Mode0); | ||
| //Init with the config | ||
| while (!dwm::init(config)) | ||
| {LedRed::set();} | ||
| LedRed::reset(); | ||
| /* Apply antenna delay value.*/ | ||
| dwm::setRXAntennaDelay(RX_ANT_DLY); | ||
| dwm::setTXAntennaDelay(TX_ANT_DLY); | ||
|
|
||
| dwm::hostaddress = hostaddress; | ||
|
|
||
|
|
||
| while (true) | ||
| { | ||
| isrx = false; | ||
| dwm::rxEnable(); | ||
| LedOrange::set(); | ||
| while(not(isrx = dwm::checkForRX() || dwm::checkForRXError())) | ||
| {} | ||
| LedOrange::reset(); | ||
| if (isrx) | ||
| { | ||
| length = dwm::rxlength(); | ||
| dwm::readrx(length, buffer); | ||
| receiveframe.loadFrame(length, buffer); | ||
| if (receiveframe.getDestinationAddress16() == hostaddress || receiveframe.getDestinationAddress16() == 0xFFFF) | ||
| { | ||
| LedGreen::set(); | ||
| if(ranging::IsRangingFrame(receiveframe)) | ||
| { | ||
| ranging::sendAnswer(receiveframe); | ||
| timeout.restart(5); | ||
| while(not(dwm::isFrameSent() || timeout.isExpired())) | ||
| {} | ||
|
|
||
| } | ||
| LedGreen::reset(); | ||
| } | ||
| else | ||
| { | ||
| LedBlue::set(); | ||
| xpcc::delayMilliseconds(100); | ||
| LedBlue::reset(); | ||
| } | ||
|
|
||
| } | ||
| else | ||
| { | ||
| LedRed::set(); | ||
| xpcc::delayMilliseconds(100); | ||
| LedRed::reset(); | ||
| } | ||
| dwm::trxdisable(); | ||
| dwm::rxreset(); | ||
|
|
||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
.../stm32f4_discovery/radio/dw1000/double-sided_two-way_ranging_dw1000/responder/project.cfg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [build] | ||
| board = stm32f4_discovery | ||
| buildpath = ${xpccpath}/build/stm32f4_discovery/radio/${name} | ||
|
|
||
| [parameters] | ||
| uart.stm32.2.tx_buffer = 1024 |
4 changes: 4 additions & 0 deletions
4
examples/stm32f4_discovery/radio/dw1000/rx_tx_dw1000/SConstruct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # path to the xpcc root directory | ||
| xpccpath = '../../../../..' | ||
| # execute the common SConstruct file | ||
| exec(compile(open(xpccpath + '/scons/SConstruct', "rb").read(), xpccpath + '/scons/SConstruct', 'exec')) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessarily long line.
(Not only here)