Skip to content

Commit

Permalink
better control, no show arrow text
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMoraru123 committed Jun 19, 2023
1 parent 635aaaf commit d864e27
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Control/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void EgoCarController::registerKeyboardCallbacks() {
if (keyStates_.find(event.getKeySym()) != keyStates_.end()) {
keyStates_[event.getKeySym()] = event.keyDown();
}
if (event.isShiftPressed()) {car_.accelerate(10.0, 1);}
});
}

Expand All @@ -32,6 +33,8 @@ void EgoCarController::handleKeyboardInput() {
} else if (keyStates_["Down"]) {
car_.accelerate(3.0, -1);
} else if (keyStates_["space"]) {
car_.accelerate(-15.0, 1);
} else {
car_.accelerate(0.0, 1);
}

Expand Down
12 changes: 6 additions & 6 deletions Objects/car.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Car::Car()
control_index(0),
sinNegAngle(0),
cosNegAngle(0),
air_resistance(0.01),
tire_friction(0.1) {}
air_resistance(0.0),
tire_friction(0.0) {}

Car::Car(
Vect3 setPosition, Vect3 setDimensions, Color setColor,
Expand All @@ -35,8 +35,8 @@ Car::Car(
velocity = 0;
control_index = 0;
rollingInstance = 0.5;
air_resistance = 0.01;
tire_friction = 0.1;
air_resistance = 0.0;
tire_friction = 0.0;
}

void Car::renderBottom(pcl::visualization::PCLVisualizer::Ptr& viewer) const {
Expand Down Expand Up @@ -113,11 +113,11 @@ void Car::render(pcl::visualization::PCLVisualizer::Ptr& viewer) const {
}

void Car::accelerate(float acc, int dir) {
acceleration = acc * dir - air_resistance * velocity * abs(velocity) - tire_friction * sign(velocity);
acceleration = acc * dir;
}

void Car::steer(float s) {
steering = s / (1 + abs(velocity));
steering = s;
}

void Car::control(const std::vector<Control>& c) {
Expand Down
2 changes: 1 addition & 1 deletion Scene/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Scene::Scene(pcl::visualization::PCLVisualizer::Ptr& viewer) {

Control Scene::randomControl(std::mt19937& gen, Car& car) {
std::uniform_real_distribution<> disTime(1, 9);
std::uniform_real_distribution<> disAcceleration(-5, 2);
std::uniform_real_distribution<> disAcceleration(-2, 1);
std::uniform_real_distribution<> disSteering(-0.15, 0.15);

Vect3 currentPosition = car.getPosition();
Expand Down
8 changes: 4 additions & 4 deletions Toolkit/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ radarMarker Tools::radarSense(Car& car, Car ego, pcl::visualization::PCLVisualiz
ego.getPosition().x + marker.rho * cos(marker.phi) + marker.rhoDot * cos(marker.phi),
ego.getPosition().y + marker.rho * sin(marker.phi) + marker.rhoDot * sin(marker.phi),
3.0
), 1, 0, 1, car.getName() + "_rhoDot");
), 1, 0, 1, false, car.getName() + "_rhoDot");
}

MeasurementPackage measPackage;
Expand All @@ -84,23 +84,23 @@ void Tools::trackerResults(Car car, pcl::visualization::PCLVisualizer::Ptr &view
pcl::PointXYZ(tracker.x_[0], tracker.x_[1],3.5),
pcl::PointXYZ(tracker.x_[0] + tracker.x_[2] * cos(tracker.x_[3]),
tracker.x_[1] + tracker.x_[2] * sin(tracker.x_[3]),3.5),
0, 1, 0, car.getName()+"_tracker_vel");
0, 1, 0, false, car.getName()+"_tracker_vel");

if (time > 0) {
double dt = time / steps;
double ct = dt;
while (ct <= time) {
tracker.Prediction(dt);
viewer->addSphere(pcl::PointXYZ(tracker.x_[0], tracker.x_[1], 3.5),
0.5, 0, 1, 0,car.getName() + "_ukf" + std::to_string(ct));
0.5, 0, 1, 0, car.getName() + "_ukf" + std::to_string(ct));
viewer->setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_OPACITY,
1.0 - 0.8 * (ct / time),
car.getName() + "_ukf" + std::to_string(ct));
viewer->addArrow(
pcl::PointXYZ(tracker.x_[0], tracker.x_[1],3.5),
pcl::PointXYZ(tracker.x_[0] + tracker.x_[2] * cos(tracker.x_[3]),
tracker.x_[1] + tracker.x_[2] * sin(tracker.x_[3]), 3.5),
0, 1, 0, car.getName() + "_ukf_vel"+std::to_string(ct));
0, 1, 0, false, car.getName() + "_ukf_vel"+std::to_string(ct));
viewer->setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_OPACITY,
1.0-0.8*(ct/time),
car.getName() + "_ukf_vel"+std::to_string(ct));
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main() {
viewer->addCoordinateSystem(1.0);
viewer->initCameraParameters();
int* screenSize = viewer->getRenderWindow()->GetScreenSize();
viewer->setSize(screenSize[0], screenSize[1]);
viewer->setSize(1280, 780);

viewer->setCameraPosition(50, 50, 50, // Camera position
0, 0, 0, // Focal point (origin)
Expand Down

0 comments on commit d864e27

Please sign in to comment.