Voice Activity Detection icon Voice Activity Detection Real-time microphone VAD using FFT to detect speech start/end and trigger scripts, with live level graph and sensitivity tuning Try it →
United Kingdom
Asked — Edited
Resolved Resolved by DJ Sures!

Getpwm Returning 0

I want to return the value from D1 and D0 whilst tracking an object, i'm using the GetPWM command but only ever get a "0" returned. Am i missing something?


ControlCommand("Camera", CameraColorTrackingEnable)

:TrackingLoop

$head0=GetPWM( D0 ) 
$head1=GetPWM( D1 ) 
print($head0)
print($head1)

sleep(1000)

Goto(TrackingLoop)

ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

Author Avatar
PRO
USA
#1  

you are using the wrong function, replace GetPWM with GetDigital.

Quote:

GetPWM (digitalPort) Gets the PWM (Pulse Width Modulation) of specified port PWM is between 0 and 100

Quote:

GetDigital( Port ) Returns the Digital value of the specified port as a 0 or 1

GetPWM returns the last value used with a PWM function.

ex:


PWM(D0, 75)
PWM(D1, 100)
Print(GetPWM(D0)) => 75
Print(GetPWM(D1)) => 100
Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#2  

I believe you are attempting to determine the position of a servo? If that is the case, use GetServo(). As stated by @ptp, the GetPWM is reserved for PWM specific functions, which is identified by its naming convention PWM vs SERVO.

Find out how a servo works from the learn section here: https://synthiam.com/Tutorials/Lesson/48?courseId=6

Additionally, there are dozens of variables for the camera control - which you can view by looking at the Variable Tab while editing. More information on editing EZ-Script can be found in the learn section here: https://synthiam.com/Tutorials/Course/6

Camera variables can help to determine the physical location of the object on the screen.

However, if you are looking to read a servo position, use GetServo(). The JD project which you are building from has some script examples that demonstrate, such as PointAndTrack

Author Avatar
United Kingdom
#3  

Thanks DJ.

getservo() works a treat