Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

各naviモードインスタンスの初期化処理をpuperun.__init__内で統一 #58

Merged
merged 6 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions burger_war_dev/scripts/navi/waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Waypoint:

next_lap_flag = False
count_waypoint = 0
waypoint_reverse_flag_for_blue = True

def __init__(self, path_waypoints, path_waypoints_depending_on_score):

Expand All @@ -30,33 +29,32 @@ def __init__(self, path_waypoints, path_waypoints_depending_on_score):
lines = csv.reader(f)
for l in lines:
point = [float(i) for i in l]
# print(point)
self.points.append(point[0:3])

with open(path_waypoints_depending_on_score) as f_score:
lines_score = csv.reader(f_score)
for l_score in lines_score:
point_depending_on_score = [float(i_score) for i_score in l_score]
# print(point)
self.points_depending_on_score.append(point_depending_on_score[0:3])

def warStateCallBack(self, data):
self.warState = data
print('get data!')
print(self.warState.enem_get_wall_marker_no)
Comment on lines -43 to -46
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

イケムラデバック用に,ここのprint残しといてくれん??笑

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

printするのってself.warState.enem_get_wall_marker_noだけでいい?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

それで大丈夫!


if Waypoint.waypoint_reverse_flag_for_blue:
# blue side の場合は,180度ひっくり返す
if self.warState.my_side == 'b':
for i, point in enumerate(self.points_depending_on_score):
self.side = rospy.get_param('/send_id_to_judge/side')
self.change_points_depending_on_score_with_side(self.side)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sideの判定はwarstateのコールバックではなくて、初期化時にrospy.get_paramで取得することにした

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'/send_id_to_judge/side'setup_sim.shの中で定義されていて、対戦開始時には確実にrosparamに設定されていると考えられるため、初期化時に一回rospy.get_paramをすれば取得できると判断した。



def change_points_depending_on_score_with_side(self, side):
if side not in ['r', 'b']:
raise ValueError("'side' param must be in ['r', 'b'], given: {}\n\
please confirm with 'rosparam get /send_id_to_judge/side'".format(side))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

将来的にサイドの設定を積極的に変更するときに、
'b'のつもりが'B'とかにして、意図したとおりに設定できていないという事態を認知できるようにValueErrorを作った

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.side=Noneにするとちゃんとエラーを吐いた

Traceback (most recent call last):
  File "/home/developer/catkin_ws/src/burger_war_dev/burger_war_dev/scripts/pupeRun.py", line 83, in <module>
    bot = PupeBot('Puperun')
  File "/home/developer/catkin_ws/src/burger_war_dev/burger_war_dev/scripts/pupeRun.py", line 27, in __init__
    self.navi_basic = NaviBasic()
  File "/home/developer/catkin_ws/src/burger_war_dev/burger_war_dev/scripts/navi/naviBasic.py", line 39, in __init__
    self.waypoints = Waypoint(self.path_waypoints, self.path_waypoints_depending_on_score)
  File "/home/developer/catkin_ws/src/burger_war_dev/burger_war_dev/scripts/navi/waypoint.py", line 41, in __init__
    self.change_points_depending_on_score_with_side(None)
  File "/home/developer/catkin_ws/src/burger_war_dev/burger_war_dev/scripts/navi/waypoint.py", line 47, in change_points_depending_on_score_with_side
    please confirm with 'rosparam get /send_id_to_judge/side'".format(side))
ValueError: 'side' param must be in ['r', 'b'], given: None
            please confirm with 'rosparam get /send_id_to_judge/side'
[pupeRun-1] process has died [pid 28700, exit code 1, cmd /home/developer/catkin_ws/src/burger_war_dev/burger_war_dev/scripts/pupeRun.py __name:=pupeRun __log:=/home/developer/.ros/log/cb3cb072-71d4-11ec-b1c1-be596e283c47/pupeRun-1.log].
log file: /home/developer/.ros/log/cb3cb072-71d4-11ec-b1c1-be596e283c47/pupeRun-1*.log

elif side == "b":
# blue side の場合は,180度ひっくり返す
for i, _ in enumerate(self.points_depending_on_score):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enumerateの第二返り値は今回ひつようないので_にしてメモリを節約

self.points_depending_on_score[i][0] *= -1
self.points_depending_on_score[i][1] *= -1
self.points_depending_on_score[i][2] -= 3.141592654

print('my side:', self.warState.my_side)
print(self.points_depending_on_score)
Waypoint.waypoint_reverse_flag_for_blue = False

def warStateCallBack(self, data):
self.warState = data
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warStateCallBack自体はほかのメソッドでself.warStateの更新を期待しているので残す必要がある


def get_next_waypoint(self):
print(self.warState.enem_get_wall_marker_flag)
Waypoint.count_waypoint = Waypoint.count_waypoint + 1
Expand Down
11 changes: 7 additions & 4 deletions burger_war_dev/scripts/pupeRun.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ def __init__(self, bot_name="NoName"):
# mode
self.mode = ActMode.basic
self.mode_prev = ActMode.basic
self.navi = NaviBasic()
self.modeDecider = ModeDecider()

#initialize navis
self.navi_basic = NaviBasic()
self.navi_attack = NaviAttack2()
self.navi = self.navi_basic
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

各naviモードの初期化は最初に行う


# subscriber
self.imgInfo_sub = rospy.Subscriber('img_info', ImgInfo, self.imgInfoCallBack)
self.imgInfo = ImgInfo()
Expand Down Expand Up @@ -59,11 +63,10 @@ def selectModeCallBack(self, state):
print(self.mode, self.mode_prev)
if self.mode != self.mode_prev:
if self.mode==ActMode.basic:
self.navi = NaviBasic()
self.navi = self.navi_basic
elif self.mode==ActMode.attack:
# self.navi = NaviAttack()
print("select attack mode")
self.navi = NaviAttack2()
self.navi = self.navi_attack

self.mode_prev = self.mode

Expand Down