Skip to content
This repository was archived by the owner on Dec 27, 2018. It is now read-only.

Commit 4a48d05

Browse files
committed
Merge branch 'release/0.1'
2 parents 3bf072d + 13ecef8 commit 4a48d05

25 files changed

+769
-176
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ CPPOBJ:=$(patsubst %.o,$(BINDIR)/%.o,$(CPPSRC:.$(CPPEXT)=.o))
2222
OUT:=$(BINDIR)/$(OUTNAME)
2323

2424
.PHONY: all clean upload _force_look
25-
2625
# By default, compile program
2726
all: $(BINDIR) $(OUT)
2827

common.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ MCUPREPARE=$(OBJCOPY) $(OUT) -O binary $(BINDIR)/$(OUTBIN)
2121
SIZEFLAGS=
2222
# Uploads program using java
2323
UPLOAD=@java -jar firmware/uniflash.jar vex $(BINDIR)/$(OUTBIN)
24+
# Flashes program using the PROS CLI flash command
25+
FLASH=pros flash -f $(BINDIR)/$(OUTBIN)
2426

2527
# Advanced options
2628
ASMEXT=s
2729
CEXT=c
28-
CPPEXT=cpp
30+
CPPEXT=cc
2931
HEXT=h
3032
INCLUDE=-I$(ROOT)/include -I$(ROOT)/src
3133
OUTBIN=output.bin
@@ -36,7 +38,7 @@ AFLAGS:=$(MCUAFLAGS)
3638
ARFLAGS:=$(MCUCFLAGS)
3739
CCFLAGS:=-c -Wall $(MCUCFLAGS) -Os -ffunction-sections -fsigned-char -fomit-frame-pointer -fsingle-precision-constant
3840
CFLAGS:=$(CCFLAGS) -std=gnu99 -Werror=implicit-function-declaration
39-
CPPFLAGS:=$(CCFLAGS) -fno-exceptions -fno-rtti -felide-constructors
41+
CPPFLAGS:=$(CCFLAGS) -std=c++14 -fno-exceptions -fno-rtti -felide-constructors
4042
LDFLAGS:=-Wall $(MCUCFLAGS) $(MCULFLAGS) -Wl,--gc-sections
4143

4244
# Tools used in program

firmware/libpros.a

1.09 KB
Binary file not shown.

include/API.h

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,11 @@ void encoderReset(Encoder enc);
644644
*/
645645
void encoderShutdown(Encoder enc);
646646

647+
/**
648+
* This value is returned if the sensor cannot find a reasonable value to return.
649+
*/
650+
#define ULTRA_BAD_RESPONSE -1
651+
647652
/**
648653
* Reference type for an initialized ultrasonic sensor.
649654
*
@@ -654,9 +659,10 @@ typedef void * Ultrasonic;
654659
/**
655660
* Gets the current ultrasonic sensor value in centimeters.
656661
*
657-
* If no object was found, zero is returned. If the ultrasonic sensor was never started, the
658-
* return value is undefined. Round and fluffy objects can cause inaccurate values to be
659-
* returned.
662+
* If no object was found or if the ultrasonic sensor is polled while it is pinging and waiting
663+
* for a response, -1 (ULTRA_BAD_RESPONSE) is returned.
664+
* If the ultrasonic sensor was never started, the return value is undefined. Round and fluffy
665+
* objects can cause inaccurate values to be returned.
660666
*
661667
* @param ult the Ultrasonic object from ultrasonicInit() to read
662668
* @return the distance to the nearest object in centimeters
@@ -736,12 +742,23 @@ bool i2cWrite(uint8_t addr, uint8_t *data, uint16_t count);
736742
bool i2cWriteRegister(uint8_t addr, uint8_t reg, uint16_t value);
737743

738744
/**
739-
* FILE is an integer referring to a stream for the standard I/O functions.
745+
* PROS_FILE is an integer referring to a stream for the standard I/O functions.
740746
*
741-
* FILE * is the standard library method of referring to a file pointer, even though there is
747+
* PROS_FILE * is the standard library method of referring to a file pointer, even though there is
742748
* actually nothing there.
743749
*/
744-
typedef int FILE;
750+
typedef int PROS_FILE;
751+
752+
753+
#ifndef FILE
754+
/**
755+
* For convenience, FILE is defined as PROS_FILE if it wasn't already defined. This provides
756+
* backwards compatability with PROS, but also allows libraries such as newlib to be incorporated
757+
* into PROS projects. If you're not using C++/newlib, you can disregard this and just use FILE.
758+
*/
759+
#define FILE PROS_FILE
760+
#endif
761+
745762
/**
746763
* Bit mask for usartInit() for 8 data bits (typical)
747764
*/
@@ -791,7 +808,7 @@ typedef int FILE;
791808
* @param flags a bit mask combination of the SERIAL_* flags specifying parity, stop, and data
792809
* bits
793810
*/
794-
void usartInit(FILE *usart, unsigned int baud, unsigned int flags);
811+
void usartInit(PROS_FILE *usart, unsigned int baud, unsigned int flags);
795812
/**
796813
* Disables the specified USART interface.
797814
*
@@ -801,26 +818,26 @@ void usartInit(FILE *usart, unsigned int baud, unsigned int flags);
801818
*
802819
* @param usart the port to close, either "uart1" or "uart2"
803820
*/
804-
void usartShutdown(FILE *usart);
821+
void usartShutdown(PROS_FILE *usart);
805822

