Jump to content


Clark3DPR

Member Since 09 Oct 2019
Offline Last Active Today, 02:21 AM

#364286 Cyberpunk 2077 Kang Tao 3D Printed Nerf Gun

Posted by Clark3DPR on 09 November 2019 - 09:14 PM

Part 5 - Arduino Code

 

Use the following code with the schematic in the last post to give you a better idea of what does what.

There was much research, trial and error to get the code working, but here it is:

const int buttonPinF = 2;      // Flywheel Rev microswitch pin number
const int buttonPinS = 5;      // Solenoid microswitch pin number
int buttonStateF = 0;             // Variable for reading the Flywheel Rev microswitch status
int buttonStateS = 0;             // Variable for reading the Solenoid microswitch status
int solenoidPin = 4;              // Solenoid MOSFET Gate pin number

#include <Servo.h>

Servo throttle;

int pos = 0;
int pin = 3;                            // ESC signal pin

void setup() {
  
   pinMode(buttonPinF, INPUT); 	       // Initialize the Flywheel microswitch pin as an input
   pinMode(buttonPinS, INPUT); 	       // Initialize the Solenoid microswitch pin as an input
   throttle.attach(pin);
   pinMode(solenoidPin, OUTPUT);         // Sets Solenoid MOSFET Gate pin as an output
    
 // ESC Arming Sequence
   for (pos = 90; pos <= 91; pos += 1) { 
      throttle.write(pos);             
      delay(3700);                                         // Wait for ESC to arm / Exit safety mode

// Increase this 3700 value depending on how long it takes for your ESC to arm

   }
}

void loop() {
  
    buttonStateF = digitalRead(buttonPinF);  // Read state of Flywheel microswitch value
 
    if (buttonStateF == HIGH) {  // Check microswitch pressed, if so Flywheel buttonState is HIGH
    throttle.write(92);                 // <(92) = Motor off / (92) = Idle speed
  } else {
    throttle.write(97);                // Motor on (92) = Idle speed / ~(115) = Max speed
  }

buttonStateS = digitalRead(buttonPinS);    // Read state of Solenoid microswitch value

  if (buttonStateF == LOW && buttonStateS == LOW) {
  digitalWrite(solenoidPin, HIGH);           // Switch Solenoid ON
  delay(90);                                                // ON duration
  digitalWrite(solenoidPin, LOW);           // Switch Solenoid OFF
  delay(100);                                             // OFF duration
   } else {
      digitalWrite(solenoidPin, LOW);      // Switch Solenoid OFF
  }
}
 
Uploading the Code
 
Caution: Do not power the Arduino with battery while USB is connected! This could damage the Arduino and/or your laptop/PC. Unplug Lipo Battery before plugging Arduino into PC via USB cable. Unplug USB cable before reconnecting the Lipo Battery. Earth yourself before touching Arduino to avoid static damage to Arduino.
 
Requires a PC / Laptop and the Arduino IDE Software. Copy this code, paste code in software, then upload to Arduino via USB cable.
 
LH5k3oW.jpg
There was a hole cut out of the bottom part and the Arduino's USB port sticking through it. This allows easy access without having to open up everything.
 
How to adjust the code
 
1. When Arduino is powered on via the safety switch, it runs the arming sequence for the brushless ESC's. My ESC's take 3.7secs, 'delay(3700)' in the code. You may have to increase this value up to 10000 (10secs) depending on your own ESC to get it to exit safe mode.
 
2. Hold secondary microswitch to rev flywheels, then press or hold primary microswitch to fire. The '&&' in 'if (buttonStateF == LOW && buttonStateS == LOW)' line of code tells the primary trigger to fire only while the secondary trigger is also held. This helps prevent jams.
 
3. Change 'throttle.write(92)' to increase/decrease motor idling speed or turn them off. By default motors will spin at low speed to decrease rev up time. (Value depends on your motor / ESC but should be around 92)
Change 'throttle.write(97)' to change motor top speed and dart velocity. (Value depends on your motor / ESC, but should be around 115)
 
4. Press or hold primary microswitch to fire solenoid.
 
5. Change 'delay(90)' and 'delay(100)' to increase/decrease fire rate of solenoid.
 
6. When Microswitches are released, ESC PWM signal for flywheels returns to idle rev speed (92) and signal to MOSFET gate for solenoid stops activating.
 
