Why is my counter setter counting infinite times #128582
Replies: 4 comments 7 replies
-
Hey Laura! I've read a while this code and I noticed something. We don't have a condition to check if the stage is 'down' or 'up'. So that's why the Here in this part:
Try adding Also in the 'else if' we don't verify if 'canCount' is true. Here the update: Hope this helps. Let me know if this worked out. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
Update: this was resolved. I used useRef instead of useState. Here was the answer from Chat GPT The issue you're encountering is due to the state not updating synchronously, which can cause multiple updates within the same bicep curl. Additionally, there is no mechanism to prevent the counter from incrementing while holding the "up" position. Let's address this by using useRef to manage the canCount state more effectively. Here's an improved version of your code: Use a useRef to manage the canCount state. Ensure the counter only increments once per complete curl. import React, { useRef, useState, useEffect } from 'react'; const App = () => {
}; const calculateAngle = (a, b, c) => { export default App; Check for canCount: Only increment the counter if canCount is true, and set it to false immediately after incrementing to prevent further increments until the next complete curl. Make sure to initialize the webcam and pose detection properly in the useEffect hook. This code assumes you have a pose detection setup that calls countReps with the detected pose. If you need help with setting up the webcam and pose detection, please provide more details about your current setup. |
Beta Was this translation helpful? Give feedback.
-
Select Topic Area
Bug
Body
I'm using Tensorflow to track the number of reps a user does a bicep curl. Every time I curl my bicep, instead of the counter incrementing once, it keeps counting until I stop doing a bicep curl. The count reps function (countReps) is crucial to show the user how many reps they have done so far. The function extracts the points from the shoulder, elbow, and wrist and it finds the angle to determine if a user is doing a bicep curl. I would do one bicep curl, but the longer I hold it, the more it keeps counting up. I'm not sure why this is happening. Can someone help? Most of the code is in the Test.jsx file. Thanks!
The code snippet is:
This is my repo: https://github.com/laura-nguyen/flexifit-ai/tree/main
Beta Was this translation helpful? Give feedback.
All reactions