Initial commit.

This commit is contained in:
jacobperron 2015-12-11 14:08:34 -08:00
commit 43c7b95361
14 changed files with 1919 additions and 0 deletions

353
include/create/create.h Normal file
View file

@ -0,0 +1,353 @@
/**
Software License Agreement (BSD)
\file create.h
\authors Jacob Perron <jperron@sfu.ca>
\copyright Copyright (c) 2015, Autonomy Lab (Simon Fraser University), All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Autonomy Lab nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CREATE_H
#define CREATE_H
#include <boost/shared_ptr.hpp>
#include <string>
#include <sys/time.h>
#include <unistd.h>
#include "create/serial.h"
#include "create/data.h"
#include "create/types.h"
namespace create {
class Create {
private:
enum CreateLED {
LED_DEBRIS = 1,
LED_SPOT = 2,
LED_DOCK = 4,
LED_CHECK = 8
};
uint8_t mainMotorPower;
uint8_t sideMotorPower;
uint8_t vacuumMotorPower;
// LEDs
uint8_t debrisLED;
uint8_t spotLED;
uint8_t dockLED;
uint8_t checkLED;
uint8_t powerLED;
uint8_t powerLEDIntensity;
create::Pose pose;
uint32_t prevTicksLeft;
uint32_t prevTicksRight;
float prevLeftVel;
float prevRightVel;
bool firstOnData;
void init();
bool updateLEDs();
void onData();
protected:
boost::shared_ptr<create::Data> data;
boost::shared_ptr<create::Serial> serial;
public:
/* Default constructor.
* Does not attempt to establish serial connection to Create.
*/
Create();
/* Attempts to establish serial connection to Create.
*/
Create(const std::string& port, const int& baud);
~Create();
/* Make a serial connection to Create.
* This is the first thing that should be done after instantiated this class.
* \return true if a successful connection is established, false otherwise.
*/
bool connect(const std::string& port, const int& baud);
inline bool connected() const { return serial->connected(); };
/* Disconnect from serial.
*/
void disconnect();
/* Resets as if you have removed the battery.
* Changes mode to MODE_PASSIVE.
*/
//void reset();
//void setBaud(int baudcode);
/* Change Create mode.
*/
bool setMode(const create::CreateMode& mode);
/* Starts a cleaning mode.
* Changes mode to MODE_PASSIVE.
*/
bool clean(const create::CleanMode& mode = CLEAN_DEFAULT);
/* Starts the docking behaviour.
* Changes mode to MODE_PASSIVE.
*/
bool dock() const;
/* Sets the internal clock of Create.
* \param day in range [0, 6]
* \param hour in range [0, 23]
* \param min in range [0, 59]
*/
bool setDate(const create::DayOfWeek& day, const uint8_t& hour, const uint8_t& min) const;
/* Set the average wheel velocity and turning radius of Create.
* \param vel is in m/s
* \param radius in meters.
*/
//void driveRadius(const float& vel, const float& radius) const;
/* Set the velocities for the left and right wheels (m/s).
*/
bool driveWheels(const float& leftWheel, const float& rightWheel) const;
/* Set the PWM for each wheel.
*/
//void drivePWM(const int16_t& leftWheel, const int16_t& rightWheel) const;
/* Set the forward and angular velocity of Create.
* \param xVel in m/s
* \param angularVel in rads/s
*/
bool drive(const float& xVel, const float& angularVel) const;
/* Set the power to the side brush motor.
* \param power is in the range [-1, 1]
*/
bool setSideMotor(const float& power);
/* Set the power to the main brush motor.
* \param power is in the range [-1, 1]
*/
bool setMainMotor(const float& power);
/* Set the power to the vacuum motor.
* \param power is in the range [0, 1]
*/
bool setVacuumMotor(const float& power);
/* Set the power of all motors.
* \param mainPower in the range [-1, 1]
* \param sidePower in the range [-1, 1]
* \param vacuumPower in the range [0, 1]
*/
bool setAllMotors(const float& mainPower, const float& sidePower, const float& vacuumPower);
/* Set the blue "debris" LED on/off.
*/
bool enableDebrisLED(const bool& enable);
/* Set the green "spot" LED on/off.
*/
bool enableSpotLED(const bool& enable);
/* Set the green "dock" LED on/off.
*/
bool enableDockLED(const bool& enable);
/* Set the orange "check Create" LED on/off.
*/
bool enableCheckRobotLED(const bool& enable);
/* Set the center power LED.
* \param power in range [0, 255] where 0 = green and 255 = red
* \param intensity in range [0, 255]
*/
bool setPowerLED(const uint8_t& power, const uint8_t& intensity = 255);
// TODO
//void setScheduleLED(...);
/* Set the four 7-segment display digits from left to right.
*/
// TODO
//void setDigits(uint8_t digit1, uint8_t digit2,
// uint8_t digit3, uint8_t digit4);
// pushButton(...);
/* Set the four 7-segment display digits from left to right with ASCII codes.
* Any code out side the accepted ascii ranges results in blank display.
* \param digit1 is left most digit with ascii range [32, 126]
* \param digit2 is second to left digit with ascii range [32, 126]
* \param digit3 is second to right digit with ascii range [32, 126]
* \param digit4 is right most digit with ascii range [32, 126]
*/
bool setDigitsASCII(const uint8_t& digit1, const uint8_t& digit2,
const uint8_t& digit3, const uint8_t& digit4) const;
/* Defines a song from the provided notes and labels it with a song number.
* \param songNumber can be one of four possible song slots, [0, 4]
* \param songLength is the number of notes, maximum 16.
* length(notes) = length(durations) = songLength should be true.
* \param notes is a sequence of notes. Each note is in the range [31, 127].
* Anything outside this range is considered a rest note.
* \param durations for each note in fractions of a second from the range [0, 4)
*/
bool defineSong(const uint8_t& songNumber,
const uint8_t& songLength,
const uint8_t* notes,
const float* durations) const;
/* Play a previously created song.
* This command will not work if a song was not already defined with the specified song number.
*/
bool playSong(const uint8_t& songNumber) const;
//void registerCallback(...);
/* True if a left or right wheeldrop is detected.
*/
bool isWheeldrop() const;
/* Returns true if left bumper is pressed, false otherwise.
*/
bool isLeftBumper() const;
/* Returns true if right bumper is pressed, false otherwise.
*/
bool isRightBumper() const;
/* True if wall is seen to right of Create, false otherwise.
*/
bool isWall() const;
/* True if there are any cliff detections, false otherwise.
*/
bool isCliff() const;
//TODO
//bool isVirtualWall() const;
//TODO
//bool isWheelOvercurrent() const;
/* Get level of the dirt detect sensor.
* \return value in range [0, 255]
*/
uint8_t getDirtDetect() const;
/* Get value of 8-bit IR character currently being received by omnidirectional sensor.
* \return value in range [0, 255]
*/
uint8_t getIROmni() const;
/* Get value of 8-bit IR character currently being received by left sensor.
* \return value in range [0, 255]
*/
uint8_t getIRLeft() const;
/* Get value of 8-bit IR character currently being received by right sensor.
* \return value in range [0, 255]
*/
uint8_t getIRRight() const;
bool isCleanButtonPressed() const;
bool isClockButtonPressed() const;
bool isScheduleButtonPressed() const;
bool isDayButtonPressed() const;
bool isHourButtonPressed() const;
bool isMinButtonPressed() const;
bool isDockButtonPressed() const;
bool isSpotButtonPressed() const;
/* Get battery voltage.
* \return value in millivolts
*/
uint16_t getVoltage() const;
/* Get current flowing in/out of battery.
* \return value in milliamps
*/
uint16_t getCurrent() const;
/* Get the temperature of battery.
* \return value in Celsius
*/
uint8_t getTemperature() const;
/* Get battery's remaining charge.
* \return value in milliamp-hours
*/
uint16_t getBatteryCharge() const;
/* Get estimated battery charge capacity.
* \return in milliamp-hours
*/
uint16_t getBatteryCapacity() const;
bool isIRDetectLeft() const;
bool isIRDetectFrontLeft() const;
bool isIRDetectCenterLeft() const;
bool isIRDetectRight() const;
bool isIRDetectFrontRight() const;
bool isIRDetectCenterRight() const;
uint16_t getDistLeft() const;
uint16_t getDistFrontLeft() const;
uint16_t getDistCenterLeft() const;
uint16_t getDistRight() const;
uint16_t getDistFrontRight() const;
uint16_t getDistCenterRight() const;
/* Return true if Create is moving forward.
*/
bool isMovingForward() const;
/* Get the current charging state.
*/
create::ChargingState getChargingState() const;
/* Get the current mode reported by Create.
*/
create::CreateMode getMode() const;
/* Get the estimated position of Create based on it's wheel encoders.
*/
const create::Pose& getPose() const;
}; // end Create class
} // namespace create
#endif // CREATE_DRIVER_H