7. When ESC's lose signal from Arduino (when safety switch is on and Arduino powered off), the ESC's revert to safe mode and turn off motors.
 
You can create your own code or modify this code to add functionality such as select fire (full auto, burst & single fire), or a knob (potentiometer) to adjust the speed of the flywheels.
 
 
Hope this helps, and ask questions or suggestions below etc (I'm no expert with coding though), happy to help.

  • 1


#364278 Cyberpunk 2077 Kang Tao 3D Printed Nerf Gun

Posted by Clark3DPR on 04 November 2019 - 04:32 AM

Part 4 - Electronics
 
Alright, so here is where it gets technical.
 
Schematic
 
GD9GSTL.jpg
 
Drawn to illustrate how everything is connected. An Arduino Nano is used because of it's small size. This should work with a Uno and others too.
 
Refer to this schematic for the below terminologies MS1, C2 etc.
 
Arduino Code will be provided in the next post, as well as an explanation on how to use it, which values you can change in it etc.
 
How it all works
 
W0IZPpW.jpg
 
The way it works, is that when MS2 (secondary microswitch trigger) is held, the brushless motors rev up.
 
When MS1 (primary microswitch trigger) is pressed or held, a signal is sent to the MOSFET gate to fire the Solenoid (S) repeatedly. The solenoid pushes the Nerf dart out of the mag and into the flywheels (M1 & M2) which then accelerate the dart out of the barrel.
 
However, MS1 only activates while MS2 is held. This helps prevent jams in case a dart gets pushed into non-spinning flywheels. This is done in the code.
 
Power supplied to the brushless motors and solenoid do not travel through the microswitches. This means you do not need high current rated microswitches.
 
Brushless Motors
I'm not going to explain how brushless differs from brushed motors here, you can search for some great explanations.
 
There are inrunner and outrunner brushless motors. You want an outrunner motor since they are flatter in shape so you don't have ugly cans sticking out the side of your Nerf blaster. Outrunner motors also have a portion of the external can rotate with the shaft. This makes it easy to 3D print flywheels to go over the motor.
 
Get a motor with rear mounting holes.
 
Voltages of motors should handle at least 12.6V (3s lipo).
 
Current of motor should not exceed Brushless ESC current rating.
 
Power of motors should be >60W. This project uses 12.6V supply voltage x measured 7A motor draw = ~80W each.
 
RPM of brushless motors should be ~25k and are determined by kV rating x Voltage. This project uses 2600kV motors @ 12.6V. Therefore 2600 x 12.6 = ~32,760RPM. I only run the motors at half throttle and darts fly 25m / 82ft!
 
Brushless ESC's
These basically control the power of the brushless motors.
 
Brushless motors don't work with brushed ESC's , get brushless.
 
You need one ESC per motor. Otherwise the back EMF from two motors connected to one ESC will mess up the ESC timing and damage said ESC and / or motors.
 
Current rating of ESC needs to be higher than current draw of motor. Motor in this case was measured at 7A each. Recommend ESC is 20A or higher.
 
Voltage rating of ESC needs to be at least 12.6V (3s Lipo).
 
ESC does not need a built-in BEC. You can use 'OPTO' ESC's. If you have an ESC with BEC, connect the ground and signal cables to Arduino as shown in the schematic. Do NOT connect the ESC 5V Red cable to anything. (Unless you have a specific purpose for it and know what you're doing).
 
Battery
 
u6b55z9.jpg
 
A single battery to power everything. I recommend using a XT60 connector.
 
Voltage is 12.6V 3S Lipo Battery.
 
Capacity is 1300mAH minimum recommended.
 
Current Discharge Rating of battery should be enough for the power draw of all loads. In this project, load current is ~25A.
 
Max discharge rate of battery is calculated by Discharge Rate (25C) x Capacity in Ah (1,300mAh = 1.3Ah).
 
Therefore 25 x 1.3 = 32A max discharge rate for the battery. You should be able to find these numbers in the battery specs.
 
MOSFET
 
LzHzMgs.jpg
 
Powering a 12V / 8A Solenoid straight from an Arduino will cause magic smoke (Arduino dies). Solution? MOSFET.
 
The power MOSFET is used as an on / off switch for the Solenoid. It basically interrupts the ground that powers the Solenoid. This is known as a N-Channel MOSFET. Make sure you get a N-Channel.
 
