Skip to content

Commit

Permalink
Parametrize examples
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina committed Nov 2, 2021
1 parent d736908 commit b042c8f
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 22 deletions.
14 changes: 12 additions & 2 deletions lrauv_ignition_plugins/example/example_buoyancy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,27 @@
*
*/

/**
* Usage:
* $ LRAUV_example_buoyancy <vehicle_name>
*/
#include <chrono>
#include <thread>

#include <ignition/msgs.hh>
#include <ignition/transport.hh>
#include "lrauv_command.pb.h"

int main(int argc, char** argv)
int main(int _argc, char **_argv)
{
std::string vehicleName("tethys");
if (_argc > 1)
{
vehicleName = _argv[1];
}

ignition::transport::Node node;
auto commandTopic = "/tethys/command_topic";
auto commandTopic = "/" + vehicleName + "/command_topic";
auto commandPub =
node.Advertise<lrauv_ignition_plugins::msgs::LRAUVCommand>(commandTopic);

Expand Down
30 changes: 28 additions & 2 deletions lrauv_ignition_plugins/example/example_controller.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/**
* This is a stupidly simple test controller
* that wiggles the fins a bit and then commands the robot
* to charge forward.
*
* Usage:
* $ LRAUV_example_controller <vehicle_name>
*/
#include <chrono>
#include <thread>
Expand All @@ -10,10 +30,16 @@
#include <ignition/transport.hh>
#include "lrauv_command.pb.h"

int main(int argc, char** argv)
int main(int _argc, char **_argv)
{
std::string vehicleName("tethys");
if (_argc > 1)
{
vehicleName = _argv[1];
}

ignition::transport::Node node;
auto commandTopic = "/tethys/command_topic";
auto commandTopic = "/" + vehicleName + "/command_topic";
auto commandPub =
node.Advertise<lrauv_ignition_plugins::msgs::LRAUVCommand>(commandTopic);

Expand Down
12 changes: 9 additions & 3 deletions lrauv_ignition_plugins/example/example_mass_shifter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* forward and backward.
*
* Usage:
* $ TestMassShifter
* $ LRAUV_example_mass_shifter <vehicle_name>
*/

#include <chrono>
Expand All @@ -30,10 +30,16 @@
#include <ignition/transport.hh>
#include "lrauv_command.pb.h"

int main(int argc, char** argv)
int main(int _argc, char **_argv)
{
std::string vehicleName("tethys");
if (_argc > 1)
{
vehicleName = _argv[1];
}

ignition::transport::Node node;
auto commandTopic = "/tethys/command_topic";
auto commandTopic = "/" + vehicleName + "/command_topic";
auto commandPub =
node.Advertise<lrauv_ignition_plugins::msgs::LRAUVCommand>(commandTopic);

Expand Down
44 changes: 31 additions & 13 deletions lrauv_ignition_plugins/example/keyboard_teleop.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/**
* Keyboard teleop controller
*
* Usage:
* $ LRAUV_keyboard_teleop <vehicle_name>
*/
#include <unistd.h>
#include <termios.h>
Expand Down Expand Up @@ -32,17 +52,15 @@ char getch()
return (buf);
}

int main(int argc, char** argv)
int main(int _argc, char **_argv)
{
// Robot namespace, to allow multiple vehicles
std::string ns = "tethys";
for (int i = 1; i < argc; i++)
std::string vehicleName("tethys");
if (_argc > 1)
{
ns = argv[i];
vehicleName = _argv[1];
}

ignition::transport::Node node;
std::string commandTopic = ns + "/command_topic";
auto commandTopic = "/" + vehicleName + "/command_topic";
auto commandPub =
node.Advertise<lrauv_ignition_plugins::msgs::LRAUVCommand>(commandTopic);

Expand All @@ -53,14 +71,14 @@ int main(int argc, char** argv)
{
std::cout << "\033[2J";
std::cout << "Keyboard teleop for lrauv" << std::endl;
std::cout << "Robot namespace set to [" << ns << "]" << std::endl;
std::cout << "Robot namespace set to [" << vehicleName << "]" << std::endl;
std::cout << " w <-- Control elevator to point up (pitch down)" <<std::endl;
std::cout << "a d <-- Control Rudder left/right" <<std::endl;
std::cout << " s <-- Point Elevator down (pitch up)" <<std::endl;
std::cout << "a d <-- Control Rudder left/right" << std::endl;
std::cout << " s <-- Point Elevator down (pitch up)" << std::endl;

std::cout << "Throttle control:" <<std::endl;
std::cout << "\tk - increase thrust "<< std::endl;
std::cout << "\tj - decrease thrust "<< std::endl;
std::cout << "Throttle control:" << std::endl;
std::cout << "\tk - increase thrust " << std::endl;
std::cout << "\tj - decrease thrust " << std::endl;

std::cout << "Current state:" << std::endl;
std::cout << "\tThrust (radians per second): " << thrust << std::endl;
Expand Down
3 changes: 1 addition & 2 deletions lrauv_ignition_plugins/example/multi_lrauv_race.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
* within reasonable limits, and send the command to the vehicle.
*
* Usage:
* $ MultiLRAUVRace
* $ LRAUV_multi_lrauv_race
*/

#include <chrono>
#include <thread>

Expand Down

0 comments on commit b042c8f

Please sign in to comment.