2007-02-04 21:38:03 +00:00
|
|
|
#include "stdafx.h"
|
2007-01-14 18:07:03 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
//Init our robot
|
|
|
|
Robot* localRobot = new Robot();
|
|
|
|
|
2007-02-19 22:02:01 +00:00
|
|
|
sleep(1);//Wait for Hardware
|
2007-02-19 20:57:03 +00:00
|
|
|
|
|
|
|
//Init Displays
|
|
|
|
for(uint8 i = IO_DISPLAY_START; i < IO_DISPLAY_END; i++)
|
|
|
|
{
|
|
|
|
Display* newDisplay = new Display(i);
|
|
|
|
localRobot->AddModule(newDisplay);
|
|
|
|
newDisplay = NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-14 18:07:03 +00:00
|
|
|
//Init Engines
|
|
|
|
for(uint8 i = IO_ENGINE_START; i < IO_ENGINE_END; i++)
|
|
|
|
{
|
|
|
|
Engine* newEngine = new Engine(i);
|
|
|
|
localRobot->AddModule(newEngine);
|
|
|
|
newEngine = NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-17 00:35:01 +00:00
|
|
|
//Init Dribbler
|
|
|
|
for(uint8 i = IO_DRIBBLER_START; i < IO_DRIBBLER_END; i++)
|
|
|
|
{
|
|
|
|
Dribbler* newDribbler = new Dribbler(i);
|
|
|
|
localRobot->AddModule(newDribbler);
|
|
|
|
newDribbler = NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-15 20:33:05 +00:00
|
|
|
//Init Kicker
|
|
|
|
for(uint8 i = IO_KICKER_START; i < IO_KICKER_END; i++)
|
|
|
|
{
|
|
|
|
Kicker* newKicker = new Kicker(i);
|
|
|
|
localRobot->AddModule(newKicker);
|
|
|
|
newKicker = NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-22 13:12:03 +00:00
|
|
|
//Init Aktuator
|
|
|
|
for(uint8 i = IO_AKTUATOR_START; i < IO_AKTUATOR_END; i++)
|
|
|
|
{
|
|
|
|
Aktuator* newAktuator = new Aktuator(i);
|
|
|
|
localRobot->AddModule(newAktuator);
|
|
|
|
newAktuator = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Init Wireless
|
|
|
|
for(uint8 i = IO_WIRELESS_START; i < IO_WIRELESS_END; i++)
|
|
|
|
{
|
|
|
|
Wireless* newWireless = new Wireless(i);
|
|
|
|
localRobot->AddModule(newWireless);
|
|
|
|
newWireless = NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-14 18:07:03 +00:00
|
|
|
//Init Sensors
|
|
|
|
for(uint8 i = IO_SENSOR_START; i < IO_SENSOR_END; i++)
|
|
|
|
{
|
|
|
|
switch(i)
|
|
|
|
{
|
2007-02-15 20:33:05 +00:00
|
|
|
//Create correct type of sensor
|
|
|
|
case IO_SENSOR_IR_0_DEG:
|
|
|
|
case IO_SENSOR_IR_30_DEG:
|
|
|
|
case IO_SENSOR_IR_60_DEG:
|
|
|
|
case IO_SENSOR_IR_100_DEG:
|
|
|
|
case IO_SENSOR_IR_180_DEG:
|
|
|
|
case IO_SENSOR_IR_260_DEG:
|
|
|
|
case IO_SENSOR_IR_300_DEG:
|
|
|
|
case IO_SENSOR_IR_330_DEG:
|
|
|
|
{
|
|
|
|
IR_Sensor* newSensor = new IR_Sensor(i);
|
|
|
|
localRobot->AddModule(newSensor);
|
|
|
|
newSensor = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-17 00:35:01 +00:00
|
|
|
case IO_SENSOR_DISTANCE_0_DEG:
|
|
|
|
case IO_SENSOR_DISTANCE_90_DEG:
|
|
|
|
case IO_SENSOR_DISTANCE_180_DEG:
|
|
|
|
case IO_SENSOR_DISTANCE_270_DEG:
|
|
|
|
{
|
|
|
|
Distance_Sensor* newSensor = new Distance_Sensor(i);
|
|
|
|
localRobot->AddModule(newSensor);
|
|
|
|
newSensor = NULL;
|
2007-02-19 20:57:03 +00:00
|
|
|
|
2007-02-17 00:35:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-02-17 13:42:00 +00:00
|
|
|
case IO_SENSOR_MOUSE_LEFT:
|
|
|
|
case IO_SENSOR_MOUSE_RIGHT:
|
|
|
|
{
|
|
|
|
Mouse_Sensor* newSensor = new Mouse_Sensor(i);
|
|
|
|
localRobot->AddModule(newSensor);
|
|
|
|
newSensor = NULL;
|
2007-02-19 20:57:03 +00:00
|
|
|
|
2007-02-17 13:42:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-14 18:07:03 +00:00
|
|
|
//Other cases
|
|
|
|
default:
|
2007-02-15 20:33:05 +00:00
|
|
|
{
|
|
|
|
Sensor* newSensor = new Sensor(i);
|
|
|
|
localRobot->AddModule(newSensor);
|
|
|
|
newSensor = NULL;
|
2007-01-14 18:07:03 +00:00
|
|
|
break;
|
2007-02-15 20:33:05 +00:00
|
|
|
}
|
2007-01-14 18:07:03 +00:00
|
|
|
}
|
2007-02-15 20:33:05 +00:00
|
|
|
}
|
2007-01-14 18:07:03 +00:00
|
|
|
|
2007-02-15 20:33:05 +00:00
|
|
|
//Init Leds
|
|
|
|
for(uint8 i = IO_LED_START; i < IO_LED_END; i++)
|
|
|
|
{
|
|
|
|
Led* newLed = new Led(i);
|
|
|
|
localRobot->AddModule(newLed);
|
|
|
|
newLed = NULL;
|
2007-01-14 18:07:03 +00:00
|
|
|
}
|
2007-02-17 00:35:01 +00:00
|
|
|
|
2007-02-17 13:42:00 +00:00
|
|
|
//Init Keyboards
|
|
|
|
for(uint8 i = IO_KEYBOARD_START; i < IO_KEYBOARD_END; i++)
|
|
|
|
{
|
|
|
|
Keyboard* newKeyboard = new Keyboard(i);
|
|
|
|
localRobot->AddModule(newKeyboard);
|
|
|
|
newKeyboard = NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-18 00:14:00 +00:00
|
|
|
//Init Position Tracker
|
|
|
|
for(uint8 i = IO_POSITION_TRACKER_START; i < IO_POSITION_TRACKER_END; i++)
|
|
|
|
{
|
|
|
|
Position_Tracker* newPositionTracker = new Position_Tracker(i);
|
|
|
|
localRobot->AddModule(newPositionTracker);
|
|
|
|
newPositionTracker = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Init Ball Tracker
|
|
|
|
for(uint8 i = IO_BALL_TRACKER_START; i < IO_BALL_TRACKER_END; i++)
|
|
|
|
{
|
|
|
|
Ball_Tracker* newBallTracker = new Ball_Tracker(i);
|
|
|
|
localRobot->AddModule(newBallTracker);
|
|
|
|
newBallTracker = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Init Navigators
|
|
|
|
for(uint8 i = IO_NAVIGATOR_START; i < IO_NAVIGATOR_END; i++)
|
|
|
|
{
|
|
|
|
Navigator* newNavigator = new Navigator(i);
|
|
|
|
localRobot->AddModule(newNavigator);
|
|
|
|
newNavigator = NULL;
|
|
|
|
}
|
2007-02-19 22:02:01 +00:00
|
|
|
|
2007-02-22 13:12:03 +00:00
|
|
|
//Init Logics
|
|
|
|
for(uint8 i = IO_LOGIC_START; i < IO_LOGIC_END; i++)
|
|
|
|
{
|
|
|
|
Logic* newLogic = new Logic(i);
|
|
|
|
localRobot->AddModule(newLogic);
|
|
|
|
newLogic = NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-19 20:57:03 +00:00
|
|
|
sleep(1);
|
2007-02-19 22:02:01 +00:00
|
|
|
|
|
|
|
//Debug code
|
|
|
|
Display* ourDisplay = localRobot->GetModule<Display>(IO_DISPLAY_MAIN);
|
2007-02-19 20:57:03 +00:00
|
|
|
ourDisplay->Clear();
|
2007-02-22 20:59:02 +00:00
|
|
|
ourDisplay->Print("Roboter fertig gestartet",1,1);
|
|
|
|
sleep(1);
|
2007-02-18 00:14:00 +00:00
|
|
|
|
|
|
|
|
2007-02-17 13:42:00 +00:00
|
|
|
IR_Sensor* ourSensor = NULL;
|
2007-02-19 20:57:03 +00:00
|
|
|
Distance_Sensor* distanceSensor = NULL;
|
2007-02-17 13:42:00 +00:00
|
|
|
uint16 value = 0;
|
2007-02-18 00:14:00 +00:00
|
|
|
int8 value2 = 0;
|
2007-02-19 20:57:03 +00:00
|
|
|
|
2007-02-18 17:57:03 +00:00
|
|
|
Keyboard* ourKeyboard = localRobot->GetModule<Keyboard>(IO_KEYBOARD_MAIN);
|
2007-02-17 13:42:00 +00:00
|
|
|
uint32 i = 1;
|
2007-02-18 17:57:03 +00:00
|
|
|
Navigator* ourNavigator = localRobot->GetModule<Navigator>(IO_NAVIGATOR_MAIN);
|
2007-02-20 21:01:02 +00:00
|
|
|
Position_Tracker* ourPosition_Tracker = localRobot->GetModule<Position_Tracker>(IO_POSITION_TRACKER_MAIN);
|
2007-02-22 13:12:03 +00:00
|
|
|
Ball_Tracker* ourBallTracker = localRobot->GetModule<Ball_Tracker>(IO_BALL_TRACKER_MAIN);
|
|
|
|
Dribbler* ourDribbler = localRobot->GetModule<Dribbler>(IO_DRIBBLER_MAIN);
|
|
|
|
ourDribbler->SetSpeed(1);
|
|
|
|
ourDribbler->SetEnabled(true);
|
|
|
|
Aktuator* ourAktuator = localRobot->GetModule<Aktuator>(IO_AKTUATOR_MAIN);
|
2007-02-22 20:59:02 +00:00
|
|
|
Logic* ourLogic = localRobot->GetModule<Logic>(IO_LOGIC_MAIN);
|
|
|
|
|
2007-02-18 17:57:03 +00:00
|
|
|
float rotation = 0;
|
2007-02-22 13:12:03 +00:00
|
|
|
float speed = 200;
|
2007-02-18 17:57:03 +00:00
|
|
|
|
2007-02-20 21:01:02 +00:00
|
|
|
//Mouse_Sensor* mouse_left = localRobot->GetModule<Mouse_Sensor>(IO_SENSOR_MOUSE_LEFT);
|
|
|
|
//Mouse_Sensor* mouse_right = localRobot->GetModule<Mouse_Sensor>(IO_SENSOR_MOUSE_RIGHT);
|
2007-02-19 20:57:03 +00:00
|
|
|
|
2007-02-22 20:59:02 +00:00
|
|
|
ourDisplay->Clear();
|
2007-02-17 13:42:00 +00:00
|
|
|
|
2007-01-14 18:07:03 +00:00
|
|
|
//Run
|
|
|
|
while(true)
|
|
|
|
{
|
2007-02-20 21:01:02 +00:00
|
|
|
ourDisplay->Print(i++,1,1);
|
2007-02-22 13:12:03 +00:00
|
|
|
|
2007-02-22 20:59:02 +00:00
|
|
|
//msleep(50);
|
2007-02-20 21:01:02 +00:00
|
|
|
|
2007-02-22 20:59:02 +00:00
|
|
|
if(!(i % 20))
|
2007-02-20 21:01:02 +00:00
|
|
|
{
|
|
|
|
ourDisplay->Clear();
|
2007-02-22 20:59:02 +00:00
|
|
|
|
|
|
|
distanceSensor = localRobot->GetModule<Distance_Sensor>(IO_SENSOR_DISTANCE_0_DEG);
|
|
|
|
value = distanceSensor->GetDistance();
|
|
|
|
ourDisplay->Print(value, 1, 4);
|
|
|
|
ourDisplay->Print(";");
|
|
|
|
distanceSensor = localRobot->GetModule<Distance_Sensor>(IO_SENSOR_DISTANCE_90_DEG);
|
|
|
|
value = distanceSensor->GetDistance();
|
|
|
|
ourDisplay->Print(value);
|
|
|
|
ourDisplay->Print(";");
|
|
|
|
distanceSensor = localRobot->GetModule<Distance_Sensor>(IO_SENSOR_DISTANCE_180_DEG);
|
|
|
|
value = distanceSensor->GetDistance();
|
|
|
|
ourDisplay->Print(value);
|
|
|
|
ourDisplay->Print(";");
|
|
|
|
distanceSensor = localRobot->GetModule<Distance_Sensor>(IO_SENSOR_DISTANCE_270_DEG);
|
|
|
|
value = distanceSensor->GetDistance();
|
|
|
|
ourDisplay->Print(value);
|
|
|
|
ourDisplay->Print(";");
|
2007-02-22 13:12:03 +00:00
|
|
|
}
|
|
|
|
|
2007-02-22 20:59:02 +00:00
|
|
|
if(!(i % 20))
|
2007-02-22 13:12:03 +00:00
|
|
|
{
|
2007-02-22 20:59:02 +00:00
|
|
|
//ourAktuator->Kick();
|
2007-02-20 21:01:02 +00:00
|
|
|
}
|
|
|
|
|
2007-02-18 17:57:03 +00:00
|
|
|
uint8 someInput = ourKeyboard->GetInput();
|
2007-02-19 20:57:03 +00:00
|
|
|
//ourDisplay->Print("Ready to accept...", 1, 2);
|
2007-02-18 17:57:03 +00:00
|
|
|
switch(someInput)
|
|
|
|
{
|
2007-02-19 20:57:03 +00:00
|
|
|
case 0:
|
|
|
|
ourNavigator->Stop();
|
2007-02-22 13:12:03 +00:00
|
|
|
return 0;
|
2007-02-20 21:01:02 +00:00
|
|
|
break;
|
2007-02-18 17:57:03 +00:00
|
|
|
case 1:
|
2007-02-22 13:12:03 +00:00
|
|
|
ourNavigator->Drive(225, rotation, speed, rotation);
|
2007-02-18 17:57:03 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2007-02-22 13:12:03 +00:00
|
|
|
ourNavigator->Drive(180, rotation, speed, rotation);
|
2007-02-18 17:57:03 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2007-02-22 13:12:03 +00:00
|
|
|
ourNavigator->Drive(135, rotation, speed, rotation);
|
2007-02-18 17:57:03 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2007-02-22 13:12:03 +00:00
|
|
|
ourNavigator->Drive(270, rotation, speed, rotation);
|
2007-02-18 17:57:03 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2007-02-19 20:57:03 +00:00
|
|
|
ourNavigator->Drive(0, rotation, 0, rotation);
|
2007-02-18 17:57:03 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2007-02-22 13:12:03 +00:00
|
|
|
ourNavigator->Drive(90, rotation, speed, rotation);
|
2007-02-18 17:57:03 +00:00
|
|
|
break;
|
|
|
|
case 7:
|
2007-02-22 13:12:03 +00:00
|
|
|
ourNavigator->Drive(315, rotation, speed, rotation);
|
2007-02-18 17:57:03 +00:00
|
|
|
break;
|
|
|
|
case 8:
|
2007-02-22 13:12:03 +00:00
|
|
|
ourNavigator->Drive(0, rotation, speed, rotation);
|
2007-02-18 17:57:03 +00:00
|
|
|
break;
|
|
|
|
case 9:
|
2007-02-22 13:12:03 +00:00
|
|
|
ourNavigator->Drive(45, rotation, speed, rotation);
|
2007-02-18 17:57:03 +00:00
|
|
|
break;
|
|
|
|
case 10:
|
2007-02-22 13:12:03 +00:00
|
|
|
ourPosition_Tracker->SetPosition(0,0,0); // Reset Position_Tracker
|
2007-02-18 17:57:03 +00:00
|
|
|
break;
|
|
|
|
case 12:
|
2007-02-22 20:59:02 +00:00
|
|
|
ourLogic->SetKeeper(true); // Reset Position_Tracker
|
2007-02-18 17:57:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-02-19 20:57:03 +00:00
|
|
|
|
|
|
|
//ourDisplay->Clear();
|
2007-02-22 20:59:02 +00:00
|
|
|
if(!(i % 20))
|
|
|
|
{
|
|
|
|
/*ourDisplay->Clear();
|
|
|
|
ourSensor = localRobot->GetModule<IR_Sensor>(IO_SENSOR_IR_0_DEG);
|
|
|
|
value = ourSensor->GetIRIntensity();
|
|
|
|
ourDisplay->Print(value, 1, 2);
|
|
|
|
ourDisplay->Print(";");
|
|
|
|
ourSensor = localRobot->GetModule<IR_Sensor>(IO_SENSOR_IR_30_DEG);
|
|
|
|
value = ourSensor->GetIRIntensity();
|
|
|
|
ourDisplay->Print(value);
|
|
|
|
ourDisplay->Print(";");
|
|
|
|
ourSensor = localRobot->GetModule<IR_Sensor>(IO_SENSOR_IR_60_DEG);
|
|
|
|
value = ourSensor->GetIRIntensity();
|
|
|
|
ourDisplay->Print(value);
|
|
|
|
ourDisplay->Print(";");
|
|
|
|
ourSensor = localRobot->GetModule<IR_Sensor>(IO_SENSOR_IR_100_DEG);
|
|
|
|
value = ourSensor->GetIRIntensity();
|
|
|
|
ourDisplay->Print(value);
|
|
|
|
ourDisplay->Print(";");
|
|
|
|
ourSensor = localRobot->GetModule<IR_Sensor>(IO_SENSOR_IR_180_DEG);
|
|
|
|
value = ourSensor->GetIRIntensity();
|
|
|
|
ourDisplay->Print(value, 1, 3);
|
|
|
|
ourDisplay->Print(";");
|
|
|
|
ourSensor = localRobot->GetModule<IR_Sensor>(IO_SENSOR_IR_260_DEG);
|
|
|
|
value = ourSensor->GetIRIntensity();
|
|
|
|
ourDisplay->Print(value);
|
|
|
|
ourDisplay->Print(";");
|
|
|
|
ourSensor = localRobot->GetModule<IR_Sensor>(IO_SENSOR_IR_300_DEG);
|
|
|
|
value = ourSensor->GetIRIntensity();
|
|
|
|
ourDisplay->Print(value);
|
|
|
|
ourDisplay->Print(";");
|
|
|
|
ourSensor = localRobot->GetModule<IR_Sensor>(IO_SENSOR_IR_330_DEG);
|
|
|
|
value = ourSensor->GetIRIntensity();
|
|
|
|
ourDisplay->Print(value);
|
|
|
|
ourDisplay->Print(";");
|
|
|
|
if(ourBallTracker->KnowsBallDirection())
|
|
|
|
{
|
|
|
|
ourDisplay->Print(ourBallTracker->GetBallDirection() * 180.0f / PI, 1, 4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ourDisplay->Print("Not found oder so", 1, 4);
|
|
|
|
}*/
|
|
|
|
}
|
2007-02-19 20:57:03 +00:00
|
|
|
|
2007-01-14 18:07:03 +00:00
|
|
|
localRobot->Update();
|
2007-02-18 00:14:00 +00:00
|
|
|
|
2007-02-22 13:12:03 +00:00
|
|
|
//ourDisplay->Print(ourBallTracker->GetBallDirection() * 180.0f / PI, 1, 4);
|
|
|
|
|
|
|
|
//ourNavigator->Drive(ourBallTracker->GetBallDirection() * 180.0f / PI, 0, 255, 0);
|
2007-01-14 18:07:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Cleanup
|
|
|
|
delete localRobot;
|
|
|
|
localRobot = NULL;
|
2007-02-04 21:38:03 +00:00
|
|
|
}
|