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
6 changes: 3 additions & 3 deletions 2016-CaroloCup/driver/include/DriverManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace msv {
Lane_Following = 0,
Parking = 1,
Overtaking = 2,
None = 99
Neutral = 99
};


Expand All @@ -38,8 +38,8 @@ namespace msv {
private:
int32_t argc;
char **argv;
DRIVER_STATE state;
DriverGeneric *driver_ptr;
DRIVER_STATE driver_state;
DriverGeneric *driverGeneric;
bool debug;

DriverManager(const DriverManager &/*obj*/);
Expand Down
3 changes: 1 addition & 2 deletions 2016-CaroloCup/driver/include/ParkingDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define AUTOMOTIVE_CAROLOCUP_PARKINGDRIVER_H

#include <DriverGeneric.h>

namespace msv {

using namespace std;
Expand Down Expand Up @@ -52,7 +51,7 @@ namespace msv {

DRIVING_STATE driving_state;
PARKING_STATE parking_state;
LaneFollowingDriver *laneDriver;
LaneFollowingDriver *laneFollowingDriver;

void setUp() { };

Expand Down
28 changes: 14 additions & 14 deletions 2016-CaroloCup/driver/src/DriverGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,26 @@ namespace msv {

VehicleControl DriverGeneric::GetControlData() {
// Create vehicle control data.
VehicleControl vc;
VehicleControl vehicleControl;

// With setSpeed you can set a desired speed for the vehicle in the range of -2.0 (backwards) .. 0 (stop) .. +2.0 (forwards)
vc.setSpeed(desiredSpeed);
vc.setSteeringWheelAngle(desiredSteering);
vehicleControl.setSpeed(desiredSpeed);
vehicleControl.setSteeringWheelAngle(desiredSteering);
// You can also turn on or off various lights:
vc.setBrakeLights(brakeLights);
vc.setFlashingLightsLeft(flashingLightsLeft);
vc.setFlashingLightsRight(flashingLightsRight);
vehicleControl.setBrakeLights(brakeLights);
vehicleControl.setFlashingLightsLeft(flashingLightsLeft);
vehicleControl.setFlashingLightsRight(flashingLightsRight);

return vc;
return vehicleControl;
}

VehicleControl DriverGeneric::GetStopControlData() {
VehicleControl vc;
vc.setSpeed(0);
vc.setSteeringWheelAngle(0);
vc.setBrakeLights(false);
vc.setFlashingLightsLeft(false);
vc.setFlashingLightsRight(false);
return vc;
VehicleControl vehicleControl;
vehicleControl.setSpeed(0);
vehicleControl.setSteeringWheelAngle(0);
vehicleControl.setBrakeLights(false);
vehicleControl.setFlashingLightsLeft(false);
vehicleControl.setFlashingLightsRight(false);
return vehicleControl;
}
} // msv
82 changes: 41 additions & 41 deletions 2016-CaroloCup/driver/src/DriverManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace msv {
: TimeTriggeredConferenceClientModule(argci, argvi, "DriverManager"),
argc(argci),
argv(argvi),
state(None),
driver_ptr(0),
driver_state(Neutral),
driverGeneric(0),
debug(false) {
// Deep copy of arguments
argv = new char *[argci + 1];
Expand All @@ -38,7 +38,7 @@ namespace msv {
// stop car when killing driver
stopCar();

delete (driver_ptr);
delete (driverGeneric);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of actively deleting a pointer, you should use unique_ptr or shared_ptr to let C++ do that for you.


for (int i = 0; i < argc; i++) {
delete[] argv[i];
Expand All @@ -52,11 +52,11 @@ namespace msv {
// This method will do the main data processing job.
odcore::data::dmcp::ModuleExitCodeMessage::ModuleExitCode DriverManager::body() {

Container proxyData;
SensorBoardData sbd;
bool button1; // lane following
bool button2; // parking
bool button3; // overtaking
Container proxyDataContainer;
SensorBoardData sensorBoardData;
bool laneFollowingButton; // lane following
bool parkingButton; // parking
bool overtakingButton; // overtaking

KeyValueConfiguration config = getKeyValueConfiguration();
debug = config.getValue<bool>("driverManager.Debug");
Expand All @@ -70,85 +70,85 @@ namespace msv {
while (getModuleStateAndWaitForRemainingTimeInTimeslice() == odcore::data::dmcp::ModuleStateMessage::RUNNING) {

// Get latest proxy data
proxyData = lifo.pop();
sbd = proxyData.getData<SensorBoardData>();
proxyDataContainer = lifo.pop();
sensorBoardData = proxyDataContainer.getData<SensorBoardData>();

// Get buttons data from proxy
button1 = (bool) (int) sbd.getValueForKey_MapOfDistances(9);
button2 = (bool) (int) sbd.getValueForKey_MapOfDistances(10);
button3 = (bool) (int) sbd.getValueForKey_MapOfDistances(11);
laneFollowingButton = (bool) (int) sensorBoardData.getValueForKey_MapOfDistances(9);
parkingButton = (bool) (int) sensorBoardData.getValueForKey_MapOfDistances(10);
overtakingButton = (bool) (int) sensorBoardData.getValueForKey_MapOfDistances(11);

// clear lifo to avoid filling memory
lifo.clear();

if (debug) {
cout << "Button1:" << button1 << ", Button2:" << button2 << ", Button3:" << button3 << flush;
cout << ", state:" << state << endl;
cout << "LaneFollowingButton:" << laneFollowingButton << ", ParkingButton:" << parkingButton << ", Overtaking button:" << overtakingButton << flush;
cout << ", driver state:" << driver_state << endl;
}

// Check if current buttons correspond to current state and driver
if (button1 && !button2 && !button3) {
if (state != Lane_Following) {
if (laneFollowingButton && !parkingButton && !overtakingButton) {
if (driver_state != Lane_Following) {
if (debug)
cout << "Creating Lane Following driver" << endl;
driver_ptr = new LaneFollowingDriver(argc, argv);
if (!driver_ptr) {
driverGeneric = new LaneFollowingDriver(argc, argv);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here, we shouldn't use pointers but wrap them into unique_ptr or shared_ptr.

if (!driverGeneric) {
if (debug)
cout << "Memory error" << endl;
continue; // TODO Improve error management
}
driver_ptr->runModule(); // Necessary to run it once to initialize the module entirely
state = Lane_Following;
driverGeneric->runModule(); // Necessary to run it once to initialize the module entirely
driver_state = Lane_Following;
}
}
else if (!button1 && button2 && !button3) {
if (state != Parking) {
else if (!laneFollowingButton && parkingButton && !overtakingButton) {
if (driver_state != Parking) {
if (debug)
cout << "Creating Parking driver" << endl;
driver_ptr = new ParkingDriver(argc, argv);
if (!driver_ptr) {
driverGeneric = new ParkingDriver(argc, argv);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here, we shouldn't use pointers but wrap them into unique_ptr or shared_ptr.

if (!driverGeneric) {
if (debug)
cout << "Memory error" << endl;
continue; // TODO Improve error management
}
driver_ptr->runModule(); // Necessary to run it once to initialize the module entirely
state = Parking;
driverGeneric->runModule(); // Necessary to run it once to initialize the module entirely
driver_state = Parking;
}
}
else if (!button1 && !button2 && button3) {
if (state != Overtaking) {
//driver_ptr = new OvertakingDriver(argc, argv);
if (!driver_ptr) {
else if (!laneFollowingButton && !parkingButton && overtakingButton) {
if (driver_state != Overtaking) {
//driverGeneric = new OvertakingDriver(argc, argv);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here, we shouldn't use pointers but wrap them into unique_ptr or shared_ptr.

if (!driverGeneric) {
if (debug)
cout << "Memory error" << endl;
continue; // TODO Improve error management
}
driver_ptr->runModule(); // Necessary to run it once to initialize the module entirely
state = Overtaking;
driverGeneric->runModule(); // Necessary to run it once to initialize the module entirely
driver_state = Overtaking;
}
}
else {
driver_ptr = 0;
state = None;
driverGeneric = 0;
driver_state = Neutral;
stopCar();
}

// Call driver's body and send resulting vehicle control
if (driver_ptr != 0) {
driver_ptr->body();
if (driverGeneric != 0) {
driverGeneric->body();
// Create container for finally sending the data.
Container c(driver_ptr->GetControlData());
Container container(driverGeneric->GetControlData());
// Send container.
getConference().send(c);
getConference().send(container);
}
}

return odcore::data::dmcp::ModuleExitCodeMessage::OKAY;
}

void DriverManager::stopCar() {
Container c(DriverGeneric::GetStopControlData());
getConference().send(c);
Container container(DriverGeneric::GetStopControlData());
getConference().send(container);
}

} // msv
Loading