1
00:00:00,870 --> 00:00:06,990
In this lecture, we're going to go over using parameters in ROS to parameters are essentially dynamic

2
00:00:06,990 --> 00:00:09,810
variables which are associated with nodes.

3
00:00:09,990 --> 00:00:15,780
These dynamic variables have information stored in it which can be set, retrieved or changed freely.

4
00:00:16,290 --> 00:00:22,650
Parameters can have a variety of uses like keeping track of the state of a system or have data related

5
00:00:22,650 --> 00:00:24,720
to, say, physical attributes of the robot.

6
00:00:25,810 --> 00:00:31,900
Let's go ahead and open up a terminal and run our RPM pub node we created in the publishers and subscriber

7
00:00:31,900 --> 00:00:32,650
project.

8
00:00:41,440 --> 00:00:47,170
Once it's running, we'll go ahead and open a new terminal tab and launch the speed publisher we created

9
00:00:47,170 --> 00:00:48,430
in the same project.

10
00:00:53,040 --> 00:00:57,750
We'll open another terminal tab and we're going to run Ross to parameter list.

11
00:00:58,350 --> 00:01:02,230
Here we can see a list of parameters sorted by Node.

12
00:01:02,250 --> 00:01:07,600
In this case, both our nodes have one parameter called use SIM time.

13
00:01:07,620 --> 00:01:10,230
This is a default parameter added to nodes.

14
00:01:10,860 --> 00:01:15,700
We can see the value of this node by using the ROS two parameter get command.

15
00:01:15,720 --> 00:01:17,760
This command takes in the name of the package.

16
00:01:17,760 --> 00:01:22,800
So for instance, we can do the RPM publisher node and then the name of the parameter we want to see

17
00:01:22,800 --> 00:01:23,310
the value of.

18
00:01:23,340 --> 00:01:30,690
In this case, use SIM time so we can see the parameter is set to false by default, which means it's

19
00:01:30,690 --> 00:01:33,630
using the time on our computer instead of a time from a simulation.

20
00:01:33,630 --> 00:01:37,920
You can set it to true if you wanted to use the time being generated by a simulation you had running.

21
00:01:38,340 --> 00:01:43,200
If you want to see more information about a parameter, you can use the ROS two parameter type command

22
00:01:43,200 --> 00:01:45,120
with the same arguments.

23
00:01:45,360 --> 00:01:49,380
Here we can see the type and any constraints the parameters may have.

24
00:01:50,250 --> 00:01:50,550
All right.

25
00:01:50,550 --> 00:01:52,710
So I'm going to go ahead and stop all of these nodes.

26
00:01:54,280 --> 00:01:54,670
All right.

27
00:01:54,670 --> 00:01:57,880
So how can parameters be useful for us in our Ross code?

28
00:01:58,030 --> 00:02:04,930
Well, in my RPM pub node, I hardcoded the value of our RPM to simulate a wheel encoder sensor going

29
00:02:04,930 --> 00:02:06,310
at a constant rate.

30
00:02:06,490 --> 00:02:11,590
Instead, let's use a parameter so that if someone wants to change the RPM value, they don't have to

31
00:02:11,590 --> 00:02:12,940
edit my source code.

32
00:02:13,360 --> 00:02:15,400
We also did this in the speed calc notes.

33
00:02:15,410 --> 00:02:19,180
If I go ahead and open that up, we hardcoded in a wheel radius.

34
00:02:19,210 --> 00:02:23,080
Now this is a potential value we would change if we were using it with a different robot, which makes

35
00:02:23,080 --> 00:02:25,070
it prime to use it as a parameter.

36
00:02:25,090 --> 00:02:29,890
So let's go ahead and use a parameter by using the declared parameter function right after I initialize

37
00:02:29,890 --> 00:02:36,580
my node to create a parameter called wheel radius and set the default value to our wheel radius variable.

38
00:02:36,940 --> 00:02:41,740
To make this a bit more clear, I will just state that this is the default wheel radius variable.

39
00:02:51,730 --> 00:02:56,680
So for the time being, I'll just also set this wheel radius variable here to wheel radius default.

40
00:02:57,310 --> 00:02:59,920
But we'll be changing this to use our parameter in a bit.

41
00:02:59,920 --> 00:03:05,710
But before we do that, I want to print out some things about our parameter so you can see how it works.

42
00:03:05,710 --> 00:03:08,460
So we can use the get parameter function of our node.

43
00:03:08,470 --> 00:03:13,210
So this function will return a parameter object in order to get the actual value from the parameter.

44
00:03:13,210 --> 00:03:17,000
We have to use the get parameter value method of this particular class.

45
00:03:17,000 --> 00:03:18,160
So we'll go ahead and print it out.

46
00:03:18,550 --> 00:03:22,330
We will have to include one more thing, but let's just see what this looks like so far.

47
00:03:22,330 --> 00:03:24,700
So I'll go ahead and save the file.

48
00:03:24,820 --> 00:03:30,490
And since we're using can build Simulink install, we don't need to recompile our workspace and instead

49
00:03:30,490 --> 00:03:34,480
I'll just head over to our terminal where we are running our speed calc node.

50
00:03:34,630 --> 00:03:39,160
And if I run it, we get this bound method, get parameter value.

