Relevant Equipment used:
- Two Xbee Series 1 modules
- Two Gravitech Xbee shields for the Arduino Nano
- Two Arduino Nano V3.0
Background: I have a rocket that for all intents and purpose is a RC model version of the Space X Grass Hopper rocket. It balances in a similar manner as the traditional cart and inverted pendulum with the exception that this entire system flies utilizing counter-rotating brush-less motors for lift. As of now, I send control signals to the motors from an Arduino connected to my laptop to the Arduino on the vehicle.
Objective of this post: The goal of this post is to be able to determine how to send multiple sets of data from the control station (the laptop) to the vehicle. For example, I wish to be able to send not only speed or altitude commands to the vehicle, I would also like to send position commands. Continuing on with that, when the vehicle is not receiving any commands from the ground station, I would like the vehicle to transmit information to the laptop, such as pitch or roll angles, current GPS information such as signal quality or acquired satellites, etc.
Just to be clear, I don't have any problem sending any of the data one way. For example, if I do not attempt to send any command from the ground station, then I can easily send pitch or roll angles to the laptop from the vehicle. The issue here is true two-way or simultaneous communication.
Here is my initial communication pseudo-code:
Ground - Station:
listen for data from computer
if there is data {
what kind of data is it (position or Altitude)
if data is position
{ format for position and send to vehicle}
elseif data is Altitude
{format for Altitude and send to vehicle}
else listen for data from the vehicle
if there is data from the vehicle
{print in the serial monitor}
Vehicle :
if data is available from the computer
{what kind of data is it (position or Altitude)}
if data is position
{change the position portion of control system}
elseif data is Altitude
{change altitude portion of control system}
else send data to computer
Major Concerns:
-
Do I need to change the modes of the Xbee to make this work? To clarify, do I need to change from AT or point to point mode to API mode?
-
Do I need to format each set of data with specific termination characters. For example, the Arduino knows when altitude data is being sent because it is formatted with these start and end characters '<' '>'. Then the GPS coordinates could be formatted with '' '/' start and end characters. This would be utilized for every type of data being sent. Would this work? Are there better alternatives? If so what are they?
That should do it for now. I would be happy to clarify if anyone has further questions.
Just for reference, I have only been working with the Arduino for about 2 months. I am a recent Mechanical Engineering graduate with little coding experience for this type of application. Therefore, any advice, tricks, tips, etc. would be greatly appreciated.
As a side note, I am curious to learn more about efficient code writing and data structures, etc. Any good starting references would be greatly appreciated.