From 1d9a716c968c7a0d6e6cb1e2b063676d71981ecb Mon Sep 17 00:00:00 2001 From: Johannes Date: Sun, 13 May 2018 15:34:09 +0200 Subject: [PATCH 1/2] Changed max to min angle in laser scan callback --- flappy_automation_code/scripts/flappy_automation_code_node.py | 2 +- flappy_automation_code/src/flappy_automation_code.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flappy_automation_code/scripts/flappy_automation_code_node.py b/flappy_automation_code/scripts/flappy_automation_code_node.py index 8ccf551..b384ee7 100755 --- a/flappy_automation_code/scripts/flappy_automation_code_node.py +++ b/flappy_automation_code/scripts/flappy_automation_code_node.py @@ -28,7 +28,7 @@ def velCallback(msg): def laserScanCallback(msg): # msg has the format of sensor_msgs::LaserScan # print laser angle and range - print "Laser range: {}, angle: {}".format(msg.ranges[0], msg.angle_max) + print "Laser range: {}, angle: {}".format(msg.ranges[0], msg.angle_min) if __name__ == '__main__': try: diff --git a/flappy_automation_code/src/flappy_automation_code.cpp b/flappy_automation_code/src/flappy_automation_code.cpp index c08f5e4..9bd4ac5 100644 --- a/flappy_automation_code/src/flappy_automation_code.cpp +++ b/flappy_automation_code/src/flappy_automation_code.cpp @@ -28,7 +28,7 @@ void laserScanCallback(const sensor_msgs::LaserScan::ConstPtr& msg) { //msg has the format of sensor_msgs::LaserScan //print laser angle and range - ROS_INFO("Laser range: %f, angle: %f", msg->ranges[0], msg->angle_max); + ROS_INFO("Laser range: %f, angle: %f", msg->ranges[0], msg->angle_min); } int main(int argc, char **argv) From 8be3246a5e2896b5ea3a1b7ca5fa6388c37fe347 Mon Sep 17 00:00:00 2001 From: Johannes Date: Sun, 13 May 2018 15:49:00 +0200 Subject: [PATCH 2/2] Code cleanup --- flappy_main_game/scripts/flappy.py | 6 ++--- flappy_main_game/scripts/laser.py | 38 ++++++----------------------- flappy_main_game/scripts/laser.pyc | Bin 3899 -> 3596 bytes 3 files changed, 9 insertions(+), 35 deletions(-) diff --git a/flappy_main_game/scripts/flappy.py b/flappy_main_game/scripts/flappy.py index 418ac70..2fd767a 100755 --- a/flappy_main_game/scripts/flappy.py +++ b/flappy_main_game/scripts/flappy.py @@ -22,8 +22,6 @@ # laser specs LASERFOV = 90 LASERRES = 9 -LASERHZ = 30 -ROTATING = 0 # scale pixels to meters SCALING = 0.01 @@ -215,7 +213,7 @@ def mainGame(movementInfo): #define publishers pub_velocity = rospy.Publisher('flappy_vel', Vector3, queue_size=10) # create laser - laser = Laser(LASERFOV,LASERRES,LASERHZ,SCALING,ROTATING) + laser = Laser(LASERFOV,LASERRES,SCALING) score = playerIndex = loopIter = 0 playerIndexGen = movementInfo['playerIndexGen'] playerx, playery = int(SCREENWIDTH * 0.13), movementInfo['playery'] @@ -362,7 +360,7 @@ def mainGame(movementInfo): bitmap = getBitmap(upperPipes,lowerPipes,(basex, BASEY)) # do raytracing with Laser playerMiddle = (playerx + IMAGES['player'][0].get_width() / 2,playery + IMAGES['player'][0].get_height() / 2) - laserPoints = laser.scan(playerMiddle,bitmap,pygame.time.get_ticks()) + laserPoints = laser.scan(playerMiddle,bitmap) # display if DEBUG == 1: diff --git a/flappy_main_game/scripts/laser.py b/flappy_main_game/scripts/laser.py index e359aa7..12bca41 100644 --- a/flappy_main_game/scripts/laser.py +++ b/flappy_main_game/scripts/laser.py @@ -5,35 +5,19 @@ #from std.msg import Float32 class Laser: - def __init__(self,fov,resolution,hz,scaling,rotating): + def __init__(self,fov,resolution,scaling): self.fov = fov #degrees self.angle_max = math.radians(fov/2.0) # radians self.angle_min = -math.radians(fov/2.0) # radians self.angle_increment = math.radians(fov/(resolution-1.0)) # radians self.resolution = resolution - self.sampleTime = 1000*1.0/hz - self.range = 355 - self.time = 0 + self.range = 355 #pixels self.laser_scan_publisher = rospy.Publisher("/flappy_laser_scan", LaserScan, queue_size=10) self.scaling = scaling - # For rotating Lidar - self.rotating = rotating - self.ray_counter = 0 - def scan(self,startPoint,bitmap,time): - # update with indicated hz - #time_diff = time-self.time - #if time_diff < self.sampleTime: - # return [] - #self.time = time-(time_diff % self.sampleTime) + def scan(self,startPoint,bitmap): pointcloud = [] - if self.rotating: - raysToCast = [self.ray_counter] - self.ray_counter += 1 - if self.ray_counter >= self.resolution: - self.ray_counter = 0 - else: - raysToCast = xrange(self.resolution) + raysToCast = xrange(self.resolution) for i in raysToCast: # calc endpoint from angle and range @@ -95,19 +79,11 @@ def _publish_laser_scan(self,pointcloud,startPoint): scan = LaserScan() scan.header.stamp = rospy.Time.now() scan.header.frame_id = 'laser_frame' - scan.range_min = 0.0 scan.range_max = self.range*self.scaling - - if self.rotating: - scan.angle_min = self.angle_max-(self.ray_counter*self.angle_increment) - scan.angle_max = scan.angle_min - scan.angle_increment = 0 - else: - scan.angle_min = self.angle_min - scan.angle_max = self.angle_max - scan.angle_increment = self.angle_increment - + scan.angle_min = self.angle_min + scan.angle_max = self.angle_max + scan.angle_increment = self.angle_increment scan.ranges = [] scan.intensities = [] diff --git a/flappy_main_game/scripts/laser.pyc b/flappy_main_game/scripts/laser.pyc index c3f9bed5e1376989526121025bd6274122d5c0a7..a95536f88ef98a69aa0123a86080167101513142 100644 GIT binary patch delta 928 zcmaJ=OKTHR6h3F3nO8E+vq@h{UCgFpr0AlGN_8bfnFxYVV%nrNLlxT@CCG$;Sro;E z_5O|`nxz|mhJV1diVNK+o^vPNI>Y(yx#uzGobTTGwESk#RDXK*y&J!e&96lb09bUA zO_KQa@!zf6Dx?4%6OtT67W6boZ0PCGGhm`1yBtWf7#Df~?ZBke)*b;r*JsN2Yl9sW zUvNzcJmD)3b6n)G`(#hNRW=&|mrWSr{{C*rN@z0_#E1NWI8wc_Pg_6>t60MZtrjle zj!L#1i9sSeo{~ZpM=B)1eMblrgpmfrBS<8EuhxVNfYLSnb z8h3fT4k78D)IBDgjrmih0K?CGU3zp1zPRkHnm#6T5EVt&Y4-CFm1H_`q(hlmq3oz2 z%|w?5b-HAA$<{kbW|l!Qw&d_X(URLTL>2MN*>I{nBngDBxa!_o<;lYWL1Ga|UOSJw z!%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