51
00:03:39,160 --> 00:03:43,150
And so that's actually because I forgot to put the parentheses to actually call this function.

52
00:03:43,390 --> 00:03:44,440
Let's try this one more time.

53
00:03:44,440 --> 00:03:45,310
Save that.

54
00:03:49,640 --> 00:03:50,750
And we'll rerun the node.

55
00:03:51,170 --> 00:03:55,030
So here we can see printing through the screen the contents of the parameter value message type.

56
00:03:55,040 --> 00:03:59,930
We can see this parameter is type three, which means it is of a type double.

57
00:03:59,930 --> 00:04:07,040
And in the double value section we see the value is 0.125, which is the value we set the default wheel

58
00:04:07,040 --> 00:04:07,820
radius variable.

59
00:04:07,820 --> 00:04:14,480
As we can also see, this parameter is available if we use the ROS two parameter list command and then

60
00:04:14,480 --> 00:04:15,860
use raw super and get.

61
00:04:21,750 --> 00:04:26,910
If we wanted to, we could set a different value for this parameter using the ROS two parameter set

62
00:04:26,910 --> 00:04:27,630
command.

63
00:04:27,660 --> 00:04:31,440
In this case, I can set the wheel radius to 0.5.

64
00:04:34,210 --> 00:04:41,590
And now if I get this parameter one more time, we see that it is indeed changed to 0.5 and this will

65
00:04:41,590 --> 00:04:43,390
also take effect within our node.

66
00:04:43,420 --> 00:04:49,840
So let's go ahead and wrap this up by adjusting our speed calc node to instead use this parameter value

67
00:04:49,840 --> 00:04:52,780
instead of the default wheel radius variable we used.

68
00:05:09,650 --> 00:05:12,770
And we will call the double value to get.

69
00:05:13,990 --> 00:05:17,800
The particular value stored in this double value part of the object.

70
00:05:18,250 --> 00:05:20,500
And I'll go ahead and stop this node from running.

71
00:05:23,950 --> 00:05:28,390
And we can go ahead and change instead of using this default wheel radius variable to instead use the

72
00:05:28,390 --> 00:05:29,080
parameter.

73
00:05:30,900 --> 00:05:37,050
All right, So now in our calculate speed publisher, we check for what the value of the wheel radius

74
00:05:37,050 --> 00:05:40,500
parameter is and get the double value of it.

75
00:05:41,210 --> 00:05:45,620
Then we calculate the speed using that parameter value.

76
00:05:46,190 --> 00:05:46,520
Great.

77
00:05:46,520 --> 00:05:49,820
So with that, we can go ahead and save this speed calc node.

78
00:05:51,150 --> 00:05:52,290
Open up a terminal.

79
00:05:53,150 --> 00:05:54,140
Now click the screen.

80
00:05:55,690 --> 00:05:59,860
And now if I rerun both my speed calc node and my RPM pub node.

81
00:06:01,990 --> 00:06:07,960
I can go ahead and clear the screen on my third terminal and echo out the speed topic.

82
00:06:10,830 --> 00:06:11,190
All right.

83
00:06:11,190 --> 00:06:14,940
So here we see the information coming in from the speed topic.

84
00:06:16,670 --> 00:06:20,600
And if I open up a fourth terminal, I can go ahead and change the parameter value.

85
00:06:20,600 --> 00:06:27,380
So, Ross two parameter set the name of the node and then the name of the parameter we want to change.

86
00:06:27,380 --> 00:06:31,100
So in this case, I'll set the wheel radius parameter to 0.5.

87
00:06:32,230 --> 00:06:36,760
And now that the parameters change, we see that our speed calculations have also changed with it.

88
00:06:36,760 --> 00:06:42,040
So it is successfully using our parameter to help calculate the given speed of our robot.

89
00:06:42,730 --> 00:06:43,720
Congratulations.

90
00:06:43,720 --> 00:06:47,980
You successfully implemented parameters in your very own ROS to code.

91
00:06:48,190 --> 00:06:52,990
It is worth noting that if you have multiple nodes that you want to share parameter values with, you

92
00:06:52,990 --> 00:06:58,240
can use ROS services to request the parameter variables between nodes.

93
00:06:58,270 --> 00:07:01,870
Now we'll learn about services later on in the course, so don't worry about it for now.

94
00:07:02,570 --> 00:07:05,030
In this lecture, we talked about parameters.

95
00:07:05,030 --> 00:07:11,240
We went over a few different terminal commands such as RAS, Super M list, get and set in order to

96
00:07:11,240 --> 00:07:15,200
look at our parameters and see what their values are as well as set them.

97
00:07:15,710 --> 00:07:21,770
We then learn how to use parameters in Python by utilizing the declare parameter function of our node,

98
00:07:21,770 --> 00:07:25,310
which we pass in a parameter name and a particular value.

99
00:07:25,340 --> 00:07:30,530
We can then utilize our nodes, get parameter command to then get this parameters value.

100
00:07:31,810 --> 00:07:37,060
In the next lecture, we'll be learning about launch files where we can automate the launching of nodes

101
00:07:37,060 --> 00:07:39,880
as well as setting of parameter values.
