# Quiz4 Grade Check Performance

**URL:** <https://get-help.theconstruct.ai/t/quiz4-grade-check-performance/21156>\
**Category:** ROS2 Basics in 5 Days (Python)\
**Tags:** quiz\
**Created:** [December 26, 2022, 4:11am UTC](https://get-help.theconstruct.ai/t/quiz4-grade-check-performance/21156 "2022-12-26T04:11:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Genozen](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/genozen/32/5897_2.png) [@Genozen](https://get-help.theconstruct.ai/u/Genozen)\
**Post date:** [December 26, 2022, 4:11am UTC](https://get-help.theconstruct.ai/t/quiz4-grade-check-performance/21156/1 "2022-12-26T04:11:44Z")

</div>

![image](https://get-help.robotigniteacademy.com/uploads/default/original/2X/9/986fe8fcd37e74ab37d5b7ce244b104f51873a4e.png)

Hello, I passed almost all the checkpoints. My testing environment shows that the robot was able to turn with specified direction, angular\_velocity, and time.

Here’s my client side:

```auto
    def send_request(self):

        print(sys.argv)
        # send the request
        self.req.direction = sys.argv[1]
        self.req.angular_velocity = float(sys.argv[2])
        self.req.time = int(sys.argv[3])

        # uses sys.argv to access command line input arguments for the request.
        self.future = self.client.call_async(self.req)
        # to print in the console

```

My shell command is as follow:  
`ros2 run services_quiz services_quiz_client right 5.0 10`

my server side is:

```auto
    def custom_service_callback(self, request, response):
        # The callback function receives the self-class parameter,
        # received along with two parameters called request and response
        # - receive the data by request
        # - return a result as a response

        # create a Twist message
        msg = Twist()

        if request.direction == "right":
            # define the linear x-axis velocity of /cmd_vel topic parameter to 0.1
            # msg.linear.x = 0.1
            # define the angular z-axis velocity of /cmd_vel topic parameter to -0.5 to turn right
            msg.angular.z = -(request.angular_velocity)
            # Publish the message to the topic
            self.publisher_.publish(msg)
            # print a pretty message
            self.get_logger().info('Turning to right direction!!')
            # response state

            start_time = time.time()
            while(time.time() - start_time < request.time):
                pass

            msg.angular.z = 0.0
            self.publisher_.publish(msg)

            response.success = True
        elif request.direction == "left":
            # define the linear x-axis velocity of /cmd_vel topic parameter to 0.1
            # msg.linear.x = 0.1
            # define the angular z-axis velocity of /cmd_vel topic parameter to 0.5 to turn left
            msg.angular.z = request.angular_velocity
            # Publish the message to the topic
            self.publisher_.publish(msg)
            # print a pretty message
            self.get_logger().info('Turning to left direction!!')
            # response state

            start_time = time.time()
            while(time.time() - start_time < request.time):
                # print(time.time() - start_time, request.time)
                pass
            msg.angular.z = 0.0
            self.publisher_.publish(msg)

            response.success = True
        # elif request.move == "Stop":
        # # define the linear x-axis velocity of /cmd_vel topic parameter to 0
        # msg.linear.x = 0.0
        # # define the angular z-axis velocity of /cmd_vel topic parameter to 0
        # msg.angular.z = 0.0
        # # Publish the message to the topic
        # self.publisher_.publish(msg)
        # # print a pretty message
        # self.get_logger().info('Stop there!!')
        # # response state
        # response.success = True
        else:
            # response state
            response.success = False

        # return the response parameter
        return response

```

I did import python `time` module to keep track of how many seconds, not sure if this is the desired way.

with the command `ros2 run services_quiz services_quiz_client right 0.2 10`  
I get less than 90 degree-ish  
 ![image](https://get-help.robotigniteacademy.com/uploads/default/original/2X/f/fac779d93513977f31755db27dba0a52c7646574.png)  
 ![image](https://get-help.robotigniteacademy.com/uploads/default/original/2X/e/eee6470bddacdb347eddfe4b009c66865c4d2136.png)

======= update ======

Got a little closer, but still unable to pass the 7 marker  
Using time with `self.get_clock().now().seconds_nanoseconds()[0]`

![image](https://get-help.robotigniteacademy.com/uploads/default/original/2X/c/cb3e9576cd5f093e6d9f193131481d5ea4da7056.png)

I noticed the robot will move slightly over time even though the Response state (client) has ended, carried by some momentum (the change is very small)

---

<div class="post-metadata">

**Author:** ![albertoezquerro](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/albertoezquerro/32/7031_2.png) [@albertoezquerro](https://get-help.theconstruct.ai/u/albertoezquerro)\
**Post date:** [December 26, 2022, 9:59am UTC](https://get-help.theconstruct.ai/t/quiz4-grade-check-performance/21156/2 "2022-12-26T09:59:12Z")

</div>

Hello @Genozen ,

Your client has to contain the values to be sent to the server inside the code. This means, you cannot capture the values from the command with `sys.argv[1]`. This is because the correction script is going to launch the client like this:

`ros2 launch services_quiz services_quiz_client.launch.py`

Without specifying any values in the command.

---

<div class="post-metadata">

**Author:** ![Genozen](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/genozen/32/5897_2.png) [@Genozen](https://get-help.theconstruct.ai/u/Genozen)\
**Post date:** [December 26, 2022, 10:04pm UTC](https://get-help.theconstruct.ai/t/quiz4-grade-check-performance/21156/3 "2022-12-26T22:04:23Z")

</div>

Thank you! this was the missing info I needed!

---

<div class="post-metadata">

**Author:** ![system](https://get-help.theconstruct.ai/uploads/default/original/2X/9/9d3ce8305cc0d0d9b6e07d15767a6f245c526f1b.jpeg) [@system](https://get-help.theconstruct.ai/u/system)\
**Post date:** [December 31, 2022, 10:04pm UTC](https://get-help.theconstruct.ai/t/quiz4-grade-check-performance/21156/4 "2022-12-31T22:04:40Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
