Skip to content

Commit

Permalink
Merge branch 'cleanup'
Browse files Browse the repository at this point in the history
  • Loading branch information
JohsLoje committed May 13, 2018
2 parents 5b60bf1 + 8be3246 commit e5e0c8d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion flappy_automation_code/src/flappy_automation_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions flappy_main_game/scripts/flappy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
# laser specs
LASERFOV = 90
LASERRES = 9
LASERHZ = 30
ROTATING = 0

# scale pixels to meters
SCALING = 0.01
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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:
Expand Down
38 changes: 7 additions & 31 deletions flappy_main_game/scripts/laser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down
Binary file modified flappy_main_game/scripts/laser.pyc
Binary file not shown.

0 comments on commit e5e0c8d

Please sign in to comment.