def rocket_callback(self, rocket_msg1): if rocket_msg1.state == 1: #print 'rocket callback in if' rocketMsg = rocket_msg() rocketMsg.state = 2 rocketMsg.timesFired = 4 self.rocketPub.publish(rocketMsg)
def launcherCallback(self, rocket_msg1): self.defenseState = rocket_msg1.state self.timesFired = rocket_msg1.timesFired rocketMsg = rocket_msg() rocketMsg.state = self.defenseState rocketMsg.timesFired = self.timesFired self.rocketPub.publish(rocketMsg)
def main_loop(self): self.init_publishers() #print "loop" self.init_subcribers() #self.init_params rate = rospy.Rate(10); self.rocket = armageddon.Armageddon() while not rospy.is_shutdown(): #print 'defense state = ', self.defenseState if self.defenseState == 0: if self.timer > 0: self.timer = self.timer - 1 #print self.timer #print 'lost ', self.lost #print 'yaw ', self.yawState #print 'pitch ', self.pitchState #print 'timesFired ', self.timesFired if self.lost is 0: self.lostCount = 0 if self.yawState is 0 and self.pitchState is 0: self.rocket.STOP() print "stop" else: #print "yaw: ", self.yawState, "pitch: ", self.pitchState if self.yawState is 1: self.rocket.RIGHT(10.0) elif self.yawState is -1: self.rocket.LEFT(10.0) elif self.yawState is 2: self.rocket.RIGHT(20.0) elif self.yawState is -2: self.rocket.LEFT(20.0) elif self.yawState is 3: self.rocket.RIGHT(40.0) elif self.yawState is -3: self.rocket.LEFT(40.0) if self.pitchState is 1: self.rocket.UP(20.0) elif self.pitchState is -1: self.rocket.DOWN(20.0) if self.fire is 1: self.rocket.FIRE() self.timer = 100 self.fire = 0 #print "fire" self.timesFired = self.timesFired +1 #print '\n\n', self.timesFired, '\n\n' rocketmsg = rocket_msg() rocketmsg.timesFired = self.timesFired if self.timesFired >= 4: self.defenseState = 1 rocketmsg.state = 1 else: self.defenseState = 0 rocketmsg.state = 0 self.rocketPub.publish(rocketmsg) else: #lost self.rocket.DOWN(100.0) self.lostCount = self.lostCount + 1 if self.lostCount >= 45: self.spinDirection = -self.spinDirection self.lostCount = 0 if self.spinDirection is 1: self.rocket.RIGHT(100.0) else: self.rocket.LEFT(100.0) #else: #print 'defense' rate.sleep()