Difference between revisions of "Category:HamsterAPIJavaTest"
Line 48: | Line 48: | ||
We have created a function to get the position of the robot and print it as long as we are connected. | We have created a function to get the position of the robot and print it as long as we are connected. | ||
In a second time we start the topic on ROS and we compare the values. | In a second time we start the topic on ROS and we compare the values. | ||
− | The purpose of this test is to verify that the positioning of the robot makes sense | + | The purpose of this test is to verify that the positioning of the robot makes sense. |
+ | |||
+ | <syntaxhighlight lang="bash" line='line'> | ||
+ | @Test | ||
+ | public void speedAndPosition(){ | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | We have created a function that recovers speed and position as long as we are connected to the robot. | ||
+ | The aim of this test is to verify the speed variations of the robots with respect to the position. | ||
+ | |||
+ | <syntaxhighlight lang="bash" line='line'> | ||
+ | @Test | ||
+ | public void navigationTest(){ | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | We created a function for the robot to navigate from point A to point B. | ||
+ | To be done: <br> | ||
+ | -First define the point A as the initial points and therefore define the initial position. | ||
+ | |||
+ | <syntaxhighlight lang="bash" line='line'> | ||
+ | Pose initial = new pose; | ||
+ | initial.setX(4.0f); | ||
+ | initial.setY(2.0f); | ||
+ | initial.setHeading(120.0f); | ||
+ | hamster.setInitialPose(initial); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | - In second time set goal to reach with position | ||
+ | |||
+ | <syntaxhighlight lang="bash" line='line'> | ||
+ | Goal goal = new goal; | ||
+ | goal.setX(4.0f); | ||
+ | goal.setY(2.0f); | ||
+ | goal.setHeading(120.0f); | ||
+ | hamster.navigateTo(goal); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Between the initial position and the goal we have to insert a thread.sleep(). | ||
== Test with robots == | == Test with robots == |
Revision as of 09:17, 9 July 2017
Tests in Java
How our Java tests works ?
before all test we have to be connected to the Robot so we beginning with the connection.
It is necessary to create an object hamster and it use all information about the Hamster class. Then we use we create a new HamsterClientParameters. It use to initialize the port and the base address of the Robot. and now we use the object Hamster that we created before with two parameters :
1- number agent of the robot
2- the name of the HamsterClientParameters that we created before.
We put this little function in a try catch of function with throws exception because if we can't be connected to the robot all the test after will failed.
Example : <syntaxhighlight lang="bash" line='line'> HamsterClientParameters params = new HamsterClientParameters(); params.port = 8101; params.base_address = "10.0.2"; Hamster hamster = new Hamster(1,params); </syntaxhighlight>
Test with simulation
Before launch our test we have to launch our simulation software Gazebo.
<syntaxhighlight lang="bash" line='line'> cd hamster_ws source devel/setup.bash </syntaxhighlight>
and then launch Gazebo :
<syntaxhighlight lang="bash" line='line'> roslaunch hamster_api_server_cpp hamster_api_simulation_server_and_gazbo_and_algs.launch </syntaxhighlight>
For the tests we created a test file where each test corresponds to a function
<syntaxhighlight lang="bash" line='line'> @Test public void positionCompareTopics(){ } </syntaxhighlight>
We have created a function to get the position of the robot and print it as long as we are connected. In a second time we start the topic on ROS and we compare the values. The purpose of this test is to verify that the positioning of the robot makes sense.
<syntaxhighlight lang="bash" line='line'> @Test public void speedAndPosition(){ } </syntaxhighlight>
We have created a function that recovers speed and position as long as we are connected to the robot. The aim of this test is to verify the speed variations of the robots with respect to the position.
<syntaxhighlight lang="bash" line='line'> @Test public void navigationTest(){ } </syntaxhighlight>
We created a function for the robot to navigate from point A to point B.
To be done:
-First define the point A as the initial points and therefore define the initial position.
<syntaxhighlight lang="bash" line='line'> Pose initial = new pose; initial.setX(4.0f); initial.setY(2.0f); initial.setHeading(120.0f); hamster.setInitialPose(initial); </syntaxhighlight>
- In second time set goal to reach with position
<syntaxhighlight lang="bash" line='line'> Goal goal = new goal; goal.setX(4.0f); goal.setY(2.0f); goal.setHeading(120.0f); hamster.navigateTo(goal); </syntaxhighlight>
Between the initial position and the goal we have to insert a thread.sleep().
Test with robots
To make the tests on the robots we use a software allowing us to know all the parameters of the robot such as the position on a map for example. To launch this software type the following command lines : <syntaxhighlight lang="bash" line='line'>
export ROS_MASTER_URI=http://10.0.2.1:11311
</syntaxhighlight> The address after http correspond to the robot's base address.
Now do an ifconfig and find the ip address that has just been added. <syntaxhighlight lang="bash" line='line'> ROS_IP=10.0.2. your address </syntaxhighlight>
And then launch rviz. <syntaxhighlight lang="bash" line='line'> rviz </syntaxhighlight>