63
include/create/data.h Normal file
View file

@ -0,0 +1,63 @@
/**
Software License Agreement (BSD)
\file data.h
\authors Jacob Perron <jperron@sfu.ca>
\copyright Copyright (c) 2015, Autonomy Lab (Simon Fraser University), All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Autonomy Lab nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CREATE_DATA_H
#define CREATE_DATA_H
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <map>
#include <vector>
#include "create/packet.h"
#include "create/types.h"
namespace create {
class Data {
private:
std::map<uint8_t, boost::shared_ptr<Packet> > packets;
uint32_t totalDataBytes;
std::vector<uint8_t> ids;
public:
Data();
~Data();
bool isValidPacketID(const uint8_t id) const;
boost::shared_ptr<Packet> getPacket(const uint8_t id);
void validateAll();
uint32_t getTotalDataBytes() const;
uint8_t getNumPackets() const;
std::vector<uint8_t> getPacketIDs();
};
} // namespace create
#endif // CREATE_DATA_H

61
include/create/packet.h Normal file
View file

@ -0,0 +1,61 @@
/**
Software License Agreement (BSD)
\file packet.h
\authors Jacob Perron <jperron@sfu.ca>
\copyright Copyright (c) 2015, Autonomy Lab (Simon Fraser University), All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Autonomy Lab nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CREATE_PACKET_H
#define CREATE_PACKET_H
#include <boost/thread/mutex.hpp>
namespace create {
class Packet {
private:
uint16_t data;
uint16_t tmpData;
mutable boost::mutex dataMutex;
public:
// TODO: Do they really need to be const? then they better be static
// I am actually not sure if const member vars are valid
const uint8_t nbytes;
const std::string info;
Packet(const uint8_t& nbytes, const std::string& info);
~Packet();
void setTempData(const uint16_t& td);
void validate();
// thread safe
void setData(const uint16_t& d);
// thread safe
uint16_t getData() const;
};
} // namepsace create
#endif // CREATE_PACKET_H

106
include/create/serial.h Normal file
View file

@ -0,0 +1,106 @@
/**
Software License Agreement (BSD)
\file serial.h
\authors Jacob Perron <jperron@sfu.ca>
\copyright Copyright (c) 2015, Autonomy Lab (Simon Fraser University), All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Autonomy Lab nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
// Based on example from:
// https://github.com/labust/labust-ros-pkg/wiki/Create-a-Serial-Port-application
#ifndef CREATE_SERIAL_H
#define CREATE_SERIAL_H
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include "create/data.h"
#include "create/types.h"
#include "create/util.h"
namespace create {
class Serial {
private:
enum ReadState {
READ_HEADER,
READ_NBYTES,
READ_PACKET_ID,
READ_PACKET_BYTES,
READ_CHECKSUM
};
boost::shared_ptr<Data> data;
boost::asio::io_service io;
boost::asio::serial_port port;
boost::thread ioThread;
boost::condition_variable dataReadyCond;
boost::mutex dataReadyMut;
ReadState readState;
bool dataReady;
bool isReading;
bool firstRead;
// These are just for diagnostics, maybe not necessary
// TODO: Investigate
uint64_t corruptPackets;
uint64_t totalPackets;
// State machine variables
uint8_t headerByte;
uint8_t packetID;
uint8_t expectedNumBytes;
uint8_t byteRead;
uint16_t packetBytes;
uint8_t numBytesRead;
uint32_t byteSum;
uint8_t numDataBytesRead;
uint8_t expectedNumDataBytes;
// Callback executed when data arrives from Create
// TODO: Should size be const?
// Not sure, this was from example
void onData(const boost::system::error_code& e, const std::size_t& size);
// Callback to execute once data arrives
boost::function<void()> callback;
// Start and stop reading data from Create
bool startReading();
void stopReading();
public:
Serial(boost::shared_ptr<Data> data, const uint8_t& header = create::util::CREATE_2_HEADER);
~Serial();
bool connect(const std::string& port, const int& baud = 115200, boost::function<void()> cb = 0);
void disconnect();
inline bool connected() const { return port.is_open(); };
bool send(const uint8_t* bytes, const uint32_t numBytes);
bool sendOpcode(const Opcode& code);
};
} // namespace create
#endif // CREATE_SERIAL_H

190
include/create/types.h Normal file
View file

@ -0,0 +1,190 @@
/**
Software License Agreement (BSD)
\file types.h
\authors Jacob Perron <jperron@sfu.ca>
\copyright Copyright (c) 2015, Autonomy Lab (Simon Fraser University), All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Autonomy Lab nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CREATE_TYPES_H
#define CREATE_TYPES_H
namespace create {
enum SensorPacketID {
ID_GROUP_0 = 0,
ID_GROUP_1 = 1,
ID_GROUP_2 = 2,
ID_GROUP_3 = 3,
ID_GROUP_4 = 4,
ID_GROUP_5 = 5,
ID_GROUP_6 = 6,
ID_GROUP_100 = 100,
ID_GROUP_101 = 101,
ID_GROUP_106 = 106,
ID_GROUP_107 = 107,
ID_BUMP_WHEELDROP = 7,
ID_WALL = 8,
ID_CLIFF_LEFT = 9,
ID_CLIFF_FRONT_LEFT = 10,
ID_CLIFF_FRONT_RIGHT = 11,
ID_CLIFF_RIGHT = 12,
ID_VIRTUAL_WALL = 13,
ID_OVERCURRENTS = 14,
ID_DIRT_DETECT = 15,
ID_UNUSED_1 = 16,
ID_IR_OMNI = 17,
ID_IR_LEFT = 52,
ID_IR_RIGHT = 53,
ID_BUTTONS = 18,
ID_DISTANCE = 19,
ID_ANGLE = 20,
ID_CHARGE_STATE = 21,
ID_VOLTAGE = 22,
ID_CURRENT = 23,
ID_TEMP = 24,
ID_CHARGE = 25,
ID_CAPACITY = 26,
ID_WALL_SIGNAL = 27,
ID_CLIFF_LEFT_SIGNAL = 28,
ID_CLIFF_FRONT_LEFT_SIGNAL = 29,
ID_CLIFF_FRONT_RIGHT_SIGNAL = 30,
ID_CLIFF_RIGHT_SIGNAL = 31,
ID_UNUSED_2 = 32,
ID_UNUSED_3 = 33,
ID_CHARGE_SOURCE = 34,
ID_IO_MODE = 35,
ID_SONG_NUM = 36,
ID_PLAYING = 37,
ID_NUM_STREAM_PACKETS = 38,
ID_VEL = 39,
ID_RADIUS = 40,
ID_RIGHT_VEL = 41,
ID_LEFT_VEL = 42,
ID_LEFT_ENC = 43,
ID_RIGHT_ENC = 44,
ID_LIGHT = 45,
ID_LIGHT_LEFT = 46,
ID_LIGHT_FRONT_LEFT = 47,
ID_LIGHT_CENTER_LEFT = 48,
ID_LIGHT_CENTER_RIGHT = 49,
ID_LIGHT_FRONT_RIGHT = 50,
ID_LIGHT_RIGHT = 51,
ID_LEFT_MOTOR_CURRENT = 54,
ID_RIGHT_MOTOR_CURRENT = 55,
ID_MAIN_BRUSH_CURRENT = 56,
ID_SIDE_BRUSH_CURRENT = 57,
ID_STASIS = 58,
ID_NUM = 52
};
enum Opcode {
OC_START = 128,
OC_RESET = 7,
OC_STOP = 173,
OC_BAUD = 129,
OC_SAFE = 131,
OC_FULL = 132,
OC_CLEAN = 135,
OC_MAX = 136,
OC_SPOT = 134,
OC_DOCK = 143,
OC_POWER = 133,
OC_SCHEDULE = 167,
OC_DATE = 168,
OC_DRIVE = 137,
OC_DRIVE_DIRECT = 145,
OC_DRIVE_PWM = 146,
OC_MOTORS = 138,
OC_MOTORS_PWM = 144,
OC_LEDS = 139,
OC_SCHEDULING_LEDS = 162,
OC_DIGIT_LEDS_RAW = 163,
OC_BUTTONS = 165,
OC_DIGIT_LEDS_ASCII = 164,
OC_SONG = 140,
OC_PLAY = 141,
OC_SENSORS= 142,
OC_QUERY_LIST=149,
OC_STREAM = 148,
OC_TOGGLE_STREAM = 150,
};
enum BAUDCODE {
BAUD_300 = 0,
BAUD_600 = 1,
BAUD_1200 = 2,
BAUD_2400 = 3,
BAUD_4800 = 4,
BAUD_9600 = 5,
BAUD_14400 = 6,
BAUD_19200 = 7,
BAUD_28800 = 8,
BAUD_38400 = 9,
BAUD_57600 = 10,
BAUD_115200 = 11
};
enum CreateMode {
MODE_OFF = OC_POWER,
MODE_PASSIVE = OC_START,
MODE_SAFE = OC_SAFE,
MODE_FULL = OC_FULL
};
enum CleanMode {
CLEAN_DEFAULT = OC_CLEAN,
CLEAN_MAX = OC_MAX,
CLEAN_SPOT = OC_SPOT
};
enum ChargingState {
CHARGE_NONE = 0,
CHARGE_RECONDITION = 1,
CHARGE_FULL = 2,
CHARGE_TRICKLE = 3,
CHARGE_WAITING = 4,
CHARGE_FAULT = 5
};
enum DayOfWeek {
SUN = 0,
MON = 1,
TUE = 2,
WED = 3,
THU = 4,
FRI = 5,
SAT = 6
};
struct Pose {
float x;
float y;
float yaw;
};
} // namespace create
#endif // CREATE_TYPES_H

61
include/create/util.h Normal file
View file

@ -0,0 +1,61 @@
/**
Software License Agreement (BSD)
\file util.h
\authors Jacob Perron <jperron@sfu.ca>
\copyright Copyright (c) 2015, Autonomy Lab (Simon Fraser University), All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Autonomy Lab nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CREATE_UTIL_H
#define CREATE_UTIL_H
#define COUT(prefix,msg) (std::cout<<prefix<<msg<<std::endl)
#define CERR(prefix,msg) (std::cerr<<prefix<<msg<<std::endl)
namespace create {
namespace util {
static const uint8_t CREATE_2_HEADER = 19;
static const float CREATE_2_AXLE_LENGTH = 0.235;
static const float CREATE_2_TICKS_PER_REV = 508.8;
static const uint32_t CREATE_2_MAX_ENCODER_TICKS = 65535;
static const float CREATE_2_WHEEL_DIAMETER = 0.078;
static const float CREATE_2_MAX_VEL = 0.5;
static const float PI = 3.14159;
static const float TWO_PI = 6.28318;
static const float EPS = 0.001;
inline float normalizeAngle(const float& angle) {
float a = angle;
while (a < -PI) a += TWO_PI;
while (a > PI) a -= TWO_PI;
return a;
};
} // namespace util
} // namespace create
#endif // CREATE_UTIL_H