Showing posts with label State Machine. Show all posts
Showing posts with label State Machine. Show all posts

Monday, December 22, 2014

Drone Following Project #13: State of Grace

Work on the "Lakitu" ROS package has began! I'm trying my best to make headway, but unfortunately, I'm also ill at the moment. Currently I'm working on making the Arduino state machine launch the Drone via rosserial. In order to do that though, I'm slowly realizing I could modify my Arduino sketch in a slight manner in order to greatly increase the efficiency of how the two objects communicate. For the time being, the Arduino is constantly broadcasting it's state, and the program is constantly receiving it. As I was implementing this, I realized that this is quite inefficient, if you consider what all is going on in this manner:
  • /Lakitu/Device_State is constantly sending out messages regarding states.
  • The ROS package is constantly receiving these messages.
  • The ROS package is constantly evaluating what to do with these messages.
  •  The ROS package is constantly sending out messages to drone topics such as "/ardrone/takeoff" and "/ardrone/land"
The problem is that we always want the drone to be aware of what it should be doing, but not be bogged down with too much information. Therefore I propose we take a step back and modify the Arduino sketch to now send out two messages, the original and a new boolean message that signifies if this is the first change to a new state. This adds only a slight amount of added stress on the Arduino in order to take a large amount off of the ROS node-- which quickly becomes bungled as the 'communicator' for all aspects of the program. This will reduce our complicated web of 'if' statements constructed from handling the state machine to a much simpler series that will only ever be evaluated if it is the first spin of a new state.

After this has been handled, I'll be working with first just getting some strings on the ROS terminal to match these states, then the Drone's LEDs, and then, finally takeoff and landing (if I can find the space to safely do so). From this point I'll be moving on to handling the IMU's data and orientation, and then GPS.

-----------------------------------------------------------------------------------------------------------------------------------

Additionally, I'll be working on making things more uniform. The device will follow the topic convention of

/Lakitu/Device/<topic>

And things on the ROS end will be 

/Lakitu/<topic>
 

Sunday, December 14, 2014

Drone Following #10: Added ROS capabilities to sketch

Tonight I added ROS functionality to Arduino sketch. It's just a few lines of code, but they have great implications! The LED state machine is now a Publisher and sends its information via the serial port, so now anything connected to ROS on my laptop can read what state the device is in. Logically, the next step is to start working with the Drone. Here are some screenshots from it in action:



As you can see, rosserial got a little upset at my procedure... and I'm not sure why. All 3 states still work in action, but I get lots of mean text as opposed to the approval you get from other message types. A lot of threads seem to indicate this is due to the relative message size and buffer size for the particular board, but I seem to be well within the limits of my ATMEGA32 board. I'm investigating it currently, but as it works, I'll also be moving on to something a lot more exciting.


Drone Following #9: Soldering, State Machine, Github.



I've been quite productive since my finals (finally) ended.

First of all, my chips arrived! I was quite impressed with how small they were! The LSM9DS0 is about the length of half your thumb, and the level converter only a third of that. Not long after they arrived, I snuck out to the school's tech lab and soldered them together. It was nice to get back in the saddle and sit down with the ol' soldering iron. It feels like knitting, but with heat. My work isn't what it used to be, but I think it's enough to get the job done.



Next, I enjoyed my break exactly as envisioned. Tonight I spent the night doing some programming, the beginning of the drone following project. This consisted of creating an 3 state finite state machine. Right now it doesn't do much other than turn on LEDs in a sequential order and via the serial port tell you what state it's in.



But this is very important! After all, when I integrate this with the Drone controls, you don't want it ever going to the wrong state at the wrong time... This could mean taking off or landing at the wrong time. That being said, there was also some fool-proofing to be done-- for example, the Arduino reads super quick (sometimes), so you need to put a time delay in for the button press, or it may quickly transition between states. I handled this by having it hold for a second in a loop if the button is held. Right now all of the states are working as intended, so the next move will be ROS integration-- sending the state to ROS. From here, the Drone will read it, and respond accordingly. The states are as follows: Landing Mode, Takeoff Mode (indicated by a yellow LED) and Calibration Mode (indicated by a green LED). Calibration is where the Drone begins to follow movement.


Finally, I've made myself available on Github. It's been a while since I used it consistently, but I've realized that if I want to show people what I'm made of, I have to... show people what I'm made of. Therefore, I'll try to be consistent in uploading any code changes for your own viewing at my own github profile, Gariben. Here you can find the code for the state machine mentioned, as well as handy Fritzing diagrams and schematics. I'll usually include those in the blog, like so:
Currently, the code is housed under the "AirCat" repository. I didn't quite know what to name the project, since "Drone Following" will properly get me a pitchfork mob from an uneducated following, so I thought I'd just mimic the AirDog project that features the Drone remote, since the ideas are similar. Anyways, I hope to continue work on this project along with work to those I've dedicated myself too, so I'll try to keep everyone updated. Be sure to stay tuned to my Github for the latest-- it always comes at least a little before the blog.