Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MicroMouse-2016/MicroMouse-2016.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
E119488C1D052D4B00D5794C /* AssertionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AssertionHandler.h; path = ../../micromouse/AssertionHandler.h; sourceTree = "<group>"; };
E1D9B6F61CD7CB2900F1C492 /* MicroMouse-2016 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "MicroMouse-2016"; sourceTree = BUILT_PRODUCTS_DIR; };
E1D9B7001CD7CB4800F1C492 /* Main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Main.cpp; path = ../../Main.cpp; sourceTree = "<group>"; };
E1D9B7031CD7CB7E00F1C492 /* ButtonFlag.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ButtonFlag.h; path = ../../micromouse/ButtonFlag.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -113,6 +114,7 @@
isa = PBXGroup;
children = (
E1D9B7031CD7CB7E00F1C492 /* ButtonFlag.h */,
E119488C1D052D4B00D5794C /* AssertionHandler.h */,
E1D9B7041CD7CB7E00F1C492 /* callibration_temp */,
E1D9B7051CD7CB7E00F1C492 /* Controller.cpp */,
E1D9B7061CD7CB7E00F1C492 /* Controller.h */,
Expand Down Expand Up @@ -339,6 +341,7 @@
E1D9B6FF1CD7CB2900F1C492 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
55 changes: 55 additions & 0 deletions micromouse/AssertionHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// AssertionHandler.h
// micromouse-xcode
//
// Created by Erick Sanchez on 4/20/16.
// Copyright © 2016 Erick Sanchez. All rights reserved.
//

#ifndef AssertionHandler_h
#define AssertionHandler_h

#include "Logger.h"
#include "Memory.h"
#include <assert.h>

#ifdef __MK20DX256__ // Teensy Compile

inline static void logError( int code ) {
//Read and increment to the next error state, as well as validate to loop back to 1 if incremented to 21
int intNextIndex = Micromouse::Memory::read(Micromouse::ERROR_MEMORY) +1;
intNextIndex = intNextIndex > 20 ? 1 : intNextIndex;

//Find next state address and save code as well as the most recent error state in ERROR_MEMORY
int intNextStateAddress = Micromouse::ERROR_MEMORY +intNextIndex * 4;
Micromouse::Memory::write( intNextStateAddress, code);
Micromouse::Memory::write( Micromouse::ERROR_MEMORY, intNextIndex);

}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a function here that dumps all the errors in memory to the serial port using log()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, you mean read all the codes and output them to the serial port?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't tell if i did it right :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite, look at logger.h for proper use

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about now???
plus i can't tell why i can't call to this inline method anywhere in the project :P

inline static void printErrorCodes() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it need to be inline?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, beats the hell out of me, i thought i had to, does it need to be static? i would say no huh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it can just be a regular global function

for (int error = 0; error <= 11; error += 1) {
int address = Micromouse::ERROR_MEMORY;
log(INFO) << Micromouse::Memory::read((error * 4) +address);

}

}

//Prints to concole using Logger(..) << code and metadata of the assertion
#define assertion(condition,code) \
( \
(__builtin_expect(!(condition), 0) ? (void)(logError(code)) : (void)0) \
)

#else

