Smart sentry gun6/20/2023 ![]() Yaw_stepper. Serial.print("Current angle: ") Serial.println(current_angle) Serial.print("Steps taken: ") Serial.println(steps_taken) Ĭurrent_angle = steps_taken / STP_PER_DEG_PITCH Serial.print("Target locked at location X: ") Serial.print(x) Serial.print(", Y: ") Serial.println(y) Serial.print("Target seen at location X: ") Serial.print(x) Serial.print(", Y: ") Serial.println(y) Move_pitch(target_angle - current_angle) Here is a video demonstrating the gun working:Ĭonst int pins = //MX STEP, DIR, EN, MY STEP, DIR, ENĬonst int limit_switch = 26, laser_pin = 11, spool_pin = 10, servo_pin = 13, distance_trig = 29, distance_echo = 30 įloat hyp_distance //distance from gun to target in metersīasicStepperDriver pitch_stepper(MOTOR_STEPS_X, pins, pins) īasicStepperDriver yaw_stepper(MOTOR_STEPS_X, pins, pins) It did well, as my program calibrates and adjusts the angle for the measured distance. I put a neon pink index card to the wall to test the gun’s accuracy. This removes some of the rotating mass from the gimbal setup, putting less strain on the servos, but moves the center of gravity forward, making the gun harder to balance in the beginning. The MOSFET then switches the motor off and then the nerf gun returns to looking for targets. On the plus side, it prevents the center of gravity from moving as the tank empties over time. After it has spooled up for five seconds it then moves the servo motor to pull the trigger. The Sentry Gun functions as an automated turret that fires at the closest enemy within its range and line of sight. The gun then moves to this position and turns on the motors via a MOSFET. My code has a function called get_angle() which uses these two distances to calculate how much of an angle is needed to hit that target. By using this distance, the horizontal and vertical distances can be found by using some basic trigonometric functions. Then the gun moves until the target is centered in the Pixy’s view, where its distance from the gun barrel to the target is then measured. The different states go as follows:Īcquiring the target involves first setting up the Pixy to track neon pink objects as targets. I started by writing out the program flow and logic step-by-step, detailing what would happen at each machine state. A projectile-firing machine is very complex, and the math behind it can be confusing. Now for the most difficult part of the project: programming.
0 Comments
Leave a Reply. |