Sunday 26 May 2019

RC car improvements up to June 2019 - and a future possibility?

Car number 2 works with the software on SD card #3, but the problem is that it takes off too fast and needs a lot more room than I have to fully test it. It also doesn't respond very quickly to the tablet.

I'll give it a go with SD card #7, which has the AP built in and see if that is any better.

- 2019-06-13 Car number 2 with R-Pi3W and Card#7 out on the road, it works aside from the fact that left and right are wrong way around, just not very fast to respond. Is it worth doing a video showing it?
- How can I improve response times?


----------------------------

Because of the things that I have found out about pwm for driving the RC airplane servo's I might try and make the forward/back work using pwm with every press of the 'forward' button adding 5% to the pwm pulsewidth.

At the moment struggling to get basic pwm operation working in the program instead of go/stop.

---------------------------
9/9/2019
I did get this working.  One of the things about PWM is that driving Remote Control Servos
uses PWM of about 1.5% to 2.5% ( these are just approx figures from my mind, check elsewhere for actual limits) To drive the car motors I noticed that it didn't do anything at 5% PWM, so I made it increase in steps of 15% and this worked fine. Another challenge was getting the feedback to display in the HTML the figure of the PWM value.

Here is the python code for the car: [some comments removed]

from flask import Flask, render_template

# This gives us control of the Raspberry Pi's pins.
import RPi.GPIO as GPIO
import time

# Tell it which pin number we'll  be using to refer to the GPIO pins.
# We will use the physical pin ordering. Set initial state of pins
GPIO.setmode(GPIO.BOARD)

MotorFwd = 12
MotorBack = 16
MotorLeft = 19
MotorRight = 23
GPIO.setup(MotorFwd, GPIO.OUT)
GPIO.setup(MotorBack, GPIO.OUT)
GPIO.setup(MotorLeft, GPIO.OUT)
GPIO.setup(MotorRight, GPIO.OUT)

# PWM pin
u_d_pin_no = 18
GPIO.setup(u_d_pin_no, GPIO.OUT)


frequency_hertz = 50
pwm = GPIO.PWM(u_d_pin_no, frequency_hertz)

PWM_Stop = 0
PWM_value = 0
PWM_increment = 3
# becomes 15 after calculations

# total number of milliseconds in a a cycle.  Given this, we will then
# know both how long we want to pulse in this cycle and how long tghe
# cycle itself is.  That is all we need to calculate a duty cycle as
# a percentage.
ms_per_cycle = 1000 / frequency_hertz

# now lets get into Flask

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/motor-stop/')
def on():
    # motor.stop()
    PWM_value = 0
    duty_cycle_percentage = PWM_value
#    print("Duty Cycle[S]: " + str(duty_cycle_percentage))
    pwm.start(duty_cycle_percentage)
    return render_template('index.html')


@app.route('/up_15/')
def up_15():
    global PWM_value
    PWM_value = PWM_value + PWM_increment
    duty_cycle_percentage = PWM_value * 100 / ms_per_cycle
#    print("Duty Cycle[F]: " + str(duty_cycle_percentage))
    pwm.start(duty_cycle_percentage)
#    time.sleep(.5)
#    pwm.ChangeDutyCycle(0)
    return render_template('index.html', PWM_PC = duty_cycle_percentage)

@app.route('/down_15/')
def down_15():
    global PWM_value
    if (PWM_value > 0) :
        PWM_value = PWM_value - PWM_increment
        duty_cycle_percentage = PWM_value * 100 / ms_per_cycle
#        print("Duty Cycle[F]: " + str(duty_cycle_percentage))
        pwm.start(duty_cycle_percentage)
#        time.sleep(.5)
#        pwm.ChangeDutyCycle(0)
#    endif
    return render_template('index.html')

@app.route('/motor-left/')
def motorleft():
    GPIO.output(MotorLeft,GPIO.HIGH)
    GPIO.output(MotorRight, GPIO.LOW)
    time.sleep(1)
    GPIO.output(MotorLeft, GPIO.LOW)
    return render_template('index.html')

@app.route('/motor-right/')
def motorright():
    GPIO.output(MotorLeft, GPIO.LOW)
    GPIO.output(MotorRight, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(MotorRight, GPIO.LOW)
    return render_template('index.html')


if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')
# We have shut all our stuff down but we should do a complete
# close on all GPIO stuff.  There's only one copy of real hardware.
# We need to be polite and put it back the way we found it.
    pwm.stop()
    GPIO.cleanup()

--------------------------

Having done all this I decided to do an R/C boat as it would combine the motor drive and the servo drive. I have given up on this idea because 1] I don't have a boat  2] the little motor that I was going to use didn't work with PWM and 3] I don't have a propellor.


Friday 17 May 2019

Four(!) RC cars now

May-2019
I seem to have been collecting cars to experiment on. This is what I have now.

Car #1  The one in the video, It was using a program called WebIOpi that became obsolete after an update to Raspbian. Also the original driver board broke after it was touched wrongly and has now been replaced by a Deek-Robot board. It still works.


and the deek-robot driver board. 
I only paid about a pound for this, but it works fine. 

Car # 2
This has taken a bit of work to get going because I have been trying to make a harness that can be moved between cars. What drove this is that Cars 1,2 &3 all have a 16 pin dual in-line receiver chip on them that have the same pinouts for forward and back, left and right.  On car 2 I replaced the IC with a DIL socket. The software that this is using is built on Flask from an article in Linux Format. 





Car #3 I have not touched this one yet, but as can be seen, it has the 16 pin DIL chip there for when I do get around to it.


This one was a 40MHz radio. It's the one that gave me the idea to make a common interface connection from the Raspberry Pi. 

Car #4 This one has a 16 pin IC surface mount and a bit smaller, but I'll bet that the pinouts are the same.  I'll have to modify the connections from my 16 pin DIL Header to connect to it. This one says it is 2.4GHz and it is a Maisto brand. Because of my history with Wifi with Telxon and the university, I wanted to try and drive it directly but a previous blog describes why this idea was a non-starter. 



That's it to date. Next step is to post a video of car #2 in operation.

25 June 2019:

In Car 2 the IC that has been replaced by a socket so that the harness from the R-Pi can plug straight in  has the following pinouts. This enabled me to build the harness. Note that the poor creation of this jpg has the 'right' label too high and it should be on pin 6.


Now the pinouts for the IC from Car 3 are as follows:

Which is the same.  For anybody who wants to check this, car 3 is a 40MHz unit using SM6135W IC and car 2 was a 27MHz and I'll have to look back in these blogs to find the IC part number.

The reason for belabouring this point is that with the R-Pi3w and the software in card #7, car 2 behaves well, but car 3 is all topsy turvy in that the L/R buttons make it go Forward/Backward, and the F/B buttons turn the car.  I don't understand it.