Use short descriptive names. (1st priority is to be descriptive, 2nd is to make it short).mighty69 wrote:how would i go about calling the outputs from my hardware?
For the parts you implement you're free to use naming you like... for using already implemented bits use names they picked.mighty69 wrote:Essentially the naming is arbitrary then?
This your "assign" task is actually reading from/writing to hardware.mighty69 wrote:I would just use the name and assign it to the hardware somehow?
Each component has a datasheet where this is defined. Some standard ways exist, named as protocols (I2C, SPI, ...).mighty69 wrote:I'm failing to see how the program knows to access the hardware for providing data.
Coding typically takes minor amount of overall effort. Initially, reading and learning takes most of this time.mighty69 wrote:I feel like I can write code all day and never get what I need.
And troubleshooting, debugging and finding your own mistakes takes the other 90% of your time. But I've noticed in my career, as computers have evolved from room-sized, to refrigerator-sized, to breadbox-sized, to "credit card sized", the smaller they get, the more motivated I am to "best" them.FLYFISH TECHNOLOGIES wrote:Coding typically takes minor amount of overall effort. Initially, reading and learning takes most of this time.
Umm, it doesn't.mighty69 wrote:I'm failing to see how the program knows to access the hardware for providing data.
But it's much easier to program in a high-level language like Python, than a low-level language like assemblerame wrote:As a programmer you might throw up your hands in frustration and ask "Do I have to think of everything?!". The answer is "Yes", every tiny detail.
Code: Select all
Traceback (most recent call last)"
File "Master.py", line 4, in <module>
from Adafruit_I2C import Adafruit_I2C
File "/home/pi/Adafruit_I2C.py", line 23, in <module>
class Adafruit_I2C:
File "/home/pi/Adafruit_I2C.py", line 37, in Adafruit_I2C
def _init_(self, address, bus=smbus.SMBus (1 if getPiREvision() >1 else 0), debug=False)
IOError: [Errno 13] Permission deniedCode: Select all
from Adafruit_I2C import Adafruit_I2C
from Adafruit_L3GD20 import L3GD20
from Adafruit_LSM303DLHC import LSM303DLHCHehe!mighty69 wrote:I commented the i2c blacklist out, so it should work. never seen foo.py though?
Code: Select all
#calculate position B using accelerations
def findB(t,p1,p2,p3):
return array([2*t**2+p1, 3*t**2+p2, 9.8*t**2+p3])
Code: Select all
#calculate position B using accelerations
def findB(t, pos, accel):
tsq = t**2
return array([accel[0]*tsq+pos[0], accel[1]*tsq+pos[1], accel[2]*tsq+pos[2]])
Code: Select all
from Adafruit_LSM303DLHC import LSM303DLHC
lsm = LSM303DLHC(0x19, 0x1E, False)
accel = lsm.readAccelerationsG()
Code: Select all
print "Accel X: %6.3f G, Accel Y: %6.3f G, Accel Z: %6.3f G" % (accel.x, accel.y, accel.z)Code: Select all
#calculate position B using accelerations
def findB(t, pos, accel):
tsq = t**2
return array([accel[0]*tsq+pos[0], accel[1]*tsq+pos[1], accel[2]*tsq+pos[2]])Code: Select all
import os
import math
from Adafruit_I2C import Adafruit_I2C
from Adafruit_LSM303DLHC import LSM303DLHC
import numpy as np
from numpy import *
import time
from datetime import datetime, date
lsm = LSM303DLHC (0x19, 0x1E, False)
lsm.setTempEnabled (True)
def sub(a, b)
return array([b-a])
def findB(t, p, a):
tsq=t**2
return array([a[0]*tsq+p[0], a[1]*tsq+p[1], a[2]*tsq+p[2]])
while (1):
accell= lsm.readAccelerationsG()
temp = lsm.readTempF()
heading = lsm.readMagneticHeading()
def main():
pos1=input()
pos2=input()
pos3=input()
pos5=input()
pos4=input()
pos6=0
time7=input()
start=array([pos4, pos5, pos6])
finish=array([pos1, pos2, pos3])
current=findB(time7, start, accel)
print(sub(start, finish))
if time7>0:
print(findB(time7, current, accel))
print(sub(current, finish))
main()
Yeah, you could simply change the findB function so that it takes accel as an object parameter, rather than as an array:mighty69 wrote:these three values usingTo use those values in my own function is where i'm still tripping up. when Andrew S. wroteCode: Select all
print "Accel X: %6.3f G, Accel Y: %6.3f G, Accel Z: %6.3f G" % (accel.x, accel.y, accel.z)those three imputs are an integer, "t" and two arrays, "pos" and "accel" and the function refers to the positions in the arrays? so accel[0]=accel.x?Code: Select all
#calculate position B using accelerations def findB(t, pos, accel): tsq = t**2 return array([accel[0]*tsq+pos[0], accel[1]*tsq+pos[1], accel[2]*tsq+pos[2]])
Code: Select all
#calculate position B using accelerations
def findB(t, pos, accel):
tsq = t**2
return array([accel.x*tsq+pos[0], accel.y*tsq+pos[1], accel.z*tsq+pos[2]])Code: Select all
accel.x*tsq+p[0]Code: Select all
accel[0]*tsq+p[0]