Program Design with multiple PDALib imports?

Moderator: Steve

Program Design with multiple PDALib imports?

Postby alanmcdonley » Wed Jun 22, 2016 9:51 am

I'm starting to think forward to how I am going to architect my robot software, and wondering if I need to do anything special to wrap the PDALib because I am importing packages which import PDALib and each other?

My s/w architecture at the moment:

usDistance.py
# HC-S04 UltraSonic Distance Sensor -adjusted to center of bot based on positionOfTiltPanInDeg()
import PDALib
import tiltpan
def initSensor()
def inInches(readings=75)
def off()

irDistance.py
# Sharp IR Distance Sensor -adjusted to center of bot based on positionOfTiltPanInDeg()
import PDALib
import tiltpan
def inInches(readings=75)


currentsensor.py
# ACS712 Current Sensor
import PDALib
def inMA(readings=75)

battery.py
# 6-cell battery through 2:1 divider
import PDALib
def inVolts(readings=75)

tiltpan.py
# tilt/pan servos with camera, HC-S04, and IR distance sensors
import PDALib
def center()
def centerTilt()
def centerPan()
def tiltDegUp(upDegFromCenter)
def panDegLeft(leftDegFromCenter)
def tiltPanDegUpLeft(upDegFromCenter, leftDegFromCenter)
def positionOfTiltPanInDeg() # returns current position of both servos[ tilt_upDegFromCenter, pan_leftDegFromCenter]

encoders.py
# wheel encoders - direct read or interrupt read
import PDALib
def initWithInterrupts()
def initNoInterrupts()
def off() #remove interrupt
def reset()
def countsLR()

motors.py
# motor drive and rotate commands
import PDALib
import encoders
import currentsensor
import bumpers
import irDistance
import usDistance

**************
Eventually, I want to have multiple async threads collecting sensor data with async data consumers, and async effectors (motor/tiltPan/speaker) but I don't know enough Python yet to design that.
alanmcdonley
 
Posts: 90
Joined: Thu Jul 23, 2015 10:50 am
Location: Boynton Beach, Florida

Re: Program Design with multiple PDALib imports?

Postby mikronauts » Wed Jun 22, 2016 11:12 am

That is an excellent question.

You may run into issues with accessing SPI devices from multiple scripts if they are running in separate threads.

If the app is single threaded, you should be OK.

If you need multiple threads, you will need to provide locks around the SPI code at a minimum (analogRead(), the low level SPI digital I/O functions)

The Pi pins should be OK, as pigpio controls them, and worst case I think is that each thread would open a socket connection to pigpiod.

Please keep me updated!
mikronauts
 
Posts: 119
Joined: Tue Sep 16, 2014 6:58 pm


Return to Pi Droid Alpha

Who is online

Users browsing this forum: No registered users and 2 guests

cron