MicroFobo / Fall 2019
Fobo Poser to ArxRobot firmware with 3DoT: V9
Author: Paco Ellaga
Table of Contents
Introduction
When it comes to creating the firmware for MicroFobo using the 3DoT in relation to implementing it into Arxterra’s ArxRobot app, the user will encounter a bit of navigation to understanding both C++ and Arduino C/C++. In the process of understanding the Fobo Poser app, the code to create the Fobo Poser app was also looked into.
This is where a lot of unnecessary amount of time was accidentally spent on to understand, as the language the app was built upon was different (C# and XAML using C#) from the one actually exporting (.action which is turned into .pde and read as .ino in Arduino IDE) or directly importing (C++). To begin, the process for the Fobo Poser app will be explained, followed by the C++ and header file modified and used, and lastly by the implementation of the 3DoT into the .action files produced from Fobo Poser.
First Steps – Decoding Fobo Poser’s Importance
When the user comes across the Fobo Poser after downloading from projectbiped.com, the user will come across an interface where the user will be able to create the custom frame sets that are composed of 8 different servo positions. As shown below in the figure, the user will see this setup:
Breaking this down, the user is allowed to do several different things:
- Calibrate servo positions (to 60° AKA Home Position) every time new servos are installed and/or (Micro)Fobo is built/rebuilt.
- The reason is that within each degree of freedom, Fobo will not have all 8 servos perfectly center when installing them. When having a preset walking gait defined from specific servo angles, if Fobo is not angled correctly, it WILL fall over.
- Recommendation: If possible, do not unnecessarily rebuild MicroFobo if there is no reason to. This is due to the unnecessary amount of time it takes to recalibrate each servo.
- Create a full calibration file based on certain servo configuration setup
- This will auto-generate a file that will make MicroFobo run that calibration command sequence.
- Create .action files to make a sequential frame set command sequence that adjusts MicroFobo’s 8 servo positions to make a specific gesture/pose.
Given this, whether the user will be implementing 3DoT or not, they will still need to use this app at least for calibration purposes. In doing so, there is a specific procedure for which the user will need to follow to make this happen.
Breaking down the C# and XAML Files (Misdirection)
In the process before getting to the procedure of how one will get MicroFobo properly integrated into the 3DoT, it would probably be smart to explain which set files one should NOT analyze that comes with MicroFobo and Fobo Poser. If not told, it could potentially set successors of MicroFobo into the direction of wasted effort as well given the time frame allowed to complete the design project. As result of this, for this generation, it ended up with no change to those numerous C# and XAML files but the others (Servoshield.h, Servoshield.cpp, and exported .action files) as they will be explained in detail later on.
These files that wasted time were spent on were essentially all of the C# and XAML (using C#) files. Up to PDR, it was sought into best interest to change the method of the Fobo Poser app where it can be possibly immediately be calibrated for the 3DoT, since all the files were in direct relation for servo positions, maximum and minimum angles, and logic sequences between the servo angles matrices. While, yes, they were set for servo calibrations, it was ultimately found that this was incorporated into developing the exported .action file as result from the ServoShield header and C++ files. So, by modifying the C# and XAML, the user will not actually change the results, but how the Fobo Poser app is structured. Furthermore, since the 3DoT is integrated with Arduino and the Fobo Poser app is powered by sending it out to Arduino, only the ServoShield header file, C++, and exported .action file are the necessary files to modify.
If one were interested to see all these files, it would be found here. In this page, download Fobo Poser Source (C#, WPF, Visual Studio 10 solution) and all the files included were the files analyzed and wasted time upon.
ServoShield.h and ServoShield.cpp
As regard to the explanation for the header and C++ file, it was discovered to be more use to James Spane in setting up the electronics and PCB design. So, it was taken up by James to understand the mechanics of how it worked alongside the assistance of Professor Hill. Please refer to this blog post written by James Spane to go into futher detail. The only needed detail will be exported from there that is needed here for this post, is that the #include wProgram.h needs to be rewritten as #include Arduino.h and that there needs to a modified version for 3DoT specifically and a non-modified one for calibration for the Remote_Control.ino file found on Project Biped.
3DoT Implementation
From here on, the development of MicroFobo evolved. Originally MicroFobo had reached the full development cycle to where it was able to be fully programmed with wall detection and maze solving capabilities at a “Micro” size. This new development for MicroFobo is that the robot is now programmed to have a full walking gait capability like it’s predecessor. But, instead of only being fully automatic upon awaking, it is now capable of being activated and controlled manually via an external app aside from the Fobo Poser. This app is non other than the ArxRobot app in conjunction with the 3DoT board V9. As for full redevelopment into making this work for 3DoT and ArxRobot, this will have to start from the beginning.
Remote Control Preparation
To begin the firmware, the user will need to download the Remote Control Program and the Fobo Poser app from Project Biped. From here, it is assumed the user has their electronics and system designed. Below, is the complete code of the Remote Control program as provided by Project Biped.
It is also to be noted that if the user is planning to implement a 3DoT system, upon initial setup they CANNOT use a 3DoT and MUST use an Arduino with the ORIGINAL Servoshield.h and ServoShield.cpp file. In the following code, the include is labeled as ServoShield2.h… This is because late in the development process, this detail was forgotten and when V3 of MicroFobo was produced and needed to be calibrated. At this point, V1 and V2 MicroFobo already had 3DoT implemented with a modified Servoshield.h and Servoshield.cpp. Due to the system of Jonathan Dowdall’s code design architecture within the C# files, builds of MicroFobo cannot instantly be connected to 3DoT and the servos must be calibrated using an Arduino setup.
The main take away form here is that the maximumServoShieldPosition and the minimumServoShieldPosition are set to 2000 and 1000, respectively. This is normally preset and the code is used to prepare MicroFobo for the connection to the Fobo Poser. In the method that was approached, this code was untouched and only needed for calibrations and establishing the connections through EstablistConnection() and InitializeServos().
Servo Calibrations
Now that MicroFobo is uploaded with the Remote_Control.ino, the user must now connect MicroFobo to the Fobo Poser to calibrate and set movement (action) commands. What shown below is the walking gate that was used throughout the whole process of redeveloping and taking on MicroFobo.
From here, it is shown in the lower left that the name of the command is called “walk”, there are 10 frames, there is a delay of 12, and that it loops. From there the user can start, stop, and/or export the action to Arduino. Since the method to improve upon was to make it useable for 3DoT, and the 3DoT is implementable from Arduino IDE, exporting to Arduino is currently safe to use. From here generated code will be produced that will contain the matrix of frames recorded from this app and will have a preset method as designed by Jonathan Dowdall of Project Biped.
In the lower right, the user can see their entire movement matrix as frames. These frames are what MicroFobo will be reading to progress as servo position movement. As for the control, the user can add, delete, copy/paste rows making MicroFobo run through them as commands.
As for the middle section, the sliders are what is used to calibrate the servo positions. To create a movement sequence, the user must manually move each slider into a pose that MicroFobo will hold. With MicroFobo’s overarching design, there is a method to how one will make a walking gait. For a full explanation, Project Biped provided a full explanation on how to approach it.
Lastly, for the top row, by pressing the button Press to connect to FOBO, the user will fully connect their Arduino system to MicroFobo (given that the Remote_Control.ino was used correctly with the original Servoshield.h and Servshield.cpp. Fore the Move the Servos to Home Position, the user will use this autocorrelate the sliders to 60°. And before it is too late, it is to be noted that the minumum and maximum degrees allowed for the standard MicroFobo is from -60° -> 60° offset from the center (given the whole range of 120°). Given the V3 of MicroFobo, while servos were replaced, this reduced the clearance for the left and right ankle servos reducing the clearance to be -30° -> 30° form the center (total range of 60° of clearance). As for the Set Calibration File button, if is pressed, the user is able to preload and .action file from their local storage.
Now that is all predefined, one might think how is MicroFobo able to move? This section will actually be pretty short as this is the test for compatibility with the electronic system into integration for the 3DoT and it will described after how MicroFobo moves and what is taken out to move forward in the the Gen 3 development. It is to be noted that the code used for this was offered on the Project Biped site labeled as “Navigation“, where it was modified of an original .action file where Fobo was modded with the working capability of an ultrasonic sensor and turning capability to dodge obstacles.
The only change that needed to accomodate for the new 3DoT system was the calibration array. This array feeds into every MicroFobo differently, due to personal installation of the servos. For this generation upon the V3 model of MicroFobo, it was set to these following values. To break this down in terms where it make sense, the servo position in degree is multiplied by 100 (where 60° is the home position) and the servo positions read as:
Breaking down the mechanics of the Navigation.ino file, the key features and verified through the 3DoT’s implementation was the capabilities to walk, stop, turn in any of that order depending if there is an obstacle in direct course or not in front of MicroFobo. This implentation provided a numerous amount of data and more into how MicroFobo operates.
To start, let’s break down the reason why the exported files are called .action. In the Navigation.ino file, there is a class defined as Action. Now, Action takes precedence in the way MicroFobo works as this is the way how the servo positions are processed from the matrices from the Fobo Poser.
From here, the Action class is futher defined into the way how frames are interpreted and processed over time. As shown below, this is the code of the frame set organization.
To describe what is going on here, let’s break down NextFrame(), GetCurrentFrame(), GetFrame(), and GetIntermediateFrame(). NextFrame() works in a way where the current frame position of MicroFobo it calculated and procedes to move onto the…next frame, in the current matrix, which is also the new servo positions. If the next frame exceeds the max, the frame number is reset to zero. This is then fed into GetCurrentFrame(), where the current frame is found and fed into a being attached with both the frame servo position componentsand the exact frame number in the matrix. This is then fed into GetFrame(), where the frame is calculated into the number of frames in the set, number of frames remaining, if it is above the max amount and how it is from repeating based on a percentage complete. Lastly, GetIntermediateframe() describes taking these percentages and states of the frames. They determine how to move onto the next frame based on current and next frame servo positions before even Fobo moves to and out of it.
Now, the 1st major component is taking multiple matrices to move MicroFobo. In these matrices multiple Actions are made and saved. They are listed as…
Additionally, since there is multiple actions, it is needed that a calibration addition is placed in SetServoPositions(). Specifically, it looks like:
where the servoAngle serves a way to help Fobo recalibrated when each angle is being processed based on the preset calibration servo angles from the Fobo Poser. This is function is found and constantly in Loop(), where the angles are in relation the adjusted calibrated servo angles of MicroFobo.
Now to sum up turning and walking, this is managed automatically by the ultrasonic sensor where it can be seen below:
Now, as shown, this is pretty standard code for setting the ultrasonic sensor, as with the modifaction to make it workable through a single pingPin, which will feed the signal back to determine turning sequences when MicroFobo sees an obstacle up ahead.
Here, inUpdateAction(), this void provided the way MicroFobo determines changes in the way matrices are read and change within it’s logic. Essentially, the way the code works is that if MicroFobo seeas an object when the current action is walking, it will change it current frame and shift it to stop in a servo position where it can start running the turning action from frame zero. Then when the current Action is turning it will turn all the way until it is complete before it will run back to the walking action. This loop essentially can loop endlessly, as if it keeps seeing a wall where it will keep turning till there is no wall or it will keep waking till it finds a wall.
New MicroFobo Features/implementations
Here in this section, the methods of how MicroFobo works directly with the ArxRobot will be explained. It was a long process to finally reach this point and from here it will provide the framework for sucessors to make more implementations to MicroFobo. Given all that was explained, this section will summarize why it was needed to breakdown the sections prior to understand and make ArxRobot works the way it works upon the use of a 3DoT board versus a traditional Arduino setup.
Manual Control Customization + Perks
Now let’s start how the file is modified for the ArxRobot app. This below is how the converted action file is started:
As shown and described, this is the proposed finished app customization, but due to unforseen issues and constraints, alot had to be scrapped and postponed to work on the walk efficiency and complete recalibration of the V3. V3’s design allowed for easier walking due to the lower centewr of mass, but the ankle servo ankles proved challenging. To make the verification due date, alot had to be scrapped and remodeled to where the Move command and the StateActive remained.
As for the matrices and calibrations used, these were the final results and implemented:
This process takes up quite a bit of space, but it proved no problem, as this area acted a journal for the times when MicroFobo was acted upon when calibrations and implementations were set. As recommended earlier, with the 3DoT system, recalibrating becomes a constant effort since the servo angles become thrown off completely. With this whole system, MicroFobo allows for the turn left, turn right, the walk forward, and a resting frame Action where the servos are set to 60° for set amount of time. From here, the setup is next.
By having 4 Actions, the user now will be able to access these through callback as this was a way to forward declare them in the code. For the setup(), the robot mircoFobo.begin(); is called followed by the initialization of the pins, which at this point was only the ultrasonic sensor needed. The servos, which are directed to the CD4017B decade counter, are actually called within the Servoshield files. S, it is unnecesary to call them again in the .ino file. The reason it is needed for the ultrasonic is because it is defined here as a way to create that ObstacleInPath() condition. After that, the user will then load their commands and set MicroFobo to the walking Action. Lastly, after all that, the servos would then become initalized with them being set to the calibrated home position based on the calibrationFrame() matrix.
Now, to reveal how the Action sequences are calculated using ArxRobot, it was discovered that the UpdateAction() was the brain onto how this was achieved. So, by following Arxterra’s tutorials on creating a moveHandler utilizing the MOVE command, the user can access the Joystick controls and hav that feed out a signal to trigger the movement in the UpdateAction(). This was used by creating if-else if statements in the handler and followed by switch-case statements where each case correlated to a directional command to trigger each different Action in the UpdateAction(). In each case, the user will forever run a command until they decide to stop either by the reset Action or by changing the command manually. There is only a single speed and the Action will correlate only to being activated or to not be running at all.
ArxRobot App Interface
Ultimately, over the course of the development, the inferface changed. Due to debugging and limitation of the servo calibrations and time constraints, alot had to be scrapped via the app. Although scrapped in the app, it’s proof of concept existed in the Navigation.ino provided and all that was needed was to fully implement. But, proper implementation was not possible, since multiple versions and servos failing forcing a reconstruction of MicroFobo and constant recalibrating was occuring. Below is the finalized results and only the main header at 0x00 is required along with the MOVE command at 0x01.
Eventually, as if progressed further plans are to add the boolean to make a automatic and manual control mode followed by a selector of automatically turning right or turning left when automatic mode is on. Lastly, a mode to turn ON/OFF MicroFobo was considered, due to having a boosted external battery source attached alongside the 3DoT.
Conclusion – Future Improvement/Implementation
Given this framework, there is aways possibly a better and more efficient way to approach the Action matrices. It was actually advised that possibly the file could be split to save data and make it easier to read. Another idea was to consider removing StateActive and running it directly in moveHandler() instead also flowing into UpdateAction(). They both are great for cleaning up the code and presenting cleaner data to help, but in results…it presented very odd movement. By doing any of these methods, frameDelay() in the Action was either not being properly analyzed or the system ran too slow for some unkwown reason. There was not time to fully figure why the system reacted in this sense, so the code was reverted back to switch-case and having StateActive re-enabled.
Physically, what would happen is that MicroFobo will move when the command was executed, but it will move at a super slow/practically crawling speed. There was not enough time to fully analyze as to why this happened and the results presented to make MicroFobo walk at proper frameDelay() speed is result of what was shown above. Shown below is the attempt made and can be used if it were attempted again. This was attempted when the ultrasonic sensor was being attempted to be plugged in as well. There are no guarantees the sensor will work in this method, but the turn commands were confirmed to work.
As shown here, this is how it was implemented, as said it would produce slower results for MicroFobo. So, it was ultimately abandoned. It was unfortunate as just removing the StateActive and merging moveHandler() and UpdateAction() the .ino sketch would reduce by 10 bytes of dynamic memory. As for future work and implementation, the next and possibly last part would be optimization of the code and adding even more commands to MicroFobo. Overall, the memory did reasonably well, as the most memeory ever used was 50% at max throughout the whole developement process where up to 500+ lines of actual code (minus comments) were being used.
If anything to help the development even further with 3DoT, the camera feature in ArxRobot could have been utilized where a switch of the ultrasonic sensor to a camera mount could be implemented and the Arxterra’s ArxRobot Control Panel could be more useful. Another feature could inprove the speed control utilizing the changes in moveHandler(), where increase input could possibly dynamically change frameDelay().
References/Resources
- http://www.projectbiped.com/prototypes/fobo
- http://www.projectbiped.com/prototypes/fobo/navigation
- http://www.projectbiped.com/prototypes/fobo/walking-cycle
- https://www.arxterra.com/arxterra-built-in-commands-and-telemetry/
- https://www.arxterra.com/arxterra-custom-commands-and-telemetry/
- https://www.arxterra.com/news-and-events/members/3dot-robots/biped-generations/biped-generation-5/
- https://drive.google.com/drive/folders/1kpG_KypcmrSHTbLKSuxfvC8q9DlebUrB