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) 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 c3f9bed..a95536f 100644 Binary files a/flappy_main_game/scripts/laser.pyc and b/flappy_main_game/scripts/laser.pyc differ