在进行roslaunch <pkg> <file>.launch
时,我希望在该文件中启动的所有节点仅在尚未运行时才启动。
我该怎么做呢?
如果不可能,那么是否至少可以分别为每个节点执行此操作?
如果有人有想法,那么最好将代码添加到下面的示例.launch片段中。
<?xml version="1.0" encoding="UTF-8"?>
<launch>
<node pkg="rviz" type="rviz" name="rviz" />
</launch>
答案 0 :(得分:1)
不幸的是,这不可能像here所讨论的那样。
public static void customerRegistration(){
java.io.FileOutputStream file;
java.io.FileInputStream file2;
java.io.ObjectOutputStream object;
java.io.ObjectInputStream object2;
Validation validation = new Validation();
Customer[] customer = new Customer[100];
Scanner input = new Scanner(System.in);
String string;
int i = 0 , choice = 0, ww = 1;
boolean value , lol = false , exception = false;
ExceptionHandler handleEx = new ExceptionHandler();
int year , day , month;
Calendar date = Calendar.getInstance();
date.setLenient(false); // is a method that will validate the date and throws an exception if its out of range
do{
try{
file2 = new java.io.FileInputStream("Appointments.bin");
object2 = new java.io.ObjectInputStream(file2);
Customer[] aaa = (Customer[]) object2.readObject();
for(Customer ddd : aaa)
System.out.print(ddd);
object2.close();
file2.close();
} catch(java.io.FileNotFoundException a){
System.out.print("Appointments.bin File Not Found , Please Contact The Developer to fix this issue. Thank you.\n\n");
System.exit(-1);
} catch(java.io.IOException b){
} catch(java.lang.ClassNotFoundException c){
System.out.print("dsada");
}
customer[i] = new Customer();
do{
System.out.print("Enter First Name : ");
customer[i].setFirstName(input.nextLine());
value = validation.validateName(customer[i].getFirstName());
} while (value);
do{
System.out.print("Enter Last Name : ");
customer[i].setLastName(input.nextLine());
value = validation.validateName(customer[i].getLastName());
} while(value);
do{
System.out.printf("\n\n%-20s %-20s %-20s\n\n" ,"Services" , "Time Available" , "Days Available" );
System.out.printf("%-20s %-20s \n%-20s %-20s %-20s\n%-20s %-20s %-20s\n%-20s %-20s %-20s\n\n\n", "Repair" , "9.00am - 10.00am" , "Repaint" , "11.00am - 12.00pm" , "Monday - Sunday" , "Wax & Polish" , "1.00pm - 2.00pm" , "Monday - Sunday" , "Maintenance Service" , "3.00pm - 4.00pm" , "Monday - Sunday");
System.out.print("Enter A service based on numbers Ex (Repair = 1 , Repaint = 2 and so on) :");
choice = handleEx.handle(input);
input.nextLine(); // reads the new line character left by input.nexInt() in the class method.
if(choice < 1 || choice > 4)
System.out.print("\n\nPlease Enter a choice within (1-4) Range. Thank you.\n\n");
}while(choice < 1 || choice > 4);
switch(choice){
case 1:
customer[i].setService("Repair");
break;
case 2:
customer[i].setService("Repaint");
break;
case 3:
customer[i].setService("Wax & Polish");
break;
default:
customer[i].setService("Maintenance Service");
}
do{
System.out.print("Enter a time for appointment (X:XX) Where X represents a digit along with a colon : ");
if(customer[i].getService().equalsIgnoreCase("Repair")){
customer[i].setTime(input.nextLine()+"am");
if (customer[i].getTime().matches("(9):[0-5][0-9]am"))
value = false;
else{
value = true;
System.out.print("\n\nThis time is not available for this service. Please re-enter. Thank you.\n\n");
}
}
else if(customer[i].getService().equalsIgnoreCase("Repaint")){
customer[i].setTime(input.nextLine()+"am");
if (customer[i].getTime().matches("(11):[0-5][0-9]am"))
value = false;
else{
value = true;
System.out.print("\n\nThis time is not available for this service. Please re-enter. Thank you.\n\n");
}
}
else if(customer[i].getService().equalsIgnoreCase("Wax & Polish")){
customer[i].setTime(input.nextLine()+"am");
if (customer[i].getTime().matches("(1):[0-5][0-9]am"))
value = false;
else{
value = true;
System.out.print("\n\nThis time is not available for this service. Please re-enter. Thank you.\n\n");
}
}
else {
customer[i].setTime(input.nextLine()+"am");
if (customer[i].getTime().matches("(3):[0-5][0-9]am"))
value = false;
else{
value = true;
System.out.print("\n\nThis time is not available for this service. Please re-enter. Thank you.\n\n");
}
}
} while(value);
System.out.print("Enter a year : ");
year = handleEx.handle(input);
do{
System.out.print("Enter a month : ");
month = handleEx.handle(input);
month -= 1;
if(month < 1 || month > 12)
System.out.print("\n\nInvalid Date. Please re-enter. Thank you\n\n");
}while(month < 1 || month > 31);
do{
System.out.print("Enter a day : ");
day = handleEx.handle(input);
input.nextLine();
date.set(year, month, day);
value = handleEx.handle(date);
} while(value);
customer[i].setDay(Calendar.DAY_OF_MONTH + "-" + Calendar.MONTH + "-" + Calendar.YEAR);
do{
System.out.print("Please Enter Car Plate Number : ");
customer[i].setCarNo(input.nextLine().toUpperCase());
value = validation.validateCar(customer[i].getCarNo());
}while(value);
string = input.nextLine();
i++;
} while(string.equalsIgnoreCase("Y"));
try{
file = new java.io.FileOutputStream("Appointments.bin" , true);
object = new java.io.ObjectOutputStream(file);
for(Customer s : customer)
object.writeObject(s);
file.close();
object.close();
System.out.print("\n\nRecord Successfully Stored!\n\n");
} catch(java.io.FileNotFoundException a){
System.out.print("Appointments.bin File Not Found , Please Contact The Developer to fix this issue. Thank you.\n\n");
System.exit(-1);
} catch(java.io.IOException b){
System.out.print("IOException has occured. There might something wrong with the Appointmentss.bin file. Please Contact The Developer to fix this issue. Thank you.\n\n");
}
}
}
和roslaunch
将始终以所需的名称运行该节点,从而导致rosrun
将杀死具有相同名称的活动节点。
您可以使用roscore
标记来运行多个实例,这些实例的名称始终不同,如here所述。
此行为的唯一例外是anon
及其节点,如here所述。
从我的角度来看,当前唯一的解决方法是编写一个脚本,该脚本通过roscore.xml
检查所需的节点是否已在运行,并根据结果是否运行您的节点。
答案 1 :(得分:0)
在通过<arg>
标签连接的启动文件中使用<include>
标签,可以在顶部启动文件中设置变量并将其发送到其他包含的启动文件。然后,使用<if>
和<unless>
,可以启动或离开节点。您可以在ROS_Wiki中找到它的文档。
在多个独立的启动文件中,情况有所不同,因为启动文件之间没有链接。您可以使用环境变量来复制结果。