The MOSFET knows when to turn on and off because of a signal sent to the MOSFET gate pin from an Arduino output pin (D4 in this case). Arduino's put out 5V, and the gate should be fully on at 5V. For this to work it needs to be a Logic Level MOSFET.
 
Current draw from Solenoid is rated at 8A. Make sure the MOSFET has a higher max current rating. This project uses a 30A max rated MOSFET.
 
Voltage though the MOSFET is 12.6V to power the solenoid. This MOSFET is rated at 60V max which is plenty of headroom.
 
Temperature of the MOSFET is less than 35°C in this case. This is achieved because the MOSFET is rated for 30A, though there is only ~8A of load being pulled through it. The other reason is the load (Solenoid) is only powered on momentarily before switching off, instead of powered on constantly. A heat sink is not necessary in this case.
 
Solenoid
 
6nPuf5f.jpg
 
This pushes the dart into the flywheels. All you want is a 12V rated Solenoid with 35mm stroke length. Shorter strokes will not push the full length type Nerf darts far enough.
 
The spring on the solenoid is upgraded to a stiffer spring. 0.9mm wire diameter, 14mmOD and 40mm length. This prevents pusher rod from getting stuck on darts and also increases fire rate!
 
Because the Solenoid is powered on momentarily as opposed to continuously, it should only get mildly warm ~40°C and therefore not require cooling.
 
These solenoids are relatively cheap and generic. They can be found on Ebay, Aliexpress etc.
 
Safety Switch
SW safety switch is simply a 2 position slider switch. It has 3 contacts, though only 2 are used. Powers off Arduino when safety is on, preventing flywheels & solenoid from activating.
 
Protection Circuitry
This section explains how to prevent frying your electronics!
 
C1 33μF is all I had (100μF recommended) & C2 100nF (0.1µF) reduces voltage sag and spikes to the Arduino power input.
 
Caution: C1 is polarity sensitive, striped side is negative, else it goes bang!
 
D1 prevents reverse voltage to Arduino VIN. Take note of it's polarity.
 
D2 is a fly-back / freewheeling diode. It prevents the solenoid (or other inductors) from creating back EMF. This back EMF could otherwise damage the MOSFET. Take note of it's polarity.
 
R1 & R2 are 4.7kΩ pull-up resistors for MS1 & MS2. This prevents floating voltage at the microswitches.
 
R3 is a 10kΩ pull-down resistor to prevent floating voltage at the gate of the MOSFET.
 
R4 is a 150kΩ for the optional LED's. My LED's are 2 in series at 2.4V / 50mA each. Your resistor value may vary. These LED's flash on and off in sync with the solenoid to replicate muzzle flash!
 
 
That sums up this guide. Arduino Code will be provided in the next post, as well as an explanation on how to use it, which values you can change in it etc.
 
Any questions leave a comment below :)

  • 2


#364255 Cyberpunk 2077 Kang Tao 3D Printed Nerf Gun

Posted by Clark3DPR on 27 October 2019 - 11:54 PM

You went with manual supports?!?

 

First, I'd like to see how you've gone about making them. Second, those grids that are left over look more difficult to remove than some of the auto-generated supports I've used, especially tree supports.

 

This remains an excellent post, I hope you continue to fill it out.

 

Ah yes, manual because i'm crazy like that!

 

Auto supports tends to be dense, I have to saw / cut it off in some instances. Also, some areas are small and fragile, and could easily break off with the support material. Auto is 'dumb' and places supports in some places where it is not needed.

 

Grids are easy enough to remove with needle nose pliers using a twisting motion. It just takes a bit of time. Grid is only 0.5mm thick.

 

The supports were created within the 3D CAD software (I use Autodesk Inventor Professional) before importing to the Slicer software. I might make a video on the topic of manual supports.

 

I haven't tried tree supports yet, I will look into that.

 

Yes, next week there will be a technical explanation of electronics, MOSFET, brushless motors, brushless ESC, Arduino, Solenoid, Microswitches etc. And maybe a video of it firing!

 

Thanks for commenting


  • 1


#364234 Cyberpunk 2077 Kang Tao 3D Printed Nerf Gun

Posted by Clark3DPR on 20 October 2019 - 06:33 AM

PART 2 - 3D PRINTING

 

Now it's time to bring this Kang Tao into reality!

 

Slicer software used was PrusaSlicer

3D Printer used was Artillery Sidewinder X1 - 300x300x400mm build area.

