Skip to content
Browse files

ART6 controller "working" although could be better...

  • Loading branch information...
1 parent 35725da commit 4bb1013730fded72c6d9857363b2be5ac34ad4d8 Ricky Ng-Adam committed Apr 4, 2011
View
BIN ART5/NetUSBTest/Debug/NetUSBTest.ilk
Binary file not shown.
View
BIN ART5/NetUSBTest/NetUSBTest/Debug/BuildLog.htm
Binary file not shown.
View
18 ART5/NetUSBTest/NetUSBTest/NetUSBTest.cpp
@@ -33,7 +33,11 @@ void EnableLed2() {
}
static void __stdcall callback(unsigned char* buff, size_t n) {
- printf("Got a callback!");
+ printf("Got a callback!\n");
+ for(int i=0;i<n;i++) {
+ printf("%d.", buff[i]);
+ }
+ printf("\n");
}
BOOL WINAPI ConsoleHandler(
@@ -68,17 +72,22 @@ int main(int argc, _TCHAR* argv[])
printf("Successfully opened device!\n");
EnableLed2();
//NetusbRegisterNotification(HWND handle);
+ printf("Starting listening...");
NetusbSetCallback(callback);
+ NetusbSetFrequence(4487-4224);
NetusbStartListen();
}
} else {
printf("no!");
}
- BYTE buf[1];
+ BYTE buf[255];
+ BYTE returned = 0;
BYTE result;
int i = 0;
+ buf[0] = 99;
while(running) {
+ /*
i++;
if(i>255) {
i = 0;
@@ -89,6 +98,11 @@ int main(int argc, _TCHAR* argv[])
if(result != 0) {
printf("Error %d", result);
}
+ */
+ NetusbGetData(buf, &returned);
+ if(returned) {
+ printf("received %d", buf[1]);
+ }
Sleep(100);
}
//NetusbUnregisterNotification();
View
10 ART5/NetUSBTest/NetUSBTest/NetUSBTest.vcproj
@@ -205,7 +205,7 @@
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
- RelativePath="..\netusb.h"
+ RelativePath=".\netusb.h"
>
</File>
<File
@@ -224,6 +224,14 @@
>
</Filter>
<File
+ RelativePath=".\Netusb.dll"
+ >
+ </File>
+ <File
+ RelativePath=".\NetusbD.dll"
+ >
+ </File>
+ <File
RelativePath=".\ReadMe.txt"
>
</File>
View
BIN ART5/NetUSBTest/NetUSBTest1.ncb
Binary file not shown.
View
BIN ART5/NetUSBTest/NetUSBTest1.suo
Binary file not shown.
View
73 ART6/Controller/Controller.pde
@@ -140,14 +140,18 @@ pin_t RIGHT_PIN = 5;
*****************************************************************************/
enum sensor_position {
SENSOR_LEFT,
- SENSOR_FRONT,
+ SENSOR_FRONT, // unused
SENSOR_RIGHT,
SENSOR_LEFT_SIDE,
SENSOR_RIGHT_SIDE,
- SENSOR_BACK,
+ SENSOR_BACK_LEFT, // unused
+ SENSOR_BACK,
+ SENSOR_BACK_RIGHT, // unused
NUMBER_READINGS,
};
+boolean sensor_readings[NUMBER_READINGS];
+pin_t sensor_to_pin[] = { INFRARED_LEFT, 0, INFRARED_RIGHT, INFRARED_LEFT_SIDE, INFRARED_RIGHT_SIDE, 0, INFRARED_BACK, 0};
/*****************************************************************************
* RC CAR RELATED
*****************************************************************************/
@@ -168,7 +172,7 @@ bitmask8_t current_command = 0;
/*
Makes sure that exclusive directions are prohibited
*/
-void _go(enum_t dir) {
+void go(enum_t dir) {
switch(dir) {
case FORWARD:
digitalWrite(REVERSE_PIN, LOW);
@@ -192,7 +196,7 @@ void _go(enum_t dir) {
}
}
-void _suspend(enum_t dir) {
+void suspend(enum_t dir) {
switch(dir) {
case FORWARD:
digitalWrite(FORWARD_PIN, LOW);
@@ -219,7 +223,7 @@ example:
if current_command is 1010 (or similar), then skip
otherwise (1000), execute and set current_command = 1000 | 0010 = 1010
*/
-void go(enum_t dir) {
+void _go(enum_t dir) {
bitmask8_t dir_bitmask = 1 << dir;
if(!(current_command & dir_bitmask)) {
_go(dir);
@@ -228,7 +232,7 @@ void go(enum_t dir) {
}
}
-void suspend(enum_t dir) {
+void _suspend(enum_t dir) {
bitmask8_t dir_bitmask = 1 << dir;
if(current_command & dir_bitmask) {
_suspend(dir);
@@ -267,9 +271,6 @@ enum states {
SMALL_TURN_CW,
};
-enum_t current_state = STOP;
-enum_t previous_state = FORWARD_UNIT;
-
/*****************************************************************************
* SETUP
*****************************************************************************/
@@ -295,38 +296,41 @@ void setup() {
Serial.println(millis());
}
-boolean no_obstacle(pin_t pin) {
- int value = analogRead(pin);
- boolean no_obstacle = value > 500;
- //LOG_TELEMETRY(INFRARED_SENSORS, pin, value);
- return no_obstacle;
+
+boolean no_obstacle(enum_t sensor) {
+ boolean value = analogRead(sensor_to_pin[sensor]) > 500;
+ if(sensor_readings[sensor] != value) {
+ sensor_readings[sensor] = value;
+ LOG_TELEMETRY(INFRARED_SENSORS, sensor, value);
+ }
+ return sensor_readings[sensor];
}
/*****************************************************************************
* MAIN STATE MACHINE LOOP
*****************************************************************************/
+boolean left, right, back, left_side, right_side;
+enum_t initial_state;
+enum_t dir;
+enum_t current_state = STOP;
+
void loop(){
- enum_t initial_state = current_state;
+ initial_state = current_state;
- // SENSOR READINGS
- boolean left = no_obstacle(INFRARED_LEFT);
- boolean right = no_obstacle(INFRARED_RIGHT);
- boolean left_side = no_obstacle(INFRARED_LEFT_SIDE);
- boolean right_side = no_obstacle(INFRARED_RIGHT_SIDE);
- boolean back = no_obstacle(INFRARED_BACK);
-
// DECISION LOGIC
+ left = no_obstacle(SENSOR_LEFT);
+ right = no_obstacle(SENSOR_RIGHT);
if(left && right) {
current_state = FORWARD_UNIT;
} else if(left && !right) {
current_state = FORWARD_LEFT_UNIT;
} else if(!left && right) {
current_state = FORWARD_RIGHT_UNIT;
- } else if(!left && !right) {
- if(back) {
- if(left_side) {
+ } else {
+ if((back = no_obstacle(SENSOR_BACK))) {
+ if((left_side = no_obstacle(SENSOR_LEFT_SIDE))) {
current_state = REVERSE_LEFT_UNIT;
- } else if(right_side) {
+ } else if((right_side = no_obstacle(SENSOR_RIGHT_SIDE))) {
current_state = REVERSE_RIGHT_UNIT;
} else {
current_state = REVERSE_UNIT;
@@ -342,8 +346,6 @@ void loop(){
return;
}
- full_stop();
-
// ACTUATORS CONTROL
switch(current_state) {
case FORWARD_LEFT_UNIT:
@@ -360,29 +362,34 @@ void loop(){
break;
case REVERSE_UNIT:
case FORWARD_UNIT:
- // do nothing, we will decide below what to do
+ suspend(RIGHT);
+ suspend(LEFT);
+ break;
+ case STUCK:
+ full_stop();
break;
default:
LOG_BAD_STATE(current_state);
break;
}
- int dir;
switch(current_state) {
case FORWARD_LEFT_UNIT:
case FORWARD_RIGHT_UNIT:
case FORWARD_UNIT:
- dir = FORWARD;
+ go(FORWARD);
break;
case REVERSE_LEFT_UNIT:
case REVERSE_RIGHT_UNIT:
case REVERSE_UNIT:
- dir = REVERSE;
+ go(REVERSE);
+ break;
+ case STUCK:
+ // we've already stopped
break;
default:
LOG_BAD_STATE(current_state);
break;
}
- go(dir);
LOG_TELEMETRY(STATE_CHANGE, initial_state, current_state);
View
49 ART_Control4/ART_Control4.pde
@@ -142,10 +142,6 @@ pin_t RIGHT_PIN = 9;
pin_t PUSHBUTTON_PIN = 10;
// servo
pin_t SENSOR_SERVO_PIN = 12;
-// analog adjustments
-pin_t FORWARD_POT_PIN = A5;
-pin_t REVERSE_POT_PIN = A4;
-// buttons
/*****************************************************************************
* TIMING RELATED
@@ -461,22 +457,22 @@ void full_stop() {
*****************************************************************************/
enum states {
// start state
- INITIAL = 'I',
- FULL_SWEEP = 'Q',
+ INITIAL,
+ FULL_SWEEP,
// units advancement
- FORWARD_LEFT_UNIT = '1',
- FORWARD_UNIT = '2',
- FORWARD_RIGHT_UNIT = '3',
- REVERSE_LEFT_UNIT = '4',
- REVERSE_UNIT = '5',
- REVERSE_RIGHT_UNIT = '6',
+ FORWARD_LEFT_UNIT,
+ FORWARD_UNIT,
+ FORWARD_RIGHT_UNIT,
+ REVERSE_LEFT_UNIT,
+ REVERSE_UNIT,
+ REVERSE_RIGHT_UNIT,
// decision making
- STANDSTILL_DECISION = '?',
+ STANDSTILL_DECISION,
// end state
- STUCK = 'K',
- STOP = '.',
- SMALL_TURN_CCW = '<',
- SMALL_TURN_CW = '>',
+ STUCK,
+ STOP,
+ SMALL_TURN_CCW,
+ SMALL_TURN_CW,
};
enum_t current_state = STOP;
@@ -497,9 +493,7 @@ void setup() {
pinMode(REVERSE_PIN, OUTPUT);
pinMode(LEFT_PIN, OUTPUT);
pinMode(RIGHT_PIN, OUTPUT);
- // input potentiometer
- pinMode(FORWARD_POT_PIN, INPUT);
- pinMode(REVERSE_POT_PIN, INPUT);
+
//buttons
pinMode(PUSHBUTTON_PIN, INPUT);
@@ -522,16 +516,11 @@ void setup() {
* DECISION HELPERS
*****************************************************************************/
duration_ms_t get_forward_time_millis() {
- duration_ms_t max_time = map(analogRead(FORWARD_POT_PIN), 0, 1024, MIN_TIME_UNIT_MILLIS, MAX_TIME_UNIT_MILLIS);
- duration_ms_t time = map(current_max_distance_cm(), 0, SENSOR_MAX_RANGE_CM, MIN_TIME_UNIT_MILLIS, max_time);
- return time;
+ 1000;
}
duration_ms_t get_backward_time_millis() {
- // same logic because we don't have a front sensor...
- duration_ms_t max_time = map(analogRead(REVERSE_POT_PIN), 0, 1024, MIN_TIME_UNIT_MILLIS, MAX_TIME_UNIT_MILLIS);
- duration_ms_t time = map(current_max_distance_cm(), 0, SENSOR_MAX_RANGE_CM, MIN_TIME_UNIT_MILLIS, max_time);
- return time;
+ 1000;
}
boolean is_safe_large_turn(enum_t sensor) {
@@ -821,9 +810,9 @@ void init_direction_unit(enum_t decision) {
void handle_unit(enum_t sensor, Ultrasonic& sensor_object) {
- if(timed_operation_expired(WAIT_FOR_ROBOT_TO_MOVE)) {
- init_full_sweep();
- }
+ //if(timed_operation_expired(WAIT_FOR_ROBOT_TO_MOVE)) {
+ // init_full_sweep();
+ //}
if(read_sensor(sensor, sensor_object) != NO_READING) {
if(!is_safe_large_turn(SENSOR_FRONT)) {
init_full_sweep();
View
5 ART_Control4/Ultrasonic.cpp
@@ -28,9 +28,8 @@ long Ultrasonic::Timing()
return pulseIn(Echo_pin,HIGH);
}
-long Ultrasonic::Ranging(int sys)
+long Ultrasonic::Ranging()
{
- Timing();
- return duration /29 / 2;
+ return Timing()/29 / 2;
}
View
BIN presentations/KickOff-Slides.pdf
Binary file not shown.
View
BIN presentations/KickOff.odp
Binary file not shown.
View
BIN presentations/kickoff.odt
Binary file not shown.
View
BIN presentations/kickoff.pdf
Binary file not shown.

0 comments on commit 4bb1013

Please sign in to comment.
Something went wrong with that request. Please try again.