loading
 
Sabertooth Module and RoboRealm API
Anonymous
10 years
In the java source code that I downloaded for the RoboRealm API, I would like to send commands to control the motors. I tried this snippet of code, but it isn't finding the motors.

rr.execute("<head><version>1.8.1.3</version></head><DE_Sabertooth><motor_4_value>128</motor_4_value>"+
            "<motor_5_max>255</motor_5_max>" +
            "<com_port>2</com_port>" +
            "<motor_15_max>255</motor_15_max>" +
            "<motor_16_max>255</motor_16_max>" +
            "<motor_8_value>128</motor_8_value>" +
            "<motor_14_max>255</motor_14_max>" +
            "<motor_6_max>255</motor_6_max>" +
            "<motor_5_value>128</motor_5_value>" +
            "<motor_9_value>128</motor_9_value>" +
            "<motor_9_max>255</motor_9_max>" +
            "<motor_4_max>255</motor_4_max>" +
            "<motor_1_map>left_motor</motor_1_map>" +
            "<motor_12_value>128</motor_12_value>" +
            "<motor_2_map>right_motor</motor_2_map>" +
            "<motor_13_max>255</motor_13_max>" +
            "<motor_3_max>255</motor_3_max>" +
            "<motor_8_max>255</motor_8_max>" +
            "<motor_10_value>128</motor_10_value>" +
            "<motor_13_value>128</motor_13_value>" +
            "<motor_11_max>255</motor_11_max>" +
            "<motor_12_max>255</motor_12_max>" +
            "<motor_1_max>255</motor_1_max>" +
            "<motor_2_max>255</motor_2_max>" +
            "<motor_14_value>128</motor_14_value>" +
            "<motor_15_value>128</motor_15_value>" +
            "<motor_10_max>255</motor_10_max>" +
            "<motor_6_value>128</motor_6_value>" +
            "<baud_rate>9600</baud_rate>" +
            "<motor_7_value>128</motor_7_value>" +
            "<motor_16_value>128</motor_16_value>" +
            "<motor_11_value>128</motor_11_value>" +
            "<motor_7_max>255</motor_7_max>" +
            "<motor_3_value>128</motor_3_value</DE_Sabertooth>");


// execute a Motor; motor 1 is left and motor 2 is right
    
    boolean result = rr.putModuleVariable("DE_Sabertooth", "motor_1_map", "left_motor","29");
    System.out.println("Putting motor value "+result);


public boolean putModuleVariable(String module_name, String module_num, String param_name, String param_value)
  {
    if (!connected) return false;
    if ((module_name==null)||(module_name.length()==0)) return false;

    if (send("<request><set_parameter><module>"+escape(module_name)+"</module><module_number>"+
            escape(module_num)+"</module_number>" + "<name>"+escape(param_name)+"</name>"+"<value>"+escape(param_value)+"</value>"+
                    "</set_parameter></request>"))
    {
        
              // read in confirmation
              String buffer;
              if ((buffer=readMessage())!=null)
              {
                if (buffer.equals("<response>ok</response>"))
                  return true;
              }
    }

            return false;
}

I always get back false here. What is wrong with the code, or is it not even possible the way the code is currently structured?

Thanks,
Anonymous 10 years
Actually, you've got things a little confused between parameters and variables (which is expected since the parameter API call is very new).

If you setup the module as you have done you only need to change the value of the left_motor and right_motor VARIABLES to different values. That would use the set_variable API call and not the set_parameter. The control module would then look into those variables to determine the actual number to send to the robot.

If you wanted to change the motor_1 binding from the left_motor variable to say the lefty_side variable then you would use the set_parameter routine to do that ... but this is probably not needed since one variable can be used just as readily as the next.

Thus in your case, forget about the set_parameter routine, set the left and right motors (using the GUI or execute API call) to left_motor and right_motor and then just use the set_variable routine to set the values for the left_motor and right_motor variables.

Note that in the above routine module_number will almost always be 1 and not a string.

boolean result = rr.putModuleVariable("DE_Sabertooth", 1, "motor_1_map","left_motor");

would be the correct usage and then

rr.putVariable("left_motor", 29)  

would cause the motor to get value 29.

As you have two levels of indirection here you've attempted to merge them into a single routine. This was probably done due to the confusion about set_parameter which is only rarely used and is never really needed for any GUI configuration that specifies a variable. The set_parameter is really only for those GUI items that use numbers or strings and do not understand variable values.

Hopefully this makes some sense ... please ask further questions if you are confused.

STeven.
Anonymous 10 years
Yes this makes sense. My next question is whether or not we can use the RoboRealm API and any of the current methods to receive encoder values from the motor driver and the motors for closed-loop control?

-Melanie
Anonymous 10 years
I assume you are using the Sabertooth motor driver? We are not aware that it has the ability to read any encoders. Or perhaps you are using something different to read encoders?

Normally with RoboRealm the closed loop is through vision although we will support encoder feedback if the hardware device also supports it.

STeven.
Melanie from United States  [21 posts] 10 years
We will use Vision Odometry and visual obstacle avoidance. I believe RoboRealm has both of these algorithms? How accurate are these techniques for outdoors vehicular navigation?
Anonymous 10 years
The accuracy of those techniques will vary depending on how quick your camera is (i.e. less motion blur the better), how bumpy the course is and many other factors that make it impossible to really know the answer to that question until you try it out. Keep in mind that if you plan to just use visual odometry in the same way as encoder odometry it will most likely NOT work. With vision the better technique is to think in terms of landmarks (that's more or less the way we do it). I.e. target a specific landmark and head towards that. If you need to go of course do so but then look again for that landmark after the obstacle has passed.

To make things easy, pick a known landmark (i.e. orange cone) and just try to have the robot head towards that. After that you can start thinking about natural landmarks that you can use for tracking. The visual anchor module may be useful in that regard.

What are the rules to the competition? Perhaps that will narrow the answers towards something more specific.

STeven.
Melanie from United States  [21 posts] 10 years
I changed the code and I get back true.
    result = rr.setVariable("left_motor", "29");
    System.out.println("Putting motor value "+result);

However, RoboRealm gives an error below. I'm using RoboRealm v. 1.8.2.0. Obviously this is some glitch:

"You need RoboRealm version 0.0 for this program to function correctly! Please upgrade by going to http://www.roborealm.com/"

I will answer your other question in another post soon.

Thanks!

-Melanie
Anonymous 10 years
Melanie,

Thanks for the tip, it was indeed a version error with the API. You can avoid it by removing the <head> part of the execute statement which is really optional ... or you can download tomorrow's release which will contain a fix for that.

STeven.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index