//Prints to concole using the definition of assert(e) declared in assert.h
#define assertion(condition,code) \
( \
(__builtin_expect(!(condition), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #condition) : (void)0) \
)

#endif

#endif /* AssertionHandler_h */
8 changes: 4 additions & 4 deletions micromouse/IRSensor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "IRSensor.h"
#include "Logger.h"
#include "RobotIO.h"
#include <assert.h>
#include "AssertionHandler.h"

#ifdef __MK20DX256__ // Teensy Compile
#include "WProgram.h"
Expand Down Expand Up @@ -33,12 +33,12 @@ namespace Micromouse {

bool IRSensor::calibrate( int calibrationStart, int calibrationInterval )
{
assert(calibrationStart >= MIN_RANGE);
assert(calibrationInterval > 0);
assertion(calibrationStart >= MIN_RANGE, 1);
assertion(calibrationInterval > 0, 2);
this->calibrationStart = calibrationStart;
this->calibrationInterval = calibrationInterval;
calibrationSize = ( MAX_RANGE - calibrationStart ) / calibrationInterval + 1;
assert(calibrationSize <= 17);
assertion(calibrationSize <= 17, 3);

delete[] calibrationData;
calibrationData = new int[calibrationSize];
Expand Down
4 changes: 2 additions & 2 deletions micromouse/Maze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <algorithm>
#include <math.h>
#include "Maze.h"
#include <assert.h>
#include "AssertionHandler.h"

namespace Micromouse
{
Expand Down Expand Up @@ -137,7 +137,7 @@ namespace Micromouse
// adds a new node to the maze at the given position
void Maze::addNode( PositionVector pos )
{
assert(isInsideMaze(pos));
assertion(isInsideMaze(pos), 4);
maze[pos.x()][pos.y()] = new Node(pos);
}

Expand Down
15 changes: 7 additions & 8 deletions micromouse/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ namespace Micromouse {
1: calibrationStart
2: calibrationInterval
3-19: CalibrationData[]
*/
const int IR_FRONT_LEFT_MEMORY = 100;//-119
const int IR_FRONT_RIGHT_MEMORY = 200;//-139
const int IR_LEFT_MEMORY = 300;//-159
const int IR_RIGHT_MEMORY = 400;//-179

*/
const int IR_FRONT_LEFT_MEMORY = 100;//to 199
const int IR_FRONT_RIGHT_MEMORY = 200;//to 299
const int IR_LEFT_MEMORY = 300;//to 399
const int IR_RIGHT_MEMORY = 400;//to 499

//180-511 unreserved

//512-2047 map
const int ERROR_MEMORY = 512; //to 599 carrying 20 error states at a time plus index slot at 512



Expand Down
4 changes: 2 additions & 2 deletions micromouse/MouseBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Author GitHub: joshuasrjc
#include "MouseBot.h"
#include "Logger.h"
#include "ButtonFlag.h"

#include "AssertionHandler.h"


namespace Micromouse
Expand Down Expand Up @@ -466,7 +466,7 @@ namespace Micromouse
void MouseBot::setSpeed( int spd )
{
speed = spd;
assert(speed > 0 && speed <= MAX_SPEED);
assertion(speed > 0 && speed <= MAX_SPEED, 5);
}


Expand Down
4 changes: 2 additions & 2 deletions micromouse/PIDController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Author GitHub: joshuasrjc
\*********************************/

#include "PIDController.h"
#include <assert.h>
#include "AssertionHandler.h"
#include "Logger.h"

#ifdef __MK20DX256__ // Teensy compile
Expand All @@ -35,7 +35,7 @@ namespace Micromouse

float PIDController::getCorrection(float currentError)
{
assert(started);
assertion(started, 8);

float deltaTime = getDeltaTime();

Expand Down
7 changes: 3 additions & 4 deletions micromouse/Path.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "Path.h"
#include <assert.h>

#include "AssertionHandler.h"



Expand All @@ -26,7 +25,7 @@ namespace Micromouse

DirectionVector Path::popStep()
{
assert( !path.empty() );
assertion(!path.empty(), 6);

DirectionVector step = path.top();
path.pop();
Expand All @@ -38,7 +37,7 @@ namespace Micromouse

DirectionVector Path::peekStep()
{
assert( !path.empty() );
assertion(!path.empty(), 7);

return path.top();
}
Expand Down
6 changes: 3 additions & 3 deletions micromouse/RobotIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "Logger.h"
#include "Timer.h"
#include "ButtonFlag.h"

#include "AssertionHandler.h"


#ifdef __MK20DX256__ // Teensy Compile
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace Micromouse
bool RobotIO::isWallinDirection( direction dir )
{
// ensure valid data
assert( dir == W || dir == N || dir == E || dir == NW || dir == NE);
assertion(dir == W || dir == N || dir == E || dir == NW || dir == NE, 9);

switch( dir )
{
Expand All @@ -95,7 +95,7 @@ namespace Micromouse
{
int dist = (int)IRSensors[FRONT_LEFT]->getDistance();

return (dist < 120 && abs(dist - IRSensors[FRONT_RIGHT]->getDistance()) < 30);
return (dist < 120 && abs(dist - IRSensors[FRONT_RIGHT]->getDistance()) < 30);
}

default:
Expand Down
10 changes: 5 additions & 5 deletions micromouse/Vector.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Vector.h"
#include <assert.h>
#include "AssertionHandler.h"

namespace Micromouse
{
Expand Down Expand Up @@ -201,9 +201,9 @@ namespace Micromouse

void DirectionVector::validateSelf()
{
assert( _dir != NONE );
assert( _mag >= 0 );

assert( _mag < NUM_NODES_W || _mag < NUM_NODES_H );
assertion(_dir != NONE, 10);
assertion(_mag >= 0, 11);
assertion(_mag < NUM_NODES_W || _mag < NUM_NODES_H, 12);
}
}
4 changes: 2 additions & 2 deletions micromouse/VirtualMaze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Author GitHub: joshuasrjc
\*********************************/

#include "VirtualMaze.h"
#include <assert.h>
#include "AssertionHandler.h"

#ifdef __MK20DX256__ // Teensy Compile
#include <Arduino.h>//random
Expand All @@ -23,7 +23,7 @@ namespace Micromouse
width(width),
height(height)
{
assert(width % 4 == 3 && height % 4 == 3);
assertion(width % 4 == 3 && height % 4 == 3, 13);
}


Expand Down