Rasbperry pi 3 and t100 thrusters

I am using a Raspberry Pi 3, Afro ESC’s, and t100 thrusters. I am a beginner. I am trying to connect the t100 thrusters to my raspberry pi 3. I have the correct physical set up, but i am having a hard time with the python code to make the t100 thrusters power on and perform. we are using dc batteries for the power source. we are having issues finding a python code to control both thrusters together. we want the thrusters to move in forward, reverse, left and right. we also want to control them independently.

Below i have pasted the code we have been editing and working on. why wont this code work?

Servo Control
import time
import wiringpi

use ‘GPIO naming’
wiringpi.wiringPiSetupGpio()

set #18 to be a PWM output
wiringpi.pinMode(18, wiringpi.GPIO.PWM_OUTPUT)

set the PWM mode to milliseconds stype
wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)

divide down clock
wiringpi.pwmSetClock(192)
wiringpi.pwmSetRange(2000)

delay_period = 0.01

while True:
for pulse in range(50, 250, 1):
wiringpi.pwmWrite(18, pulse)
time.sleep(delay_period)
for pulse in range(250, 50, -1):
wiringpi.pwmWrite(18, pulse)
time.sleep(delay_period)

Hi Morgan,

Thanks for the email! It looks like this code (from Adafruit) is meant to sweep a servo back and forth. Since the thrusters require a solid pulse at 1500 µs to initialize, they are probably not initializing properly.

Here’s small modification that should work:

# Servo Control
import time
import wiringpi

# use 'GPIO naming'
wiringpi.wiringPiSetupGpio()

# set #18 to be a PWM output
wiringpi.pinMode(18, wiringpi.GPIO.PWM_OUTPUT)

# set the PWM mode to milliseconds stype
wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)

# divide down clock
wiringpi.pwmSetClock(192)
wiringpi.pwmSetRange(2000)

# PWM pulses for thruster:
# 110 = 1100 µs (full reverse)
# 150 = 1500 µs (stopped + initialize)
# 190 = 1900 µs (full forward)
# initialize thruster
wiringpi.pwmWrite(18, 150)

# wait for initialization (2 seconds)
time.sleep(2.0)

# set to some speed
wiringpi.pwmWrite(18, 170)

Let me know if that works.

-Rusty

I am using a Raspberry Pi 2, Afro ESC’s, and t100 thrusters. I am a beginner. I am trying to connect the t100 thrusters to my raspberry pi 2. I had operated only one thruster with GPIO Pin 18 but I try to connect pins with different GPIO Pin but it isn’t work. I want connect four thruster. What’s happening?

Thanks
Christos

My program:

import time
import wiringpi

wiringpi.wiringPiSetupGpio()
pins = 18

wiringpi.pinMode(pins, wiringpi.GPIO.PWM_OUTPUT)
#wiringpi.pinMode(17, wiringpi.GPIO.PWM_OUTPUT)

wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
wiringpi.pwmSetClock(192)
wiringpi.pwmSetRange(2000)
print ("program")

while True:
    print ("on 150")
    wiringpi.pwmWrite(pins, 150)
#    wiringpi.pwmWrite(17, 150)
    time.sleep(2.0)
    print ("on 160")
    wiringpi.pwmWrite(pins, 160)
#    wiringpi.pwmWrite(17, 160)
    time.sleep(5.0)
    print ("off 130")
    wiringpi.pwmWrite(pins, 130)
#    wiringpi.pwmWrite(17, 130)
    time.sleep(2.0)
    print ("on 120")
    wiringpi.pwmWrite(pins, 120) 
#    wiringpi.pwmWrite(17, 120)
    time.sleep(2.0)
    print ("stop")
    wiringpi.pwmWrite(pins, 0)
#    wiringpi.pwmWrite(17, 0)

Hi, the Raspberry Pi has only one gpio capable of pwm. If you want more pwm outputs, you will have to add something like the pwm shield.

Do you have an example code on how to run thruster using a pwm shield?

Hi

I am running 6 thrusters, camera tilt, and (shortly) lights off the Rasberry PI without a shield - it appears to work very well.

By the default only one gpio is capable of pwm, but this can be modified using the pigpio library to turn any gpio into pwm. It appears quite stable.

Jacob has already discussed pigpio in the other related post.

Andrew

Andrew,
Can you point me to that link?

-Jestoni

There is some good reading material here:

Sample code is below, after ensuring the service is running “sudo pigpiod”. There are ways to start this automatically on startup.

import time
import sys
import pigpio

pi = pigpio.pi() # Connect

# turn thruster on - pin 22
pi.set_servo_pulsewidth(22, 1700)

# wait half a second
time.sleep(0.5)

# turn thruster off - pin 22
pi.set_servo_pulsewidth(22, 1500)

pi.stop()

The Raspberry Pi has only one hardware PWM, but these libraries provide a way to generate them via software. The downside of software PWMs is that they are often jittery, because they depend on the Operating System to work.

In my experience ServoBlaster had the best performance jitter-wise between all the libraries I tested for software PWM.

You can also use the Raspberry I²C with a PCA9685 board.

it doesn’t work what you shared code in the post . So how can i fixed and worked ? Dou you have any idea please share with me . thank you.

The code is fairly standard and does usually work. Can you please share a little about your setup, what you have tried, and where the problem lies?

Also note that the Raspberry Pi gets fairly warm and resourced up controlling 6 thrusters, lights, and everything else. Patrick’s suggestion is really worth consideration.