Modern Robotics Inc. Core Spartan Controller Documentation Version 3.0.
Core Spartan Documentation Modern Robotics, Inc Contents 1. 2. 3. Document Control ................................................................................................................. 4 Description............................................................................................................................. 5 Express Installation via Ardublockly for Spartan ............................................................... 6 3.1.
Core Spartan Documentation Modern Robotics, Inc 9.2. Compass (45-2003) ............................................................................................. 41 9.3. Integrating Gyro (45-2005) ................................................................................ 44 9.4. Range Sensor (45-2008) ..................................................................................... 47 9.5. IR Locator 360 (45-2009) ........................................................................
Core Spartan Documentation Modern Robotics, Inc 1. Document Control Revision History Version Date 1.0.0 12/7/15 1.1.0 1/15/16 2.0.0 2/29/16 2.1.0 5/17/16 2.1.1 6/9/16 2.1.2 10/12/16 2.2.0 2/6/17 2.2.1 2/7/17 3.0.0 4/7/17 3.0.1 5/24/17 3.0.2 7/10/17 3.0.
Core Spartan Documentation Modern Robotics, Inc 2. Description The following document is a guide for the use and implementation of the Core Spartan Controller and all Core Sensor functions. The Core Spartan Controller is the control center that runs user code and handles all the data produced by the Core Sensors. The Core Spartan Controller is easy to connect, control, and program your robot with the use of the Arduino IDE.
Core Spartan Documentation Modern Robotics, Inc 3. Express Installation via Ardublockly for Spartan Ardublockly is a block coding environment that makes it easy for anyone at any age to program their very own robot. When Ardublockly is installed it comes with the Ardublockly programming environment, Arduino 1.6.8, Core Spartan Library and the Core Spartan Controller Board. 3.1.
Core Spartan Documentation Modern Robotics, Inc 4. Manual Installation of Core Spartan Resources The following is a guide to install the resources necessary to control a Core Spartan Controller on any platform that supports Arduino. There are two main steps involved in installation of Core Spartan Resources: installation of library and examples via a .zip file and installation of the board file via the Arduino Board Manager.
Core Spartan Documentation Modern Robotics, Inc Step3 Navigate using the file browser to the place where CoreSpartanController.zip was downloaded. Then click “Open” to load the file into the Arduino IDE. Arduino will respond if the library was successfully installed or if it failed. Step 4 Restart the Arduino IDE to ensure that Core Spartan Controller Library is fully loaded. To verify that your library is installed, please check to see if CoreSpartanController show up in the corresponding locations.
Core Spartan Documentation 4.2. Modern Robotics, Inc Installation of the Board via Arduino Board Manager Installing the Core Spartan Controller Board via that Arduino Board Manager is a safe and straightforward to add different boards to your Arduino environment. Once a board is added to Arduino via the board manager the board will be automatically update on your machine when the Arduino IDE opens. Step 1 Open Arduino and navigate to File ► Preferences and open the preferences window.
Core Spartan Documentation Modern Robotics, Inc Step 2 In the lower half of the window there is a field labeled “Addition Boards Manager URLs.” This is where you want to paste the URL: http://modernroboticsinc.com/Content/Images/uploaded/Spartan/ArduinoLibrary/package_CORE_SUPPORT_index.json Once you have completed this step, click “OK”. Step 3 Now navigate to Tools ► Boards ► Boards Manager… and open the board manager. Version 3.0.
Core Spartan Documentation Modern Robotics, Inc Step 4 Type “Spartan” into the search bar to find the Core Spartan Controller. Find the Modern Robotics AVR Boards that has the Core Spartan Controller package and install it by click the “Install” button in the lower right corner of the box. Step 5 Select the Core Spartan Controller as the board you want to use by navigating to Tools ► Boards ► Core Spartan Controller.
Core Spartan Documentation 4.3. Modern Robotics, Inc Testing Installation of Library and Board To test and verify the installation of all the components please restart the Arduino IDE. Step 1 Go to File(Arduino) ► Examples ► CoreSpartanController ► CoreController ► FlashLEDs and upload the program to the Core Spartan Controller. Step 2 Connect your Core Spartan Controller to your computer.
Core Spartan Documentation Modern Robotics, Inc Step 3 Go to Tools ► Ports ► Core Spartan Controller to set the port to the Core Spartan Controller. If your Core Spartan Controller does no show in the list of COM ports (/dev/cu.usbserial- for Mac) then your module has not yet fully installed drivers on your computer. Step 4 Upload the FlashLEDs.ino program to your Core Spartan Controller.
Core Spartan Documentation Modern Robotics, Inc Step 5 If you have successfully compiled and uploaded the program to your Core Spartan Controller you will notice the Red and Blue on board LEDs are blinking with a 50mS on/off cycle. When the Core Spartan Controller is first connected the Red and Blue LEDs will blink back and forth at a slow pace. If you have successfully compiled and uploaded the program to your Core Spartan Controller, the LEDs will blink at a much faster rate (50ms intervals). 4.4.
Core Spartan Documentation Modern Robotics, Inc 5. Modern Robotics Spartan Coding Methods This section will break down the style of coding used in the examples and explain some syntax used in the code. For questions or concerns about the programming language, please contact us at support@modernroboticsinc.com for assistance. Modern Robotics Header Include Statements Object Declarations Setup Loop Add your own functions Version 3.0.
Core Spartan Documentation 5.1. Modern Robotics, Inc Modern Robotics Header The Modern Robotics Header is in every example published by Modern Robotics. At the top of the header is the name of the file and the main sensors that are being used in the program. Below that are two to three paragraphs are designed to be informative by explaining the sensor use and a description of the expected behavior of the example.
Core Spartan Documentation 5.2. Modern Robotics, Inc Include Statements The include statement is a key function used to import other pieces of code into the current file. For our use we include the CORE.h header file which includes all basic Core Spartan Controller functions and sensor libraries. When including CORE.h into your code double quotes (“”) must be used and not the angled brackets (<>). #include “CORE.h” 5.3.
Core Spartan Documentation Modern Robotics, Inc The naming of objects become crucial when using multiples of the same object. The example below demonstrates the use of naming multiple objects for use in code. The example will use the ODS sensor (section 7.3). CORE_ANALOG left(A0); CORE_ANALOG right(A1); … left_value = left.read(); right_value = right.read(); In this example both the left and right optical distance sensors use the same function read().
Core Spartan Documentation 5.5. Modern Robotics, Inc Loop The loop is the part in code that follows directly after the setup. The loop consecutively loops around allowing the program to continually run. The below example assumes “CORE_DIGITAL touch(7);” is called before setup. void loop(){ if(touch.read() == 0) Serial.println(“value is 0”); if(touch.read() == 1) Serial.
Core Spartan Documentation 5.6. Modern Robotics, Inc Add your own functions Using a user function can really help clean up code or help in using complex algorithms. All user functions must be declared after the loop and can be any type (void, int, char, etc). For example, in the example GetInfo.ino there is a custom function placed after the loop. void cls (void){ int counter = 100; while(counter--) Serial.print("\n"); } This function is called inside the loop making user functions clean and easier to d
Core Spartan Documentation Modern Robotics, Inc 6. Core Spartan Controller (45-2000) The Core Spartan Controller is the processing and control center for the all the Core sensors. Core is driven by an Atmega328P chip using the Optiboot bootloader that controls all the Core sensors. A PIC24F Microchip is used to drive the motors and servos using a PWM signal. The chips communicate with each other via I2C communication. Battery power must be ON to use the Core functions, i.e. motors, servos and information.
Core Spartan Documentation Modern Robotics, Inc *** When compiling, use the Core Spartan Controller, in the Tools ► Board ► Core Spartan Controller *** Core Functions: CORE_SPARTAN(); long getInfo(void); unsigned char getControllerStatus(void) unsigned char getBatteryVoltage(void) void servoEnable(unsigned char servo, unsigned char enable) void servoTarget(unsigned char servo, unsigned char target) int servoPosition(unsigned char servo) void motorMode(unsigned char motor, unsigned char mode) void motorSpe
Core Spartan Documentation Modern Robotics, Inc unsigned char getControllerStatus(void) Returns the status of the battery to the user. 0 – Normal Operation 1 – Battery Fault 2 – Battery Low unsigned char value; value = CORE.getControllerStatus(); …or… Serial.print(CORE.getControllerStatus()); unsigned char getBatteryVoltage(void) Returns the current battery voltage in 40mV increments to the user. If value=35, then battery voltage is (35 x 0.04) = 1.4V unsigned char value; value = CORE.
Core Spartan Documentation 6.2. Modern Robotics, Inc Servos PWM +5V Ground Servos come with a variety of colored wire. Please ensure that your servo follows this wiring scheme before operation. Version 3.0.
Core Spartan Documentation Modern Robotics, Inc void servoEnable(unsigned char servo, unsigned char enable) This function turns the servo(s) on or off. This function may be called anywhere in code, however it is advised to use it in the setup function. The parameter servo refers to which servo will be enabled or disabled. The parameter enable determines if the servo(s) will be on or off.
Core Spartan Documentation 6.3. Modern Robotics, Inc Motors OR The Core Spartan Controller works with the Spartan DC Motors. The Spartan DC Motors are housed in a servo style housing with two wires: red for power and black for ground. Connecting the motors in reverse polarity will switch the direction of motor rotation and will not cause any damage to the controller or the motors. Version 3.0.
Core Spartan Documentation Modern Robotics, Inc void motorMode(unsigned char motor, unsigned char mode) This function sets the mode for the motor(s). The parameter motor refers to the motor(s) that will experience the change in state. The parameter mode refers to the way the motor(s) will function. In FLOAT mode, the motor is able to coast to a stop at a speed value of 0, unlocking the motor allowing it to spin freely.
Core Spartan Documentation 6.4. Modern Robotics, Inc Core Reset void reset(void) When this function is called, the Core Spartan Controller will reset like the hardware reset button. CORE. reset(); 6.5. Core LED void led(unsigned char led, unsigned char state) This function turns on and off the on-board LEDs. These LEDs correspond to digital ports 12 and 13, BLUE and RED respectively. CORE. led(CORE.RED_LED, CORE.ON); CORE. led(CORE.BLUE_LED, CORE.ON); 6.6.
Core Spartan Documentation Modern Robotics, Inc 7. Serial Communication The Spartan Controller supports serial communication on ports D0 (RX) and D1 (TX) and they are used to communicate with other devices or to the computer via USB. The code below is a method used to communicate between two Core Spartan Controllers. Please refer to https://www.arduino.cc/en/Reference/Serial for more information and examples about the Arduino Serial Library.
Core Spartan Documentation Modern Robotics, Inc 8. Three Wire Analog & Digital Sensors All three wire sensors connect to either a digital port or an analog port. Therefore, if it is a digital sensor it returns a value of either 0 or 1. If the sensor is analog it returns a value between 0 and 255. The sensors consist of a black, red and yellow wire. The black wire is the ground wire and must line up with the black bar on the right side of the port.
Core Spartan Documentation 8.1. Modern Robotics, Inc Program Control Button (45-2002) The Program Control Button (PCB) is intended for use in starting and stopping programs giving the user more control over their program. The sensor consists of a button and an LED that interact digitally with Core Spartan Controller. The PCB can be used with delayedStart() to reset and start the Core Spartan Controller, or with read() and writeLED() independent of the delayedStart() function.
Core Spartan Documentation Modern Robotics, Inc int delayedStart(void) If delayedStart() is called and the button is not connect to D2, the function returns -1, otherwise it returns 0. When the delayedStart() function is called, Core Spartan Controller will wait inside that function until the PCB is pressed. At this point the button acts as a start button and the LED will be blinking. Once the button is pushed the program will start the next line of code after the delayedStart() call.
Core Spartan Documentation 8.2. Modern Robotics, Inc Rate Gyro (45-2004) The Rate Gyro is used to detect the rate of rotation. When the Rate Gyro is completely still, the returned reading is 1.4V which produces a reading of 280° ±2°. With the sensor idle at 280° a Counter Clockwise (CCW) rotation will increase the value of the reading and then return to 280° once movement is stopped.
Core Spartan Documentation 8.3. Modern Robotics, Inc Optical Distance Sensor (45-2006) The Optical Distance Sensor (ODS) is an analog sensor that uses electro optical proximity detection to calculate distance from an object based on the intensity of the light. This sensor can accurately calculate distances between 1 cm and 15 cm. Lighter colored objects will return a more accurate and consistent reading, the material also plays a part on the returned value.
Core Spartan Documentation 8.4. Modern Robotics, Inc Touch Sensor (45-2007) The Touch Sensor can be used for an array of different tasks including object detection, counter, standard push button and many more. The sensor returns either a 0 or a 1. The Touch Sensor can be attached to either the analog or digital ports. Refer to the Touch Sensor example folder for more information on different implementation methods. http://modernroboticsinc.
Core Spartan Documentation 8.5. Modern Robotics, Inc Light Sensor (45-2015) The Light Sensor detects the ambient light level using a phototransistor. It returns a quasi-logarithmic analog value that allows the Light Sensor to be used over at least four decades of light. This means that the Light Sensor can detect small changes in light and dark environments. Refer to the Light Sensor example folder for more information on different implementation methods.
Core Spartan Documentation 8.6. Modern Robotics, Inc Magnet Sensor (45-2020) The Magnet Sensor can detect a magnetic field up to 4cm away. When the returned value is increasing, the sensor is detecting the north pole of the magnet. If the value returned is decreasing, then the sensor is detecting the south pole magnet. The sensor value ranges from -340 to +340 where 0 indicates no magnetic field. Refer to the Magnet Sensor example folder for more information on different implementation methods.
Core Spartan Documentation Modern Robotics, Inc 9. Four Wire Digital I2C Sensors All four-wire sensor are I2C sensors.I2C stands for Inter-Integrated Circuit and it is used for communication between multiple devices. Will all MR I2C sensors there are 4 wires coming from the device: Black, Red, Yellow and White. The black wire is the ground wire and must line up with the black bar on the right side of the port. The red wire is the power wire that connects to 5V for all of the sensors to operate on.
Core Spartan Documentation 9.1. Modern Robotics, Inc I2C Class The I2C class was design to make generic I2C reads and writes easier to use. I2C class makes use of the Wire library provided by Arduino. I2C Functions: CORE_I2C(int address) void request(int location, int length) unsigned char read(void) int available(void) void write(int location, unsigned char data) void write(int location, unsigned char data[], int length) CORE_I2C(int address) Save the I2C address for future reads and writes.
Core Spartan Documentation Modern Robotics, Inc int available(void) Checks to see if there is any data left in the buffers from a previous request. while(sensor.available()) value = sensor.read(); …or… if(sensor.available != 0) value = sensor.read(); void write(int location, unsigned char data) Complete a signal byte write to a selected register location. The parameter location refers to the location in which the data is to be written.
Core Spartan Documentation 9.2. Modern Robotics, Inc Compass (45-2003) The Compass uses a magnetometer and an accelerometer to calculate heading data based on Earth’s magnetic field. The compass can return the heading data, accelerometer data and magnetometer data to the user. Anything that generates a magnetic field must be moved away from the sensor like power cables, motor or magnetic material.
Core Spartan Documentation Modern Robotics, Inc void hardIronCalibration(void) Hard Iron Calibration (HIC) is a method of checking for magnets or an object generating a magnetic field around the sensor and generating an offset to account for the magnetic field. During HIC the sensor must be rotated 360° in 5 seconds while keeping a constant pace. Try to start and stop the sensor pointing due north. Refer to CalibrationHardIron example program for full calibration details. COMP.
Core Spartan Documentation Modern Robotics, Inc void tiltUp(void) This function calculates an offset to compensate for the magnetic field not being perfectly horizontal. The sensor must be held 20° above the horizon during calibration. COMP.tiltUp void tiltDown(void) This function calculates an offset to compensate for the magnetic field not being perfectly horizontal. The sensor must be held 20° below the horizon during calibration. COMP.
Core Spartan Documentation 9.3. Modern Robotics, Inc Integrating Gyro (45-2005) The Integrating Gyro uses a 3-axis chip to obtain x, y and z coordinates as well as an integration of the z-axis to provide heading data. The integrated z value is an integration of the z-axis over time and this value is used internally in heading calculations. The LED will blink at 1Hz during normal operation and will remain on during null operation (calibration).
Core Spartan Documentation Modern Robotics, Inc void setNull(void) Setting the gyro to null will enable the user to calibrate their gyro. The gyro must be kept perfectly still and flat during the null operation. During the null operation, the LED will be on and remain on until calibration is complete. It is recommended that this function be called in setup(). This function writes to the EEPROM every time it is called. Therefore set the gyro to 0 without writing to the EEPROM, use the setZero() function.
Core Spartan Documentation Modern Robotics, Inc int getAxis(char axis) This function returns the rate of rotation for a particular axis in degrees. X = X Axis Y = Y Axis Z = Z Axis int value; value = GYRO.getAxis(X); …or… Serial.print(GYRO.getAxis(Z)); void setScale(float scale_value) This function allows for scaling on the Z axis. The z axis scaling coefficient is a 16 bit value meant to scale the heading reading so that more precise measurements can be made.
Core Spartan Documentation 9.4. Modern Robotics, Inc Range Sensor (45-2008) The Range Sensor combines ultrasonic and optical distance measuring elements to obtain a reading between 1cm and 255cm. This is where the optical sensor comes in use because it can detect objects within 15cm. Refer to the Range Sensor example folder for more information on different implementation methods. . http://modernroboticsinc.
Core Spartan Documentation Modern Robotics, Inc unsigned char optical(void) This function allows the user to read the infrared reading from the Range Sensor. The infrared reading is accurate from 1cm to 15cm. int value; value = RANGE.optical(); …or… Serial.print(RANGE.optical()); Version 3.0.
Core Spartan Documentation 9.5. Modern Robotics, Inc IR Locator 360 (45-2009) The IR Locator 360 is a 360° infrared detecting sensor. There are 4 IR photo diodes that are arranged to provide an accurate reading of the IR source. The sensor provides 600Hz and 1200Hz readings that produce results at a resolution of 5°. The frequencies are channels that the IR Locator 360 uses to tell the difference between IR emitting sensors. The IR Locator 360 has a range out to 10 feet (3m).
Core Spartan Documentation Modern Robotics, Inc int getIntensity(int setting) Returns the strength of the signal to indicate how close the object is. The parameter setting refers to the frequency at which the user wants to read. The user can enter 6 or 600 for 600Hz and 12 or 1200 for 1200Hz. int value; value = locator.getIntensity(); …or… Serial.print(locator.getIntensity()); Version 3.0.
Core Spartan Documentation 9.6. Modern Robotics, Inc Sound Generator (45-2016) The Sound Generator can generate a sound based on volume, pitch and duration. This sensor also can overwrite settings during a tone to change how it sounds, change the volume, or to extend the duration of the tone. Refer to the Sound Generator example folder for more information on different implementation methods.
Core Spartan Documentation Modern Robotics, Inc void setPitch(int frequency) The pitch controls how high or low the sound of the tone will be. The sensor operates between 1Hz and 5kHz (5000Hz) and it resonates at 2kHz, so the sensor will sound its loudest at this frequency. beep.setPitch(100); beep.setPitch(2000); beep.setPitch(4500); void setDuration(int length) The duration is the length of the tone. The duration has a range of 10 ms – 2550 ms in 10 ms increments.
Core Spartan Documentation Modern Robotics, Inc void setSoundBlocking(int level, int frequency, int length, int post_pause) This function allows the user to set the volume, pitch and duration all in a single call with a blocking function feature. What makes this function different from setSound() is that this function blocks other actions while a sound is being played. Therefore while a sound is being played via this function, no other code will run.
Core Spartan Documentation 9.7. Modern Robotics, Inc IR Seeker V3 (45-2017) The IR Seeker V3 is the perfect sensor for locating and tracking an IR source. The IR Seeker V3 consists of two IR detectors to locate the IR source and calculate when it is directly in front of the sensor. It can read incoming infrared light at 600Hz and 1200Hz. The sensor has a range of 9 feet (2.75m). It is primarily intended to provide head-on resolution when locating an IR source.
Core Spartan Documentation Modern Robotics, Inc int getHeading(int frequency) This function returns the location of the IR source with respect to the front of the sensor. The heading is calculated from values read by the left and right IR detectors. When the heading returns a value of zero, the IR source is directly in front of the sensor. int value; value = seeker.getHeading(); …or… Serial.print(seeker.getHeading()); int getIntensity(int frequency) This function returns the intensity of the IR signal.
Core Spartan Documentation Modern Robotics, Inc 9.8. Color Sensor (45-2018) The Color Sensor is a sensor used to read the color of an object and return a handful of useful data using a red/green/blue reading. This data includes a color number that corresponds to the color line in the documentation, as well as raw and adjusted readings. The material of the surface being read and the ambient light in the room will affect the results.
Core Spartan Documentation Modern Robotics, Inc CORE_COLOR_SENSOR(int address) Save the I2C address for future reads and writes. This must be done before setup(). CORE_COLOR_SENSOR colour; …or… CORE_COLOR_SENSOR colour(0x1E); void colorSetup(char mode, int rate) This function sets the mode and rate at which the readings are taken. The mode can be either active or passive. In active mode, the white LED on the sensor is used to illuminate the surface that it is trying to detect.
Core Spartan Documentation Modern Robotics, Inc void whileBalance(void) This function gathers data and calculates and average value for each of the three color channels. Then the values are adjusted based on the readings from the blackBalance() function. When calibrating, hold the sensor no more than 2 inches (5cm) away from a white target. The target must be very white, using a white board or 3 layers of high quality copy paper. Calibration takes approximately 1.5 seconds. colour.
Core Spartan Documentation Modern Robotics, Inc int getColorIndex(void) This function returns a 6-bit color index in one byte. Bits 5 and 4 encode the red color index, bits 3 and 2 encode the green color index and bits 1 and 0 encode the blue color index. int value; value = colour.getColorIndex(); …or… Serial.print(colour.
Core Spartan Documentation Modern Robotics, Inc void getColorNormalized(int *red, int *green, int *blue, int *white) This function gets the analog value of the color channel adjusted by the calibration values. There is no return for this function; instead there are pointers for parameters. Therefore, the parameters will be updated by the function. colour.getColorNormalized(red, green, blue, white); Version 3.0.
Core Spartan Documentation Modern Robotics, Inc 9.9.Color Beacon (45-2019) The Color Beacon is used to display one of seven colors or any set custom color based on RGB values. The beacon can also indicate RED/BLUE team colors with the use of a magnet. Simply hold a magnet over the Hall Effect sensor on the left side of the beacon to change between RED, BLUE and normal operating mode. There is no code or setup needed to operate as a team indicator.
Core Spartan Documentation Number 0 1 2 3 4 5 6 7 Modern Robotics, Inc Color OFF RED GREEN YELLOW BLUE PURPLE TEAL WHITE CORE_COLOR_BEACON(int address) Save the I2C address for future reads and writes. This must be done before setup(). CORE_COLOR_BEACON beacon; …or… CORE_COLOR_BEACON beacon(0x42); void setColor(unsigned char value) Set the color of the LED using either the name or the number of the color. beacon.setColor(4); …or… beacon.