Motor Spool Control System for the Build a CubeSat Challenge
by ali0405 in Circuits > Raspberry Pi
77 Views, 3 Favorites, 0 Comments
Motor Spool Control System for the Build a CubeSat Challenge
The Build a CubeSat Challenge is a challenge that involves building a model of a CubeSat, a type of small satellite, to simulate an actual CubeSat performing space-based research missions.
For the 2023-2024 Build a CubeSat Challenge, I developed a spool system to control the movement of the CubeSat as a way to model a satellite's movement in a Sun-synchronous orbit. For the CubeSat challenge, the spool system was attached to the wall near the ceiling of a room, so that it could pull a cable (and with it, the CubeSat itself) across the ceiling. This article will be on how I created this spool system.
Of course, this spool system is not restricted to only working with a CubeSat—it can be applicable to any project involving a spool mechanism.
The spool control system in this article functions with the use of a bipolar stepper motor driven by an L298N Driver and a Raspberry Pi.
Supplies
A 3D printer is needed to print the pieces for the spool's frame/structure.
Additionally, beyond a Raspberry Pi and an L298N motor driver, you'll need a Nema 17 Stepper Motor and cables to connect the different components.
Listed below are the supplies I used:
Tools:
- 3D Printer
Materials:
- PLA filament
Parts:
- Raspberry Pi
- L298N Motor Driver
- Nema 17 Stepper Motor 17HS4401
- 10 Cables
Making and Assembling Spool
The first step is to 3D print the spool frame. I was able to find 3D printing files for this online.
Here's the webpage I found the files from: https://electronoobs.com/eng_arduino_tut174_stl1.php
Wiring
The next step is connecting the L298N Driver, the Raspberry Pi, and the stepper motor.
Follow the wiring in the picture above. (Using different colors will make this much easier!)
I used a motor governor to adjust the output power to meet the amount needed for the motor to run properly.
Code
A code is needed to control the speed and direction the spool system rotates. It will, in other words, control the amount of cable/string being spooled or un-spooled.
import RPi.GPIO as GPIO
import time
out1 = 17
out2 = 18
out3 = 27
out4 = 22
direction = "forward"
step_sleep = 0.007
step_count = 200
GPIO.setmode( GPIO.BCM )
GPIO.setup( out1, GPIO.OUT )
GPIO.setup( out2, GPIO.OUT )
GPIO.setup( out3, GPIO.OUT )
GPIO.setup( out4, GPIO.OUT )
# initializing
GPIO.output( out1, GPIO.LOW )
GPIO.output( out2, GPIO.LOW )
GPIO.output( out3, GPIO.LOW )
GPIO.output( out4, GPIO.LOW )
def cleanup():
GPIO.output( out1, GPIO.LOW )
GPIO.output( out2, GPIO.LOW )
GPIO.output( out3, GPIO.LOW )
GPIO.output( out4, GPIO.LOW )
GPIO.cleanup()
try:
if direction == "forward":
i = 0
for i in range(step_count):
if i%4==0:
GPIO.output( out4, GPIO.HIGH )
GPIO.output( out3, GPIO.LOW )
GPIO.output( out2, GPIO.LOW )
GPIO.output( out1, GPIO.LOW )
elif i%4==1:
GPIO.output( out4, GPIO.LOW )
GPIO.output( out3, GPIO.LOW )
GPIO.output( out2, GPIO.HIGH )
GPIO.output( out1, GPIO.LOW )
elif i%4==2:
GPIO.output( out4, GPIO.LOW )
GPIO.output( out3, GPIO.HIGH )
GPIO.output( out2, GPIO.LOW )
GPIO.output( out1, GPIO.LOW )
elif i%4==3:
GPIO.output( out4, GPIO.LOW )
GPIO.output( out3, GPIO.LOW )
GPIO.output( out2, GPIO.LOW )
GPIO.output( out1, GPIO.HIGH )
time.sleep( step_sleep )
elif direction == "backward":
i = 0
for i in range(step_count):
if i%4==0:
GPIO.output( out4, GPIO.HIGH )
GPIO.output( out3, GPIO.LOW )
GPIO.output( out2, GPIO.LOW )
GPIO.output( out1, GPIO.LOW )
elif i%4==1:
GPIO.output( out4, GPIO.LOW )
GPIO.output( out3, GPIO.LOW )
GPIO.output( out2, GPIO.LOW )
GPIO.output( out1, GPIO.HIGH )
elif i%4==2:
GPIO.output( out4, GPIO.LOW )
GPIO.output( out3, GPIO.HIGH )
GPIO.output( out2, GPIO.LOW )
GPIO.output( out1, GPIO.LOW )
elif i%4==3:
GPIO.output( out4, GPIO.LOW )
GPIO.output( out3, GPIO.LOW )
GPIO.output( out2, GPIO.HIGH )
GPIO.output( out1, GPIO.LOW )
time.sleep( step_sleep )
except KeyboardInterrupt:
cleanup()
exit( 1 )
cleanup()
I used "forward" to refer to the motor rotating clockwise, while "backward" is used to refer to rotation counterclockwise.
Since the Nema 17 stepper motor has a 1.8-degree step angle, it takes 200 steps to do a full rotation. Step_sleep is used to control the speed of the motor rotations.
I then created an HTTP server to allow other users to access the spool system.
Here is the link to the server code: https://github.com/ali040507/cubesat-spool-control-/blob/444452175a5183134de88e934103911234974bac/motor_server.py
Additionally, I made a HTTP client code that corresponds with the HTTP server. The code uses the request method POST.
import http.client, urllib.parse
params = urllib.parse.urlencode({'@direction': 'forward', '@step_count': '600' })
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "type/plain"}
conn = http.client.HTTPConnection("192.168.1.55:8000")
conn.request("POST", "", params, headers)
response = conn.getresponse()
print(response.status, response.reason)
data = response.read()
data
conn.close()
The link to the full code for the HTTP server and the client: https://github.com/ali040507/cubesat-spool-control-.git