Closed ksj537465 closed 3 years ago
Can you share your current script? It's easier to help that way. Thanks!
this is main script
#!/usr/bin/env pybricks-micropython
#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.parameters import Port, Stop, Direction, Button, Color
from pybricks.tools import wait, StopWatch, DataLog
from pybricks.ev3devices import Motor
from pybricks.media.ev3dev import Font
from mindsensorsPYB import PPS58
from mindsensorsPYB import ABSIMU
import os
import sys
import time
from time import sleep
def PPS58Test() :
# Create your objects here.
ev3 = EV3Brick()
pps58 = PPS58(Port.S2,0x18)
# Write your program here.
print(pps58.readAbsolute(),pps58.readGauge(),pps58.readRef())
return pps58.readAbsolute()
def DepthTest() :
# Create your objects here.
ev3 = EV3Brick()
pps58 = PPS58(Port.S2,0x18)
# Write your program here.
print(pps58.readAbsolute(),pps58.readGauge(),pps58.readRef())
return pps58.readGauge()
def ABSIMUTest() :
# Create your objects here.
ev3 = EV3Brick()
imu = ABSIMU(Port.S1,0x22)
# Write your program here.
print(imu.get_accelall(),imu. get_heading(),imu.get_gyroall())
return imu.get_accelall(),imu.get_gyroall(),imu.get_heading()
# Base_Press = PPS58Test()
data = DataLog('Pressure','ABS','time')
watch = StopWatch()
for x in range(99999):
# Motor(Port.A).run_time(1000, 18000, Stop.BRAKE, False)
# Motor(Port.B).run_time(1000, 18000, Stop.BRAKE, False)
Pressure = PPS58Test()
ABS = ABSIMUTest()
time = watch.time()/1000
Diff = DepthTest()
data.log(Pressure,ABS,time)
if Diff < 5: continue
# Motor(Port.A).run_time(-1000, 18000, Stop.BRAKE, False)
# Motor(Port.B).run_time(-1000, 18000, Stop.BRAKE, False)
if Diff == 1:
sleep(10)
and this is sensor class part
## PPS58 : this class provides EV3Dev specific interface for the PPS58
# for read and write operations.
class PPS58(mindsensors_i2c):
def __init__(self, port,i2c_address=0x18):
mindsensors_i2c.__init__(self,port, i2c_address)
## Read a absolute pressure from PPS58 sensor and return .
# @param self The object pointer.
def readAbsolute(self):
results = self.readInteger(0x43)
return results
## Read a gauge pressure from PPS58 sensor
# @param self The object pointer.
def readGauge(self):
results = self.readInteger(0x45)
return results
## Read a referance pressure from PPS58 sensor
# @param self The object pointer.
def readRef(self):
results = self.readInteger(0x47)
return results
## Write usnit register for reading pressure from PPS58 sensor
#‘p’: PSI
#‘b’: millibar
#‘k’: kPA
# @param self The object pointer.
def unitSelect(self,unit):
self.writeByte(0x42,unit)
## ABSIMU: this class provides functions for models of the ABSIMU from mindsensors.com
# for read and write operations.
class ABSIMU(mindsensors_i2c):
## Default ABSIMU I2C Address
ABSIMU_ADDRESS = (0x22)
## Command Register
COMMAND = 0x41
## X-Axis Tilt Register. Will return a signed integer reading
TILT_X = 0x42
## Y-Axis Tilt Register. Will return a signed integer reading
TILT_Y = 0x43
## Z-Axis Tilt Register. Will return a signed integer reading
TILT_Z = 0x44
## X-Axis Accelerometer Register. Will return a signed integer reading (-1050 - 1050)
ACCEL_X = 0x45
## Y-Axis Accelerometer Register. Will return a signed integer reading (-1050 - 1050)
ACCEL_Y = 0x47
## Z-Axis Accelerometer Register. Will return a signed integer reading (-1050 - 1050)
ACCEL_Z = 0x49
## Compass Heading Register. Will return an unsigned integer reading (0 - 360)
CMPS = 0x4B
## X-Axis Magnetometer Register. Will return a signed integer reading
MAG_X = 0x4D
## Y-Axis Magnetometer Register. Will return a signed integer reading
MAG_Y = 0x4F
## Z-Axis Magnetometer Register. Will return a signed integer reading
MAG_Z = 0x51
## X-Axis Gyroscope Register. Will return a signed integer reading
GYRO_X = 0x53
## Y-Axis Gyroscope Register. Will return a signed integer reading
GYRO_Y = 0x55
## Z-Axis Gyroscope Register. Will return a signed integer reading
GYRO_Z = 0x57
## Initialize the class with the i2c address of your AbsoluteIMU
# @param self The object pointer.
# @param absimu_address Address of your AbsoluteIMU.
# @remark
def __init__(self, port,absimu_address = ABSIMU_ADDRESS):
mindsensors_i2c.__init__(self,port, absimu_address )
## Writes a value to the command register
# @param self The object pointer.
# @param command Value to write to the command register.
def command(self, command):
self.writeByte(COMMAND, int(command))
## Reads the tilt value along the x-axis
# @param self The object pointer.
def get_tiltx(self):
return self.readByteSigned(self.TILT_X)
## Reads the tilt value along the y-axis
# @param self The object pointer.
def get_tilty(self):
return self.readByteSigned(self.TILT_Y)
## Reads the tilt value along the z-axis
# @param self The object pointer.
def get_tiltz(self):
return self.readByteSigned(self.TILT_Z)
## Reads the tilt values
# @param self The object pointer.
def get_tiltall(self):
res = [(self.get_tiltx(),
self.get_tilty(),
self.get_tiltz())]
return res
## Reads acceleromter value along the x-axis
# @param self The object pointer.
def get_accelx(self):
return self.readIntegerSigned(self.ACCEL_X)
## Reads acceleromter value along the y-axis
# @param self The object pointer.
def get_accely(self):
return self.readIntegerSigned(self.ACCEL_Y)
## Reads acceleromter value along the z-axis
# @param self The object pointer.
def get_accelz(self):
return self.readIntegerSigned(self.ACCEL_Z)
## Reads the accelerometer values
# @param self The object pointer.
def get_accelall(self):
res = [(self.get_accelx(),
self.get_accely(),
self.get_accelz())]
return res
## Reads compass heading
# @param self The object pointer.
def get_heading(self):
head = self.readInteger(self.CMPS)
while(head > 360 or head < 0):
head = self.readInteger(self.CMPS)
return head
## Reads magnetometer value along the x-axis
# @param self The object pointer.
def get_magx(self):
return self.readIntegerSigned(self.MAG_X)
## Reads magnetometer value along the y-axis
# @param self The object pointer.
def get_magy(self):
return self.readIntegerSigned(self.MAG_Y)
## Reads magnetometer value along the z-axis
# @param self The object pointer.
def get_magz(self):
return self.readIntegerSigned(self.MAG_Z)
## Reads the magnetometer values
# @param self The object pointer.
def get_magall(self):
res = [(self.get_magx(),
self.get_magy(),
self.get_magz())]
return res
## Reads gyroscope value along the x-axis
# @param self The object pointer.
def get_gyrox(self):
return self.readIntegerSigned(self.GYRO_X)
## Reads gyroscope value along the y-axis
# @param self The object pointer.
def get_gyroy(self):
return self.readIntegerSigned(self.GYRO_Y)
## Reads gyroscope value along the z-axis
# @param self The object pointer.
def get_gyroz(self):
return self.readIntegerSigned(self.GYRO_Z)
## Reads the tilt values
# @param self The object pointer.
def get_gyroall(self):
res = [(self.get_gyrox(),
self.get_gyroy(),
self.get_gyroz())]
return res
## Starts the compass calibration process
# @param self The object pointer.
def start_cmpscal(self):
self.command(67)
## Stops the compass calibration process
# @param self The object pointer.
def stop_cmpscal(self):
self.command(99)
## Sets accelerometer sensitivity to 2G
# @param self The object pointer.
def accel_2G(self):
self.command(49)
## Sets accelerometer sensitivity to 4G
# @param self The object pointer.
def accel_4G(self):
self.command(50)
## Sets accelerometer sensitivity to 8G
# @param self The object pointer.
def accel_8G(self):
self.command(51)
## Sets accelerometer sensitivity to 16G
# @param self The object pointer.
def accel_16G(self):
self.command(52)
Where is mindsensors_i2c
defined? Is this a module obtained from somewhere? I can't seem to find it on the mindsensors website.
Back to your original question:
this sensors read speed is 5times per second(millisecond)
i want change read speed as 1time per second
If you want to decrease the speed as you say, I suppose you could just read the sensor less often in your script?
But if you are asking to increase the speed, I believe you can change the poll time of the sensor.
Have a look at the second example snippet in the Ev3devSensor class. It shows you how to access sensor settings by reading and writing to files. Here is an overview of those files. The example shows how to read the modes
file. In your case, I think you want to read (and write) the poll_ms
file.
the attached file is the full ver
i email to mindsensor to use this sensors at pybricks
back to answer, what i want is
decrease sensors read speed(pps58, absoluteimu) 1time per seccnd
now the unit seems as milli-second but i want change it to second
at exel file you can see the time 0.372 0.562 etc it because on my script time = watch.time()/1000
i want that time measrue like 1, 2 ,3 second
did i explain well enough for u to understand??
-----Original Message----- From: "laurensvalk"notifications@github.com To: "pybricks/support"support@noreply.github.com; Cc: "ksj537465"ksj537465@naver.com; "Author"author@noreply.github.com; Sent: 2021-01-06 (수) 17:54:59 (GMT+09:00) Subject: Re: [pybricks/support] Change mindsensors read speed (#198)
Where is mindsensors_i2c defined? Is this a module obtained from somewhere? I can't seem to find it on the mindsensors website. Back to your original question:
this sensors read speed is 5times per second(millisecond)
i want change read speed as 1time per second
If you want to decrease the speed as you say, I suppose you could just read the sensor less often in your script? But if you are asking to increase the speed, I believe you can change the poll time of the sensor. Have a look at the second example snippet in the Ev3devSensor class. It shows you how to access sensor settings by reading and writing to files. Here is an overview of those files. The example shows how to read the modes file. In your case, I think you want to read (and write) the poll_ms file. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
I see, in that case let's have a look at this portion of your code.
It looks like you are measuring data in a loop. You could add a wait(1000)
to the loop to wait a second.
I've also added a suggestion about initializing the sensor. See the comments I added below.
# Base_Press = PPS58Test()
data = DataLog('Pressure','ABS','time')
watch = StopWatch()
for x in range(99999):
# Motor(Port.A).run_time(1000, 18000, Stop.BRAKE, False)
# Motor(Port.B).run_time(1000, 18000, Stop.BRAKE, False)
Pressure = PPS58Test() # <------ It would be better to do this *before* the for loop
ABS = ABSIMUTest() # <------ It would be better to do this *before* the for loop
time = watch.time()/1000
Diff = DepthTest()
data.log(Pressure,ABS,time)
# <----- Here you could wait for a while. For example, do `wait(1000)`
if Diff < 5: continue
# Motor(Port.A).run_time(-1000, 18000, Stop.BRAKE, False)
# Motor(Port.B).run_time(-1000, 18000, Stop.BRAKE, False)
if Diff == 1:
sleep(10)
can i ask why are u comment comment wait(1000)??
and the motor command is correct?
first motor go down while measure data
while motor go down if depth >5 motor go up
and while motor go up depth ==1 stop 1sec
this is the loop and during the loop every measure data will datalog is it right? -----Original Message----- From: "laurensvalk"notifications@github.com To: "pybricks/support"support@noreply.github.com; Cc: "ksj537465"ksj537465@naver.com; "Author"author@noreply.github.com; Sent: 2021-01-06 (수) 18:27:54 (GMT+09:00) Subject: Re: [pybricks/support] Change mindsensors read speed (#198)
I see, in that case let's have a look at this portion of your code. It looks like you are measuring data in a loop. You could add a wait(1000) to the loop to wait a second. I've also added a suggestion about initializing the sensor. See the comments I added below.
wait(1000)
if Diff < 5: continue # Motor(Port.A).run_time(-1000, 18000, Stop.BRAKE, False) # Motor(Port.B).run_time(-1000, 18000, Stop.BRAKE, False) if Diff == 1: sleep(10)— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
can i ask why are u comment comment wait(1000)??
I only made a few suggestions as comments, so it was easier to see where to place it.
But in your code, it should not be a comment:
wait(1000)
can i get some example for use poll_ms ???? -----Original Message----- From: "laurensvalk"notifications@github.com To: "pybricks/support"support@noreply.github.com; Cc: "ksj537465"ksj537465@naver.com; "Author"author@noreply.github.com; Sent: 2021-01-06 (수) 19:01:37 (GMT+09:00) Subject: Re: [pybricks/support] Change mindsensors read speed (#198)
can i ask why are u comment comment wait(1000)??
I only made a few suggestions as comments, so it was easier to see where to place it. But in your code, it should not be a comment: wait(1000) — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
That's only needed, if you want to increase the polling frequency. I believe you said you wanted to decrease the logging frequency, so you're going to need the wait.
thank u -----Original Message----- From: "laurensvalk"notifications@github.com To: "pybricks/support"support@noreply.github.com; Cc: "ksj537465"ksj537465@naver.com; "Author"author@noreply.github.com; Sent: 2021-01-07 (목) 16:14:08 (GMT+09:00) Subject: Re: [pybricks/support] Change mindsensors read speed (#198)
That's only needed, if you want to increase the polling frequency. I believe you said you wanted to decrease the logging frequency, so you're going to need the wait. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
now i using AbsoluteIMU and PPS58 sensor
this sensors read speed is 5times per second(millisecond)
i want change read speed as 1time per second
how can i do that