The skeleton code for the classes being made for the 2018 ASME SDC robots is shown below.
Table of Contents
Revisions List
Installations
Sensor Class Dependencies
The sensor class depends on the Sparkfun MAG3110 library that be found here. This library will need to be added to the libraries folder of the Arduino IDE. More information on the MAG3110 can be found here.
Back to top
This class is used to define the ASME SDC 2018 Omni-Wheeled robot used for the ASME SDC 2018 SDC (Student Design Competition).
#ifndef OMNI_ROBOT_H_
#define OMNI_ROBOT_H_
#include "Sensor.h"
public:
Sensor compass();
Sensor current();
Sensor ir_ball();
Sensor ir_capture();
void encoderModel() {
}
void controllerInputModel() {
}
void robotModel() {
}
};
#endif
Back to top
This class is used for motors that have an encoder that works with the Encoder class and has an optional current sensor.
#ifndef MOTOR_H_
#define MOTOR_H_
#include "Encoder.h"
#include "Sensor.h"
#define MOTOR_TYPE_DC 1
#define MOTOR_TYPE_BLDC 2
#define MOTOR_TYPE_SERVO 3
int duty_cycle;
};
int PIN_PWM;
int PIN_A;
int PIN_B;
};
public:
void setupMotor();
double getCurrentUsage();
double getMotorPosition();
protected:
static int TOTAL_MOTORS;
private:
Encoder encoder;
Sensor current;
};
#endif
Back to top
Encoder Class
This is a generalized class for an encoder.
#ifndef ENCODER_H_
#define ENCODER_H_
#define ENCODER_TYPE_INCREMENTAL 1
#define ENCODER_TYPE_QUADRATURE 2
#define ENCODER_TYPE_ABSOLUTE 3
#define MOTOR_DIR_CW 0
#define MOTOR_DIR_CCW 1
struct EncoderState {
volatile long int timestamp;
volatile long int position;
volatile bool direction;
};
struct EnoderPins {
int PIN_A;
int PIN_B;
};
class Encoder {
public:
void setupEncoder();
protected:
EncoderState state;
EncoderPins pins;
private:
void encoderInterrupt();
};
#endif
Back to top
Sensor Class
This is a generalized sensor class for the current, IR TOF (time-of-flight), and compass sensors.
#ifndef SENSOR_H_
#define SENSOR_H_
#define SENSOR_TYPE_CURRENT 1
#define SENSOR_TYPE_IR_DIGITAL 2
#define SENSOR_TYPE_COMPASS 3
#define SENSOR_COMM_TYPE_DIGITAL 1
#define SENSOR_COMM_TYPE_PULSE 2 // PWM or PPM
#define SENSOR_COMM_TYPE_I2C 3
struct SensorState {
volatile long int timestamp;
volatile double data;
};
struct SensorPins {
int PIN_DATA;
int PIN_CLOCK;
int PIN_INTERRUPT;
};
class Sensor {
public:
void setupDataInterrupt();
protected:
SensorState state;
SensorPins pins;
static int TOTAL_SENSORS;
int COMM_TYPE;
int DATA_SCALAR;
bool INTERRUPTABLE;
};
#endif
Back to top
6 Channel RC Controller Class
This class is used to take the stick inputs from an RC controller through a 6CH receiver.
#ifndef RC_CONTROLLER_6CH_H_
#define RC_CONTROLLER_6CH_H_
#define DEFAULT_CH_VALUE_MIN 1000 // min PPM signal in microseconds
#define DEFAULT_CH_VALUE_MAX 2000 // max PPM signal in microseconds
#define CH_MAP_TYPE_BINARY 1 // maps channel values to 0 to 1
#define CH_MAP_TYPE_UNIDIRECTIONAL 2 // maps channel values to 0 to 100
#define CH_MAP_TYPE_BIDIRECTIONAL 3 // maps channel values to -100 to 100
};
int PIN_CH_2;
int PIN_CH_3;
int PIN_CH_4;
int PIN_CH_5;
int PIN_CH_6;
int *PINS[] = {&
PIN_CH_1, &PIN_CH_2, &PIN_CH_3, &PIN_CH_4, &PIN_CH_5, &PIN_CH_6};
};
public:
void setupChannel(int channel, int map_type, int threshold);
void setupChannel(int channel, int map_type, int min_value, int max_value);
protected:
int CH_UPDATE_HZ;
private:
void runControllerInputModel();
void setupControllerInputTimerInterupt();
void setupChannelInterrupts();
};
#endif
Back to top
This class is used to determine the various states and error that the robot class can run into and what color sequence to show on the LED strip during these events in order to indicate this information to the user.
NOTE: **_Still needs to be defined_**
#ifndef LED_H_
#define LED_H_
};
#endif
Back to top