Difference between revisions of "F16: Autonomous Nautical System"
(→Analog/Digital Converter and SPI) |
(→Software Design) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 156: | Line 156: | ||
* Terminal Task | * Terminal Task | ||
* Navigation Algorithm | * Navigation Algorithm | ||
+ | |||
+ | <syntaxhighlight lang="c++" line> | ||
+ | |||
+ | |||
+ | class navigation_task : public scheduler_task | ||
+ | { | ||
+ | public: | ||
+ | navigation_task(uint8_t priority); ///< Constructor | ||
+ | datalog dl, dl2; | ||
+ | |||
+ | bool run(void *p) | ||
+ | { | ||
+ | xSemaphoreGive(xSemaphoreGPS); | ||
+ | xQueueReceive(printtoSDcard, &dl, 1000); | ||
+ | xSemaphoreGive(xSemaphoreTemp); | ||
+ | xQueueReceive(printtoSDcard, &dl2, 1000); | ||
+ | dl.temp = dl2.temp; | ||
+ | string s= ""; | ||
+ | s += dl.time +','+dl.latitude +','+ dl.dirNS + ',' + dl.longitude + ',' + dl.dirEW + ',' + dl.temp + '\n'; | ||
+ | char s2 [35] = {0}; | ||
+ | for(int temp = 0; temp < 35 || temp < s.length(); temp++) | ||
+ | s2[temp] = s.at(temp); | ||
+ | Storage::append("1:log.txt", &s2 , 35, 0); | ||
+ | return true; | ||
+ | } | ||
+ | bool init() | ||
+ | { | ||
+ | return true; | ||
+ | } | ||
+ | private: | ||
+ | |||
+ | }; | ||
+ | |||
+ | </syntaxhighlight> | ||
== Implementation == | == Implementation == | ||
Line 175: | Line 209: | ||
=== Analog/Digital Converter and SPI === | === Analog/Digital Converter and SPI === | ||
− | 1. Initialize SPI | + | |
+ | {| | ||
+ | |[[File:Tempreadings.jpg | thumb|400px|left| Fig. 2 Output for the temperature sensor]] | ||
+ | |1. Initialize SPI | ||
2. CS the device | 2. CS the device | ||
Line 182: | Line 219: | ||
4. Run ThermometerRead() with retrieved value | 4. Run ThermometerRead() with retrieved value | ||
+ | |- | ||
+ | |[[File:SPI-ADconvert.jpg | thumb|400px|left| Fig. 3 Schematic for A/D converter]] | ||
+ | |} | ||
− | |||
[[File:UpperTierHardwareBase.png|thumb|400px|center| Fig. 3 Top of the base]] | [[File:UpperTierHardwareBase.png|thumb|400px|center| Fig. 3 Top of the base]] | ||
[[File:BottomTierHardwareStack.png|thumb|400px|center| Fig. 4 Bottom of the base]] | [[File:BottomTierHardwareStack.png|thumb|400px|center| Fig. 4 Bottom of the base]] |
Latest revision as of 03:11, 22 December 2016
Contents
Grading Criteria
- How well is Software & Hardware Design described?
- How well can this report be used to reproduce this project?
- Code Quality
- Overall Report Quality:
- Software Block Diagrams
- Hardware Block Diagrams
- Schematic Quality
- Quality of technical challenges and solutions adopted.
Autonomous Nautical Systems for Ocean Transit and Survey (ANSOTAS)
Abstract
Constructing an autonomous navigation system responsive to GPS and Tilt Compass feedback to form and track trajectories to a given location. Low power, and observant system.
Objectives & Introduction
Peripheral goals include
- Logging to SD card using SPI
- Analog to Digital Converter reading of Temperature sensor
- Reading and controlling GPS using UART
- Reading compass measurements using UART
Team Members & Responsibilities
- Angel Hernandez-Perez
GPS control, compass, AD converting, Navigation Algorithm
- Fayek Wahhab
Servo control, compass, power management
- Abraham Carrillo
Motor Control, power management, logging to SD card
Schedule
Table 1. Schedule
Week# | Date | Tasks | Actual |
---|---|---|---|
1 | 10/8 | Decide on boat hull based on the amount of devices
we planned to us. Purchased motor, servo, and battery accordingly |
Completed
Brushed DC motor powered by Electronic Speed controller was purchased. |
2 | 11/4 | Intercept the pwm signals issued
by a remote control for steering and speed throttling. Decode these signals over time to identify which values produce what kind of effect to the driving system. |
Completed
Using a logic analyzer did not work the way we planned. An oscilloscope was used but only to prove that this was not necessary since the motor and servo reacts to PWM as any other motor or servo. |
3 | 11/25 | Make separate compass, gps, and pwm tasks | Completed
These tasks are a simple tasks demoing the functionality |
4 | 12/02 | Link separate task outputs together
using navigation task. |
Completed
Debug the steering and motor control commands issued by the state of the navigation task state machine. |
5 | 12/16 | Revise gps task to give only needed
information and use all task outputs in the navigation task. |
In Progress
Buggy and needs to check for invalid information using checksum |
6 | 12/20 | Update the wiki page | In Progress
Clean up exceptions in the land demo program |
Parts List & Cost
- SJ One Board | $80.00
- Tilt Corrected Compass | $30.00
- GPS | $50.00
- 7.2V 2600mAH Battery (included w/hull)
- 5V 5200mAH Battery | $13.00
- Hull | $155.00
- DC Motor (included w/hull)
- Servo (included w/hull)
- Electronic Speed Controller (included w/hull)
Design & Implementation
The design section can go over your hardware and software design. Organize this section using sub-sections that go over your design and implementation.
Hardware Design
Considerations for our hardware include power consumption and usefulness in a water scenario. The root of this project where sensor input is analyzed and output signals are distributed is the SJ One board. Using the FreeRTOS OS an autonomous system can adjust its velocity and direction by controlling the motor and servo. GPS and Tilt compass provides the feedback needed to make adjustments.
Hardware Interface
I2C
I2C was used to communicate to and from the SJ One board to the tilt adjusted compass. This protocol allows numerous sensors to be connect to a single wire to all devices for transmitting and receiving address and data information. This is possible because of synchronization of a clock signal and a pull-up resistor used in setting up the data/address bus. The disadvantage with this choice is speed since it can only transfer a max of 100KHz.
For our design we use our SJ One board as the master and the compass as the slave device. It is only enabled if it receives it's address from the master. Through out the operation of protocol a slave and master are under constant bidirectional communication. Using a byte or more to communicate what is desired in the form of an slave address, byte address and a quantity for receiving or transferring data. This continuous process follows a state machines for both the slave and master devices. Below Fig 5. describes for example a basic sequence of states that the slave can go through for receiving and transmitting data to a master. If at any point during transmission a data packet is invalid the transmission can abort and require exception handling.
SPI
A full duplex communication protocol characterized by the single unidirectional input and output lines between master(s) and slave(s). Our project utilizes SPI to transmit and receive data for logging on the external SD card and interface with the compass. The plan is to use a form of serial communication for it's speed and ability to use GPIO for enabling the devices' chip select.
UART
Communicating between the compass and GPS module support UART however would not be able to use the same TX and RX since there is no protection from connecting outputs from these devices. This form of communication is asynchronous which means the unidirectional data lines can be flooded with data to a particular device and does not require addressing to occur through those lines.
GPS
Extra considerations had to be noted for software driver which handles data to the microcontroller from the sensor. As the 16-byte receiving FIFO is flooded with bytes to be read an interrupt is needed to clear the FIFO of it's items and store them in a safe place. This is necessary in order to completely read a message which on average is 70 characters or bytes long.
Software Design
Building tasks dedicated for controlling each sensor is the first step to our design approach.
- GPS_task
- Compass_task
A few tasks are used to schedule and communicate data between the tasks would be the following edited libraries.
- Terminal Task
- Navigation Algorithm
class navigation_task : public scheduler_task
{
public:
navigation_task(uint8_t priority); ///< Constructor
datalog dl, dl2;
bool run(void *p)
{
xSemaphoreGive(xSemaphoreGPS);
xQueueReceive(printtoSDcard, &dl, 1000);
xSemaphoreGive(xSemaphoreTemp);
xQueueReceive(printtoSDcard, &dl2, 1000);
dl.temp = dl2.temp;
string s= "";
s += dl.time +','+dl.latitude +','+ dl.dirNS + ',' + dl.longitude + ',' + dl.dirEW + ',' + dl.temp + '\n';
char s2 [35] = {0};
for(int temp = 0; temp < 35 || temp < s.length(); temp++)
s2[temp] = s.at(temp);
Storage::append("1:log.txt", &s2 , 35, 0);
return true;
}
bool init()
{
return true;
}
private:
};
Implementation
This section includes implementation, but again, not the details, just the high level. For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI Flash. You can include sub-sections for each of your component implementation.
PWM and Compass
1. Initialize UART3
2. Set up PWM port and refresh rate
3. Send byte containing 0x13 to Compass
4. Read both bytes in receiving holding register
5. Calculate the duty cycle percent
6. Set PWM duty cycle
Analog/Digital Converter and SPI
1. Initialize SPI
2. CS the device 3. Send 0x01 0x80 0x00 as byte transfers 4. Run ThermometerRead() with retrieved value | |
Testing & Technical Challenges
The test plan includes unit testing, and integration testing. After writing the code for each task we used each method of each task class as the starting point for treating as a unit under test. Before, during, and after development any referenced class endured it's own unit testing. For example the classes which control communication protocols were heavily tested to ensure that data was not corrupted during transit. During higher level unit testing erroneous was output but testing had to be done on the classes used. By adding print statements to the data before and after packaging and transferring data. Following the results that tasks worked independently using black box testing the tasks were tested using integration testing. This area remains to this moment an area requiring further tests. In the following subsections, detailed descriptions and solutions faced in this project will be explained.
GPS Issue #1
Issue: GPS data is sent constantly from the GPS module through UART without the need for a command. Full messages referred to as NMEA sentences are received by the module and read by the microcontroller. They do not always arrive in their entirety or represent accurate data.
Solution: To counter act this problem a checksum value is included in the sentence and is useful for checking the values of he payload checksum value for the specific data in the message.
GPS Issue #2
Issue: Coordinates in the NMEA sentences are off by more than +/- 5 meters.
Solution: Following extensive research there is the possibility of configuring known reference geographical locations with the X,Y,Z and (longitude,latitude) coordinate that the GPS module is preloaded with for comparing to. However this did not help as much as making sure we used the WAAS feature which allows the GPS to get feedback from federal ground references for calculating how off satellites are in their pinning a location.
GPS Issue #3
Issue: NMEA messages that represent the recommended minimum specific are around 67 characters can overflow the local RX FIFO used with UART. Since the FIFO is 16 bytes long the FIFO runs the list of running out of space for storing items so an interrupt is used for sensing when data populates the queue.
Solution: To counter act this problem a checksum value is included in the sentence and is useful for checking the values of he payload checksum value for the specific data in the message.
Conclusion
This project provided several lessons in the values of through unit testing of each of our tasks, and integration testing of all the parts. Complications arose during the formation of our final higher level navigation task which analyzes the readings from our sensors to send commands for the system to reach the same starting GPS location.
From an organizational standpoint if more effort was taken to separate our initialization of our peripherals and our few operations for each sensor the unit testing would be more effective at catching bugs. As we observed in our issues during testing data was invalid which can hinder the pools of data being collected.
Project Video
Project Source Code
References
Acknowledgement
Acknowledgements for code and lab instruction to Preetpal Kang.
In addition, theory of embedded microcontroller design is for Prof. Haluk Ozmek.
References Used
GPS Recommended Minimum Specifics Parsing
MCP3004 A/D converter Datasheet
Appendix
N/A