I am trying to understand a sample code in Webots (robot simulation program).
I have faced this code :
Servo rightShoulderPitch = getServo("RShoulderPitch");
rightShoulderPitch.setPosition(1.5);
I do not understand what is meat by the first line. It look like that "rightShoulderPitch" is an object of Servo class but it is not created as usual and how 'getServo' (i think it is a method) comes here .
This class's header is, if it helps:
public class FieldPlayer extends Robot {
Also it has description by the company in the reference manual, but I could not understand what they mean. It can be found here search for getservo.
--- RShoulderPitch: is the name of the shoulder of the robot
I will appriceite help very much.
Thanks
To complement Jon's excellent answer, I'll try to explain you in much more general terms.
When you want a sandwich, you have two solutions:
Sandwich s = new Sandwich()
Sandwich s = snackBar.getSandwich("Ham & Cheese")
.In the latter case, it's the snackBar object's getSandwich()
method which will use the name of the sandwich you want ("Ham & Cheese") to prepare a sandwich and return it for you. This method will thus probably, internally, call new Sandwich()
. But it could also delegate to another object and call, for example: cook.prepareSandwich("Ham & Cheese")
. And in this case, it's the cook object which will call new Sandwich()
. Or the snackBar object could also just get a sandwich that has been prepared in advance and stored in some cache: fridge.getSandwich("Ham & Cheese")
.