ftrobopy: distance vs counter values

Community-Firmware (cfw), Selbstbaucontroller (TX-Pi, ftduino, usw.), usw.
Forumsregeln
Bitte beachte die Forumsregeln!
Antworten
hvn
Beiträge: 256
Registriert: 20 Feb 2011, 11:15

ftrobopy: distance vs counter values

Beitrag von hvn » 08 Jun 2018, 16:25

Hi,

I have a problem using getCurrentDistance(). According to the github manual, it should return the distance, but for me it always returns 0 (no matter which counter it's connected to). When I use getCurrentCounterValue(), I mostly get the expected counter value. Here's also a strange finding: when I read its value from C3 and C4, using Python I always get a good return but in ROBOPro ( the test panel) C4 always returns 0 (actually, the field stays empty). I haven't updated the CFW in a while, but could it have anything to do with it?

Thanks,

hvn

Torsten
Beiträge: 308
Registriert: 29 Jun 2015, 23:08
Wohnort: Gernsheim (Rhein-Main-Region)

Re: ftrobopy: distance vs counter values

Beitrag von Torsten » 10 Jun 2018, 23:36

Hi hvn,
hvn hat geschrieben:I have a problem using getCurrentDistance(). According to the github manual, it should return the distance, but for me it always returns 0 (no matter which counter it's connected to). When I use getCurrentCounterValue(), I mostly get the expected counter value.
The getCurrentDistance() command is a method of the motor class (within the ftrobopy class).
Example:

Code: Alles auswählen

txt    = ftrobopy.ftrobopy('auto')
motor1 = txt.motor(1)
motor1.setDistance(1000)
motor1.setSpeed(400)
txt.updateWait()
while not motor1.finished():
  print(motor1.getDistance())
  txt.updateWait()
For this to work it is necessary that the motor output (M1-M4) and the fast counter input (C1-C4) of a connected motor correspond to each other (e.g. it is not possible to connect the motor to M1 and its counter to C2).

In contrast to this the getCurrentCounterValue() command is a method of the ftTXT class and can return any current counter input (C1-C4) independent of whether a motor object has been defined or not.
Example:

Code: Alles auswählen

txt = ftrobopy.ftrobopy('auto')
while txt.getCurrentCounterValue(0) < 1000:
  print(txt.getCurrentCounterValue(0))
  txt.updateWait()
(meaning of getCurrentCounterValue()'s parameter: 0=C1, 1=C2, 2=C3, 3=C4, empty=all counters as list)
hvn hat geschrieben: Here's also a strange finding: when I read its value from C3 and C4, using Python I always get a good return but in ROBOPro ( the test panel) C4 always returns 0 (actually, the field stays empty). I haven't updated the CFW in a while, but could it have anything to do with it?
I don't really understand this observation ... but I assume it has nothing to do with the cfw version ... are you sure that the connections are correct ... does it only happen with C3 and C4 or also with C1 and C2 ... did you define a motor output in ROBOPro ?

Best wishes,
Torsten

hvn
Beiträge: 256
Registriert: 20 Feb 2011, 11:15

Re: ftrobopy: distance vs counter values

Beitrag von hvn » 14 Jun 2018, 14:11

Hi Torsten,

Thank you for the feedback. After changing the wiring, getCurrentDistance() indeed returns a value. However, I now notice the strange effect, that from 3 distance readings on C1 and C2, the first gives e.g. C1 = 160 and C2 = 140, then 160 and 0, finishing with 0 and 0. Running the script for about 10 times, the values differ, but the 0 appearance does not. So C1 and C2 always end up being 0. Do you have an explanation for this?

Thanks

hvn

Torsten
Beiträge: 308
Registriert: 29 Jun 2015, 23:08
Wohnort: Gernsheim (Rhein-Main-Region)

Re: ftrobopy: distance vs counter values

Beitrag von Torsten » 14 Jun 2018, 21:35

Hi hvn,
hvn hat geschrieben: ... I now notice the strange effect, that from 3 distance readings on C1 and C2, the first gives e.g. C1 = 160 and C2 = 140, then 160 and 0, finishing with 0 and 0. Running the script for about 10 times, the values differ, but the 0 appearance does not. So C1 and C2 always end up being 0. Do you have an explanation for this?
This would be the typical behaviour when setting a finite distance for the motors:

Code: Alles auswählen

m1 = txt.motor(1)
m2 = txt.motor(2)
m1.setDistance(200)
m2.setDistance(200)
m1.setSpeed(400)
m2.setSpeed(400)
txt.updateWait()
while (not m1.finished()) and (not m2.finished()):
  print(m1.getDistance(), m2.getDistance())
  txt.updateWait()

print("final:",m1.getDistance(), m2.getDistance())
The last print command will always print 0 for both both motors. The reason is, that the TXT automatically sets the distance to 0 after the distance has been completed by the motors.

You will get a different behaviour if you set the distances to 0:

Code: Alles auswählen

m1 = txt.motor(1)
m2 = txt.motor(2)
m1.setDistance(0)
m2.setDistance(0)
m1.setSpeed(400)
m2.setSpeed(400)
txt.updateWait()
while (m1.getDistance() < 200) or (m2.getDistance() < 200):
  print(m1.getDistance(), m2.getDistance())
  txt.updateWait()

print("final:",m1.getDistance(), m2.getDistance())
In this case the last print command will print a value >=200 for both motors, because there is no distance that could be finished (0 distance really means infinite distance ).

Best wishes,
Torsten

hvn
Beiträge: 256
Registriert: 20 Feb 2011, 11:15

Re: ftrobopy: distance vs counter values

Beitrag von hvn » 19 Jun 2018, 18:18

Hi Torsten,

Thank you for the explanation.

hvn

hvn
Beiträge: 256
Registriert: 20 Feb 2011, 11:15

Re: ftrobopy: distance vs counter values

Beitrag von hvn » 01 Mär 2019, 08:01

Hi Torsten,

As I understand, the distance value decreases while the counter value increases. However, after quite a few tests, I find that both values decrease. Can you explain why this (seems to) happen? From my latest test, I've saved the datalog. BTW, the forum doesn't allow the upload of files with extensions .log and .txt. So I can't add the datalog until I know what is allowed.

hvn

Antworten