Skip to content

Commit

Permalink
fixed format errors based on pylint message
Browse files Browse the repository at this point in the history
  • Loading branch information
MaryUME committed Nov 13, 2024
1 parent 1a8c35f commit 23b0db0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
13 changes: 8 additions & 5 deletions rb_ws/src/buggy/buggy/simulator/velocity_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
class VelocityUI(Node):
def __init__(self, init_vel: float, buggy_name: str):
super().__init__('velocity_ui')

# So the buggy doesn't start moving without user input
self.buggy_vel = 0
self.buggy_vel = 0
self.controller = Controller(buggy_name)
self.lock = threading.Lock()

Expand All @@ -21,22 +21,25 @@ def __init__(self, init_vel: float, buggy_name: str):
self.root.geometry('600x100')
self.root.configure(background='#342d66')

self.scale = tk.Scale(self.root, from_=0, to=300, orient=tk.HORIZONTAL, length=500, width=30)
self.scale = tk.Scale(self.root, from_=0, to=300, orient=tk.HORIZONTAL,
length=500, width=30)
self.scale.pack()

self.root.bind("<Up>", lambda i: self.scale.set(self.scale.get() + 2))
self.root.bind("<Down>", lambda d: self.scale.set(self.scale.get() - 2))

# ROS2 timer for stepping
self.create_timer(0.01, self.step) # equivalent to 100Hz (100 times per second)
# 0.01 is equivalent to 100Hz (100 times per second)
self.create_timer(0.01, self.step)

def step(self):
# Sets the velocity of the buggy to the current scale value
# called every tick
self.root.update_idletasks()
self.root.update()
# Update velocity of the buggy
self.buggy_vel = self.scale.get() / 10 # set velocity with 0.1 precision
# '/10' set velocity with 0.1 precision
self.buggy_vel = self.scale.get() / 10
self.controller.set_velocity(self.buggy_vel)

def main(args=None):
Expand Down
9 changes: 5 additions & 4 deletions rb_ws/src/buggy/buggy/simulator/velocity_updater.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
#! /usr/bin/env python3
import sys
import math
import rclpy
from rclpy.node import Node
import sys
from controller_2d import Controller
from geometry_msgs.msg import Pose
from geometry_msgs.msg import Point
import threading
import math

class VelocityUpdater(Node):
RATE = 100
# Bubbles for updating acceleration based on position
# represented as 4-tuples: (x-pos, y-pos, radius, acceleration)
# need further update such as more data or import data from certain files
CHECKPOINTS = [
(589701, 4477160, 20, 0.5)
]

def __init__(self, init_vel: float, buggy_name: str):
super().__init__('vel_updater')

self.buggy_vel = init_vel
self.accel = 0.0
self.position = Point()
Expand Down Expand Up @@ -52,7 +53,7 @@ def calculate_accel(self):
in self.CHECKPOINTS, and update acceleration of buggy accordingly
'''
for (x, y, r, a) in self.CHECKPOINTS:
dist = math.sqrt((x - self.position.x)**2 + (y - self.position.y)**2)
dist = math.sqrt((x-self.position.x)**2 + (y-self.position.y)**2)
if dist < r:
self.accel = a
break
Expand Down

0 comments on commit 23b0db0

Please sign in to comment.