FBurkelwsd / Eastlake-Shop

Place for all machine and shop information. We will have an issue for each machine in the shop
1 stars 0 forks source link

Vex v5 log #5

Open FBurkelwsd opened 3 months ago

FBurkelwsd commented 3 months ago

Please upload images and descriptions, as technical as possible of failures and successes. Feel free to look through this log to learn from other mistakes and successes.

FBurkelwsd commented 1 month ago

https://www.vexrobotics.com/v5/downloads/build-instructions https://kb.vex.com/hc/en-us/categories/360002333191-V5 Be sure to check out the mechanical, programming and build guides. Parts Libraries can be found on Onshape and have to be downloaded from internet to be integrated into Fusion 360

FBurkelwsd commented 1 month ago

Examples of How. Digital out

Thursday, May 9, 2024

3:14 PM

 Examples of How. Digital out

Thursday, May 9, 2024

3:14 PM

 

How to make a micro motor on a digital out be able to turn on and off. And maybe be able to control voltage output based on position of joystick. Or Pressing left and right buttoms and being abel to switch direction of motor spinning. What am I missing? Looks like I need to make a variable to replace the high low value, that is able to go negative in order to reverse direction of motor. Hoping for a variable motor forward

 

 

VEX V5 Brain | BLRS Wiki (purduesigbots.com)

VEX Help (vexcode.cloud)

VEX Help (vexcode.cloud)

How to make a micro motor on a digital out be able to turn on and off. And maybe be able to control voltage output based on position of joystick. Or Pressing left and right buttoms and being abel to switch direction of motor spinning. What am I missing? Looks like I need to make a variable to replace the high low value, that is able to go negative in order to reverse direction of motor. Hoping for a variable motor forward

 

  image

VEX V5 Brain | BLRS Wiki (purduesigbots.com)

VEX Help (vexcode.cloud)

VEX Help (vexcode.cloud) To add the functionality of switching between an "off" state and a range of variables (1 to 5) controlled by button presses, you'll need to modify your code to handle these states and transitions. Here is a revised version of your script that incorporates the off function and the range of variables:

python Copy code onoff = False myVariable = 0 updown = 0

def when_started1(): global onoff, myVariable, updown while True: # Assuming you want this to continuously check the button states if controller_1.buttonX.pressing(): # Toggle on/off state with button X onoff = not onoff if onoff: myVariable = 1 # Set to 1 when turning on else: myVariable = 0 # Set to 0 when turning off wait(0.3) # Debounce delay

    if onoff:
        if controller_1.buttonUp.pressing():  # Increment variable
            if myVariable < 5:
                myVariable += 1
            wait(0.3)  # Debounce delay
        elif controller_1.buttonDown.pressing():  # Decrement variable
            if myVariable > 1:
                myVariable -= 1
            wait(0.3)  # Debounce delay

    # Example output to digital_out
    if onoff:
        digital_out::value(myVariable)  # Output current value of myVariable
    else:
        digital_out::value(0)  # Output 0 when off

    wait(0.1)  # Small delay to avoid high CPU usage in the loop

Helper function to simulate waiting (replace with appropriate delay function in your environment)

def wait(seconds): import time time.sleep(seconds) Explanation: Toggle On/Off State: Button X is used to toggle the onoff state. When onoff is True, it sets myVariable to 1, and when onoff is False, it sets myVariable to 0.

Increment/Decrement Variable: When the system is "on" (onoff is True), the buttonUp and buttonDown are used to increment and decrement myVariable within the range of 1 to 5.

Output Value: The value of myVariable is sent to digital_out::value() only when onoff is True. When onoff is False, it sends 0.

Debounce Delay: wait(0.3) is used to debounce the button presses to prevent multiple rapid changes from a single press.

Continuous Check: A while True loop continuously checks the button states and updates myVariable accordingly.

Replace the wait function with the appropriate delay function for your environment if necessary. This code assumes a typical robotics control loop where button states are checked repeatedly. Adjust the buttonX, buttonUp, and buttonDown identifiers to match your specific controller's API.

FBurkelwsd commented 1 month ago

