-
Notifications
You must be signed in to change notification settings - Fork 0
Marketing Bot Overview
This is the Github Repository for the StormBots Marketing Bot, also known as "Mark". This robot was designed, programmed, and built during the Covid-19 pandemic. The robot was designed to serve as a custom platform for marketing event; before the creation of Mark the StormBots used whatever robot was available from the last competition season. Mark was designed to be easier to operate and maintain than the competition bots.
Mark was built with the idea of modularity at its core. The chassis can accept multiple different "modules" on the flat top. As of the writing of this there was one module, a pneumatic T-shirt cannon. To facilitate this modularity Mark does not use the standard FRC RoboRio as a control board. Instead it uses two Teensy 3.2 microcontrollers available from PJRC. Additionally, Mark uses radio Pulse-Position Modulation communication and a RC controller rather than the standard FRC computer and controller setup. This controller setup was chosen for its ease of transport and use compared to a bulky computer. Because of this radically different control schema programming for Mark is remarkably different compared to programming for any other bot.
Because of this difference in control scheme Mark utilizes C++ rather than Java as its programming language. The code is divided into Arduino files for each module and one for the chassis. These files are completely independent aside from the radio communication allowing for the easy swap of modules. Each module and the chassis share some common features. Additionally, these files are split into a setup portion that runs once and a loop portion that repeats. Variables are declared and libraries are called above the setup portion. All programs will need to utilize both the pulse position and ElapsedMillis libraries. The pulse position library allows for radio communication from the robot to the controller. ElapsedMillis is used for the heartbeat of the teensy controller, a led which turns on and off at one second intervals. This led shows that the teensy is operating nominally and is receiving power. All code other than that pertaining to these two libraries will be module specific.
The radio communication is one of the most important and most complex parts of the marketing bot code. The code must communicate from the controller to the chassis, and the chassis to whatever module. This is done through the Pulse Position library. First you need to declare a radio input pin and a radio output pin for the Teensy microcontroller.
Example
#define RADIO_IN_PIN 22 //22 is an example of a port on the teensy
#define RADIO_OUT_PIN 23
Example
Next, you must create a variable for the input and output of the radio. One thing to note is that you don't need a output in the code for a module as it doesn't communicate to anywhere, it only receives signals from the chassis.
Example
PulsePositionOutput radioOutput;
PulsePositionInput radioInput;
Example
Then, in the setup portion of the file you must instruct the library to begin transmitting on the input and output channels.
Example radioOutput.begin(RADIO_OUT_PIN);
radioInput.begin(RADIO_IN_PIN); Example
After this setup you can now read the radio channels and declare them as variables. Each channel should be used for a specific thing. The chassis as it exists currently uses channel #2 for throttle, #1 for turning, and #6 for shifting. However the shifting is currently disabled as of 6/27/2023 due to it causing electrical issues. This leaves the remaining channels: 3,4,5,6,7 and 8 for use in your module.
Example float turningValue= radioInput.read(1);
float shiftValue = radioInput.read(7); Example
These .read()'s return a value between 1000 and 2000 with all the way down being 1000 and all the way up being 2000. Something important to note is that you shouldn't do any <1500 or >1500's as the signal is not perfectly steady and will fluctuate. Instead do >1250 or <1750. 1500 is equivalent to 0% throttle, 2000 is 100% forwards, and 1000 is 100% backwards. By putting this .read() in the loop section it updates every time the program runs.
You can then use the variable you read the radioInput channel into via the Whatever your motor is called.writeMicroseconds(Example_Variable). You could also do MotorName.(1500) to make a motor stop.
It is also recommended to use the constrain function to avoid any interference creating abnormal results. This function removes reads that are outside the normal range of 1000-2000. Example constrain(exampleInputVariable,1000,2000) Example
Next, the chassis must pass on the radio signal from the controller to the module. The current code is as follows:
Example if(radioInput.available() < 8){ return; }
for(int i=1;i<=8; i++){ radioOutput.write(i,radioInput.read(i)); } Example
This checks if a channel has been used, and if so it writes the value on that channel to the module. Any values that are modified by the chassis should additionally be written to the module to ensure the modules do not become desynced.
Example radioOutput.write(2,throttleValue);
radioOutput.write(1,turningValue);
radioOutput.write(6,shiftValue); Example
The radio communications via PulsePosition is one of the most vital portions of marketing bot code and is necessary for the creation of any new modules.
Another library that all future modules will need to use is the elapsedMillis library. This library acts as a resettable timer and is ubiquitously used in MarketingBot code for the heartbeat on the Teensy. This "heartbeat" is an on-board LED flickering on and off to indicate that the code and the hardware is functioning properly.
This heartbeat is created by declaring an elapsedMillis variable, usually named heartbeat at the beginning of the code. We also define a pin on the teensy for the on board led that we will then write to. Next, in the setup portion of code, we set whatever pin we assigned to the LED to output mode:
Example pinMode(13,OUTPUT); Example
Then in the main loop we check if the heartbeat has reached 1000. If it has, heartbeat=0 and:
Example
digitalWrite(BUILT_IN_LED, !digitalRead(BUILT_IN_LED)
Example
This causes the LED to blink on and off once a second. elapsedMillis, as the name implies, counts milliseconds so 1000 is equivalent to one second. Overall, this creates an easy way to see if a module is functioning and detect both code and electrical faults.
Marketing Bot
Bottom text