Ask Your Question
1

rosjava: Get List of Parameters

asked 2013-02-13 00:37:19 -0600

dberm22 gravatar image

updated 2013-02-14 01:14:53 -0600

I am developing with ros on an android tablet, and I am trying to change parameters using the device (as a remote, so to speak). However, I am having trouble doing so. Has anyone done this?

Here is my attempt:

    NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic( InetAddressFactory.newNonLoopback().getHostAddress());
    nodeConfiguration.setMasterUri(URI.create(IP_ADDRESS));
    ListView ParamListView = (ListView) findViewById(R.id.ParamListView);
    final String[] NodeName = url.split("=");
    ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(Integer.MAX_VALUE);
    NodeFactory nodeFactory = new DefaultNodeFactory(scheduledExecutorService);
    Node node = nodeFactory.newNode(nodeConfiguration);
    ConnectedNode connectednode = (ConnectedNode) node;
    final ParameterTree ParamList = connectednode.getParameterTree();
    //final ParameterTree ParamList = (ParameterTree) new ArrayList<String>();
    @SuppressWarnings("unchecked")
    List<String> ParamJavaList = (List<String>) ParamList.getList(NodeName[1]);
    final ArrayAdapter<String> ParamListAdapter = new ArrayAdapter<String>(this, android.R.id.text1, ParamJavaList);
    ParamListView.setAdapter(ParamListAdapter);

What am I doing wrong? I am not sure how to copy and paste my error log, but the error is is occurring before my call of getList().

If I uncomment the commented line and comment out the 5 lines before it, I get an error saying I cannot cast from ArrayList to ParameterTree. That is how I got to this convoluted point of trying to initialize the ParamList using getParameterTree(), which requires access to the connected node.

I am sure there is an easier way to do this, but I am not aware of it.

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-02-14 08:26:14 -0600

dberm22 gravatar image

updated 2013-02-20 04:39:26 -0600

I was able to solve it by going the route of ssh-ing into the host machine (using Jsch). This code did the bulk of the work from an AsyncTask.

            JSch jsch=new JSch();  

            Properties config = new Properties();
            config.put("StrictHostKeyChecking", "no");
            config.put("compression.s2c", "zlib,none");
            config.put("compression.c2s", "zlib,none");

            this.user = params[0];
            this.host = params[1];
            this.pwd = params[2];
            this.cmd = params[3];

            session=jsch.getSession(user, host, 22);   
            session.setConfig(config);
            session.setPassword(pwd);
            session.connect();

            StringBuffer result = new StringBuffer();

            channelexec = (ChannelExec) session.openChannel("exec");
            String setPATH = "source /opt/ros/fuerte/setup.bash;export ROS_PACKAGE_PATH=/home/YOURCOMPNAME/ros_workspace:/opt/ros/fuerte/share:/opt/ros/fuerte/stacks;";
            channelexec.setCommand(setPATH+cmd);//
            channelexec.setInputStream(null);
            //channel.setOutputStream(System.out);
            channelexec.setErrStream(System.err);

            InputStream stdout = channelexec.getInputStream();
            InputStream stderr = channelexec.getErrStream();
            //channelexec.setPty(true);
            channelexec.connect();

            msg = "Connected to Host";
            toastHandler.post(toastRunnable);

            String aux = "";
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stdout));
            while ((aux=bufferedReader.readLine()) != null) {
                    aux.replaceAll(NodeName,"");
                builder.append(","+aux);
            }    

        }catch(Exception e){
            msg = "Cannot Retrieve Param List";
            toastHandler.post(toastRunnable);
            e.printStackTrace();
        }
        return builder.toString().substring(1);

And the cmd I called was:

String cmd = "rosparam list "+NodeName
edit flag offensive delete link more

Comments

This is more of a workaround then a solution, please consider removing "selected answer"

OzzieTheHead gravatar imageOzzieTheHead ( 2018-08-09 12:54:40 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-02-13 00:37:19 -0600

Seen: 616 times

Last updated: Feb 20 '13