806823
// -------------------- Character input and output --------------------
807824

808825
/**
809826
* The standard output stream uses the PC debug terminal.
810827
*/
811-
#define stdout ((FILE *)3)
828+
#define stdout ((PROS_FILE *)3)
812829
/**
813830
* The standard input stream uses the PC debug terminal.
814831
*/
815-
#define stdin ((FILE *)3)
832+
#define stdin ((PROS_FILE *)3)
816833
/**
817834
* UART 1 on the Cortex; must be opened first using usartInit().
818835
*/
819-
#define uart1 ((FILE *)1)
836+
#define uart1 ((PROS_FILE *)1)
820837
/**
821838
* UART 2 on the Cortex; must be opened first using usartInit().
822839
*/
823-
#define uart2 ((FILE *)2)
840+
#define uart2 ((PROS_FILE *)2)
824841

825842
#ifndef EOF
826843
/**
@@ -857,7 +874,7 @@ void usartShutdown(FILE *usart);
857874
*
858875
* @param stream the file descriptor to close from fopen()
859876
*/
860-
void fclose(FILE *stream);
877+
void fclose(PROS_FILE *stream);
861878
/**
862879
* Returns the number of characters that can be read without blocking (the number of
863880
* characters available) from the specified stream. This only works for communication ports and
@@ -870,7 +887,7 @@ void fclose(FILE *stream);
870887
* @return the number of characters which meet this criterion; if this number cannot be
871888
* determined, returns 0
872889
*/
873-
int fcount(FILE *stream);
890+
int fcount(PROS_FILE *stream);
874891
/**
875892
* Delete the specified file if it exists and is not currently open.
876893
*
@@ -889,7 +906,7 @@ int fdelete(const char *file);
889906
* @param stream the channel to check (stdin, uart1, uart2, or an open file in Read mode)
890907
* @return 0 if the stream is not at EOF, or 1 otherwise.
891908
*/
892-
int feof(FILE *stream);
909+
int feof(PROS_FILE *stream);
893910
/**
894911
* Flushes the data on the specified file channel open in Write mode. This function has no
895912
* effect on a communication port or a file in Read mode, as these streams are always flushed as
@@ -901,7 +918,7 @@ int feof(FILE *stream);
901918
* @param stream the channel to flush (an open file in Write mode)
902919
* @return 0 if the data was successfully flushed, EOF otherwise
903920
*/
904-
int fflush(FILE *stream);
921+
int fflush(PROS_FILE *stream);
905922
/**
906923
* Reads and returns one character from the specified stream, blocking until complete.
907924
*
@@ -910,7 +927,7 @@ int fflush(FILE *stream);
910927
* @param stream the stream to read (stdin, uart1, uart2, or an open file in Read mode)
911928
* @return the next character from 0 to 255, or -1 if no character can be read
912929
*/
913-
int fgetc(FILE *stream);
930+
int fgetc(PROS_FILE *stream);
914931
/**
915932
* Reads a string from the specified stream, storing the characters into the memory at str.
916933
* Characters will be read until the specified limit is reached, a new line is found, or the
@@ -925,7 +942,7 @@ int fgetc(FILE *stream);
925942
* @param stream the channel to read (stdin, uart1, uart2, or an open file in Read mode)
926943
* @return str, or NULL if zero characters could be read
927944
*/
928-
char* fgets(char *str, int num, FILE *stream);
945+
char* fgets(char *str, int num, PROS_FILE *stream);
929946
/**
930947
* Opens the given file in the specified mode. The file name is truncated to eight characters.
931948
* Only four files can be in use simultaneously in any given time, with at most one of those
@@ -949,7 +966,7 @@ char* fgets(char *str, int num, FILE *stream);
949966
* @param mode the file mode
950967
* @return a file descriptor pointing to the new file, or NULL if the file could not be opened
951968
*/
952-
FILE * fopen(const char *file, const char *mode);
969+
PROS_FILE * fopen(const char *file, const char *mode);
953970
/**
954971
* Prints the simple string to the specified stream.
955972
*
@@ -959,7 +976,7 @@ FILE * fopen(const char *file, const char *mode);
959976
* @param string the string to write
960977
* @param stream the stream to write (stdout, uart1, uart2, or an open file in Write mode)
961978
*/
962-
void fprint(const char *string, FILE *stream);
979+
void fprint(const char *string, PROS_FILE *stream);
963980
/**
964981
* Writes one character to the specified stream.
965982
*
@@ -969,7 +986,7 @@ void fprint(const char *string, FILE *stream);
969986
* @param stream the stream to write (stdout, uart1, uart2, or an open file in Write mode)
970987
* @return the character written
971988
*/
972-
int fputc(int value, FILE *stream);
989+
int fputc(int value, PROS_FILE *stream);
973990
/**
974991
* Behaves the same as the "fprint" function, and appends a trailing newline ("\n").
975992
*
@@ -979,7 +996,7 @@ int fputc(int value, FILE *stream);
979996
* @param stream the stream to write (stdout, uart1, uart2, or an open file in Write mode)
980997
* @return the number of characters written, excluding the new line
981998
*/
982-
int fputs(const char *string, FILE *stream);
999+
int fputs(const char *string, PROS_FILE *stream);
9831000
/**
9841001
* Reads data from a stream into memory. Returns the number of bytes thus read.
9851002
*
@@ -991,7 +1008,7 @@ int fputs(const char *string, FILE *stream);
9911008
* @param stream the stream to read (stdout, uart1, uart2, or an open file in Read mode)
9921009
* @return the number of bytes successfully read
9931010
*/
994-
size_t fread(void *ptr, size_t size, size_t count, FILE *stream);
1011+
size_t fread(void *ptr, size_t size, size_t count, PROS_FILE *stream);
9951012
/**
9961013
* Seeks within a file open in Read mode. This function will fail when used on a file in Write
9971014
* mode or on any communications port.
@@ -1001,15 +1018,15 @@ size_t fread(void *ptr, size_t size, size_t count, FILE *stream);
10011018
* @param origin the reference location for offset: SEEK_CUR, SEEK_SET, or SEEK_END
10021019
* @return 0 if the seek was successful, or 1 otherwise
10031020
*/
1004-
int fseek(FILE *stream, long int offset, int origin);
1021+
int fseek(PROS_FILE *stream, long int offset, int origin);
10051022
/**
10061023
* Returns the current position of the stream. This function works on files in either Read or
10071024
* Write mode, but will fail on communications ports.
10081025
*
10091026
* @param stream the stream to check
10101027
* @return the offset of the stream, or -1 if the offset could not be determined
10111028
*/
1012-
long int ftell(FILE *stream);
1029+
long int ftell(PROS_FILE *stream);
10131030
/**
10141031
* Writes data from memory to a stream. Returns the number of bytes thus written.
10151032
*
@@ -1021,7 +1038,7 @@ long int ftell(FILE *stream);
10211038
* @param stream the stream to write (stdout, uart1, uart2, or an open file in Write mode)
10221039
* @return the number of bytes successfully written
10231040
*/
1024-
size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream);
1041+
size_t fwrite(const void *ptr, size_t size, size_t count, PROS_FILE *stream);
10251042
/**
10261043
* Reads and returns one character from "stdin", which is the PC debug terminal.
10271044
*
@@ -1084,7 +1101,7 @@ int puts(const char *string);
10841101
* @param formatString the format string as specified above
10851102
* @return the number of characters written
10861103
*/
1087-
int fprintf(FILE *stream, const char *formatString, ...);
1104+
int fprintf(PROS_FILE *stream, const char *formatString, ...);
10881105
/**
10891106
* Prints the formatted string to the debug stream (the PC terminal).
10901107
*
@@ -1138,7 +1155,7 @@ int sprintf(char *buffer, const char *formatString, ...);
11381155
*
11391156
* @param lcdPort the LCD to clear, either uart1 or uart2
11401157
*/
1141-
void lcdClear(FILE *lcdPort);
1158+
void lcdClear(PROS_FILE *lcdPort);
11421159
/**
11431160
* Initializes the LCD port, but does not change the text or settings.
11441161
*
@@ -1147,7 +1164,7 @@ void lcdClear(FILE *lcdPort);
11471164
*
11481165
* @param lcdPort the LCD to initialize, either uart1 or uart2
11491166
*/
1150-
void lcdInit(FILE *lcdPort);
1167+
void lcdInit(PROS_FILE *lcdPort);
11511168
/**
11521169
* Prints the formatted string to the attached LCD.
11531170
*
@@ -1160,9 +1177,9 @@ void lcdInit(FILE *lcdPort);
11601177
* @param formatString the format string as specified in fprintf()
11611178
*/
11621179
#ifdef DOXYGEN
1163-
void lcdPrint(FILE *lcdPort, unsigned char line, const char *formatString, ...);
1180+
void lcdPrint(PROS_FILE *lcdPort, unsigned char line, const char *formatString, ...);
11641181
#else
1165-
void __attribute__ ((format (printf, 3, 4))) lcdPrint(FILE *lcdPort, unsigned char line,
1182+
void __attribute__ ((format (printf, 3, 4))) lcdPrint(PROS_FILE *lcdPort, unsigned char line,
11661183
const char *formatString, ...);
11671184
#endif
11681185
/**
@@ -1174,7 +1191,7 @@ void __attribute__ ((format (printf, 3, 4))) lcdPrint(FILE *lcdPort, unsigned ch
11741191
* @param lcdPort the LCD to poll, either uart1 or uart2
11751192
* @return the buttons pressed as a bit mask
11761193
*/
1177-
unsigned int lcdReadButtons(FILE *lcdPort);
1194+
unsigned int lcdReadButtons(PROS_FILE *lcdPort);
11781195
/**
11791196
* Sets the specified LCD backlight to be on or off.
11801197
*
@@ -1183,7 +1200,7 @@ unsigned int lcdReadButtons(FILE *lcdPort);
11831200
* @param lcdPort the LCD to adjust, either uart1 or uart2
11841201
* @param backlight true to turn the backlight on, or false to turn it off
11851202
*/
1186-
void lcdSetBacklight(FILE *lcdPort, bool backlight);
1203+
void lcdSetBacklight(PROS_FILE *lcdPort, bool backlight);
11871204
/**
11881205
* Prints the string buffer to the attached LCD.
11891206
*
@@ -1195,13 +1212,13 @@ void lcdSetBacklight(FILE *lcdPort, bool backlight);
11951212
* @param line the LCD line to write, either 1 or 2
11961213
* @param buffer the string to write
11971214
*/
1198-
void lcdSetText(FILE *lcdPort, unsigned char line, const char *buffer);
1215+
void lcdSetText(PROS_FILE *lcdPort, unsigned char line, const char *buffer);
11991216
/**
12001217
* Shut down the specified LCD port.
12011218
*
12021219
* @param lcdPort the LCD to stop, either uart1 or uart2
12031220
*/
1204-
void lcdShutdown(FILE *lcdPort);
1221+
void lcdShutdown(PROS_FILE *lcdPort);
12051222

12061223
// -------------------- Real-time scheduler functions --------------------
12071224
/**
@@ -1586,6 +1603,12 @@ void waitUntil(unsigned long *previousWakeTime, const unsigned long time);
15861603
* This function should only be called once in initializeIO()
15871604
*/
15881605
void watchdogInit();
1606+
/**
1607+
* Enables the Cortex to run the op control task in a standalone mode- no VEXnet connection required.
1608+
*
1609+
* This function should only be called once in initializeIO()
1610+
*/
1611+
void standaloneModeEnable();
15891612

15901613
// End C++ extern to C
15911614
#ifdef __cplusplus

include/bangBangController.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef BANG_BANG_CONTROLLER_H_
2+
#define BANG_BANG_CONTROLLER_H_
3+
4+
class BangBangController {
5+
public:
6+
7+
BangBangController(double minOutput = -127.0, double maxOutput = 127.0, double deadband = 0.0);
8+
9+
void setSetpoint(double setpoint);
10+
11+
double calculate(double input);
12+
13+
void setContinuous(bool continuous = true);
14+
void setMinInput(double minInput);
15+
void setMaxInput(double maxInput);
16+
void setMinOutput(double minOutput);
17+
void setMaxOutput(double maxOutput);
18+
void setDeadband(double deadband);
19+
double getError();
20+
21+
private:
22+
double setpoint = 0.0;
23+
double error = 0.0;
24+
double result = 0.0;
25+
double minInput = 0.0;
26+
double maxInput = 0.0;
27+
double minOutput;
28+
double maxOutput;
29+
double deadband;
30+
bool continuous = false;
31+
32+
};
33+
34+
#endif

0 commit comments

Comments
 (0)