[Rosject] ROS2 Basics Part 2: Services

Hello,

I am currently working on Part 2 of the Rosject. After so much trial and error and reading the forum for hints to keep on pushing forward, I confused myself on how services and callbacks work. I tried to reread both sections of the course, but it doesn’t really answer the questions I run into. I was debating if I should even post my code for someone to take a look at it since I do not truly know what is going on. There are two specific questions I have. The first one just occured recently where the laser_callback was grabbing the data and I could use it for the behavior_callback, but now it does not. The main question I have is how can I slow down the while loop I have for my behavior_callback? I tried to use time.sleep; however, it would switch from the wall_finder.py to wall_follower.py (back and forth). I tried to add some sort of timer, but it wasn’t helping either. I was just testing out trying to solve the angle problem by just using indexes. Also, I would appreciate any feedback on other parts of my code (motion() works for me). At this point, I may need to redo everything for part 2, but I do not want to do that.

I do not know how to post my entire code on here. I tried uploading but it only uploads jpegs, etc.



Any help would be appreciated! I will do my best to explain my code, but just know that I may not be able to answer some questions.

Godspeed,

Hi @damart35.

I apologize for the confusion. I think this arises from an error we have in out project instructions.

I see that you are already trying to introduce callback groups (although they are commented now) and that is the correct path to go down, in order for your program to be able to handle multiple callbacks.

The error I talk about is that you are instructed to start with the service part of the project before you can go through the next units: Callbacks and Multi threading

This section will give you everything you need to successfully complete the service part of the project.

I will switch the instructions to the appropriate unit now. Thank you for pointing us to the error.

Hello,

Thank you for clarifying the project, but that was not what I meant. However, I got the server to work in a proper manner, but I do not think it is the proper way to access it. It works for now, so I will leave it as is. Here is what I am talking about

You see how I used the Wall_Following() class twice. I am not sure why, but without lines 146 and 147, the rest of wall_follower.py does not start (shown below). With those lines, it goes straight into wall_following function.

Can anyone explain why this happens? For now I will just keep it like that since it works.


The problem I am facing now are the laser readings. I noticed that, in wall_finding.py, the indexing of the robot is different from when I used them for part 1 of the project. I setup the bot so that the left side is the closest to the wall. Instead, I get a different index which is always on the right side.

Before:

After:

I am still working on the logic of the while loop, so for now, the bot moves at angular velocity of 2.0 in any direction depending if it is greater or less than front laser index. The problem here is that it should have detected the wall on its left side using min(msg.ranges). I think I used the laserscan wrong for part 1 of the project for simulation, yet it worked on the real robot. What am I missing or not considering? I did update the code just a little from the previous pictures, so if need be, I can post them again. (Also, laser_forward_idx = 359, just in case that is part of the problem)

Sincerely,

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