Filament: PLA / Hotend 210°C / Bed 65°C

 

Besides a simple pencil holder, this is actually my first 3D printed project (a bit ambitious i know...)

 

So this 3D printer was purchased because of it's affordable price and rather large print area, making things easier.

Even with a large 300x300mm build area, the Kang Tao had to be split into multiple pieces to print. This was kept in mind during the CAD modelling process.

 

The first part to print is the 'main' part which houses critical components such as flywheel cage, mag, firing chamber and Arduino. This will be the base piece, where consecutive pieces will build onto it.

 

8UfsmpY.jpg

 

This finished part is another main part, which will house the remaining critical components such as the grip, trigger, solenoid and MOSFET.

17 hours later, this finished part looks something like this:

 

HTGOQaS.jpg

 

Fun Fact: Over 52 3D printed parts taking over 160 hours to print

 

Flipping it over, you can see the 'base plate'. This base plate was created so that the print stays stuck to the print bed, otherwise it would peel off mid-print and be ruined!

Also notice how the base plate is made up of multiple sections, so that removal with pliers is easier.

 

Beneath the base plate is a grid of manually designed support material, so that the printer does not print in mid air, and the material above will not collapse on a hollow section.

Auto-generated support material tends to put material everywhere, making it a nightmare to remove without damaging the part, and so support material was painstakingly designed manually.

 

mFG6bMw.jpg

 

Here it is hollowed out with most of the support material removed. You can catch a glimpse of the grid supports that once was.

You don't need to hollow this out if all you want is an inanimate object for cosplay purposes. However, because I want to be difficult and make it a functional Nerf Blaster, I needed somewhere to mount all the electronics.

 

sJePBEU.jpg

 

Flywheel cage was printed in multiple parts, specifically to fit these brushless motors. (More on electronics in future post).

 

bfLJmkG.jpg

 

Here is a video of the 3D Printing time lapse, a further explanation and a teaser of the painted parts:

 

Next post will be...hmmm...further analysis of mechanic operations. How the mag release works, solenoid, flywheel cage etc.

 

Thank for reading, any questions leave a comment :)


  • 1


#364227 Cyberpunk 2077 Kang Tao 3D Printed Nerf Gun

Posted by Clark3DPR on 16 October 2019 - 04:45 AM

PLANNING - Physical CAD Drawings

 

Here I show you over 120 hours worth of CAD drawings used to bring this project to life. Program used: Autodesk Inventor Professional.

Gameplay trailers on Youtube were used for visual reference of the Kang Tao, as well as the official CDPR reference images for Cosplayers.

 

The Kang Tao started as a single line, then evolve into many complex shapes. Everything constrained with dimensions so that every part fits together precisely. Cant just 'eyeball' this stuff.

 

a5WxaIK.png

 

Multiple parts were made with the 3D printing process in mind. Each part was designed to be fastened to one another using M3 screws and threaded inserts.

 

It is designed to be split into two halves similar to a Nerf gun. Both halves have screws, as Nerf guns look a little weird and "toy like" with screws on only one side causing deep holes where the screws are.

 

6fv3JZI.jpg

 

Fun fact: There are over 115 components that make up this project (not including screws, inserts or cables)

 

All of the electronics (except battery) were housed in the right half (similar to nerf guns) for easy access. Battery located in a compartment towards top front. (Electronics tutorial in future post).

 

By far the most challenging aspect was to make the gun functional while also aesthetically accurate to the Kang Tao from the game.

To achieve the correct look, I purchased a 3D printer (Artillery Sidewinder X1) with a massive 300x300x400mm build area. (More details in upcoming 3D printing post)

 

To achieve the functionality similar to the Kang Tao from Cyberpunk 2077, this needed to have full auto fire mode.

For this, a flywheel cage with Brushless Motors was used in conjunction with a solenoid pusher. (More parts list details in a future post).

 

There is a 'window' on the Kang Tao that features a piston moving in a back and forth motion whilst firing. I HAD to simulate that somehow…

So I moved the solenoid towards the rear and added a shaft extension through the window that pushes the Nerf dart out of the mag and into the flywheels. It just...works!

 

1aY65Vt.jpg

 

Check out my video explaining in a bit more detail of how the parts were modelled and how they all fit together etc:

 

Next post will be about the 3D Printing Process.

 

And as always, suggestions and questions just leave a comment below.


  • 1