Restarted to find a way for this to be more direct. To allow the digital output to reflect a scale of 1 to 5 based on button presses, you need to modify the code so that button presses increment or decrement the myVariable and set the digital_out_a accordingly. Below is the updated code that achieves this:

python Copy code myVariable = 0

def when_started1(): global myVariable while True: # Continuously check the button states if controller_1.buttonUp.pressing(): if myVariable < 5: myVariable += 1 wait(0.3) # Debounce delay elif controller_1.buttonDown.pressing(): if myVariable > 1: myVariable -= 1 wait(0.3) # Debounce delay elif controller_1.buttonLeft.pressing(): myVariable = 0 # Reset to 0 (off) wait(0.3) # Debounce delay

    # Example output to digital_out based on myVariable
    if myVariable == 0:
        digital_out_a.set(False)
    else:
        digital_out_a.set(True)
        # Assuming there's a function to set the value on a scale of 1 to 5
        digital_out::value(myVariable)

    wait(0.1)  # Small delay to avoid high CPU usage in the loop

Helper function to simulate waiting (replace with appropriate delay function in your environment)

def wait(seconds): import time time.sleep(seconds)

when_started1() Explanation: Variable Increment/Decrement:

buttonUp increments myVariable up to a maximum of 5. buttonDown decrements myVariable down to a minimum of 1. buttonLeft resets myVariable to 0, turning off the digital output. Output Control:

If myVariable is 0, digital_out_a is set to False. If myVariable is between 1 and 5, digital_out_a is set to True, and the value is passed to digital_out::value(myVariable). Debounce Delay:

A debounce delay of 0.3 seconds is added to each button press to prevent multiple increments/decrements from a single press. Continuous Loop:

The while True loop ensures continuous checking of button states. wait(0.1) introduces a small delay to prevent the loop from consuming too much CPU power. Additional Notes: Replace digital_out::value(myVariable) with the correct method to set the value of the digital output if necessary. This is a placeholder assuming there's a function to set the output value based on myVariable. The wait function is a placeholder for whatever delay mechanism is appropriate in your programming environment. In an actual robotics control system, you might use a different function or method to handle timing. This code ensures that the digital output reflects the state of myVariable, allowing it to range from 0 (off) to 5 based on button inputs.

FBurkelwsd commented 1 month ago

image making progress

FBurkelwsd commented 1 month ago

Used chat gpt and switched to c++ to see if this would help.

// Make sure all required headers are included.

include

include

include

include

include

include "vex.h"

using namespace vex;

// Brain should be defined by default brain Brain;

// Robot configuration code. controller Controller1 = controller(primary); digital_out DigitalOutA = digital_out(Brain.ThreeWirePort.A);

// Define variable for remote controller enable/disable bool RemoteControlCodeEnabled = true;

bool motorDirection = true; // True for one direction, False for the other

int main() { while (true) { // Check if the Up button is pressed if (Controller1.ButtonUp.pressing()) { motorDirection = true; // Set motor direction to one way DigitalOutA.set(motorDirection); // Turn motor in the set direction } // Check if the Down button is pressed else if (Controller1.ButtonDown.pressing()) { motorDirection = false; // Set motor direction to the other way DigitalOutA.set(motorDirection); // Turn motor in the set direction } // Check if the Left button is pressed to stop the motor else if (Controller1.ButtonLeft.pressing()) { DigitalOutA.set(false); // Turn off motor }

// Small delay to avoid high CPU usage in the loop
wait(20, msec);

} }

After many trials above. Got yellow motor only to turn on could never control voltage/speed or change direction of motor. With Vex motor module and Vex Servo I was able to get servo to turn 1 direction with the press of a button. Makes me wonder if we need another controller or found this source talking about another microprocessor connected to digital out. https://learn.sparkfun.com/blog/1593

FBurkelwsd commented 1 month ago

Working on entire other motor configuration, with 393 motor and motor controller to see if we can controll direction. May be reaching the need to have a 3 wire expander. https://kb.vex.com/hc/en-us/articles/4402846880788-Using-3-Wire-Digital-In-Digital-Out-Devices