41223245 - cad2024 作業網站

  • Home
    • SMap
    • reveal
    • blog
  • About
  • Attendance
  • HW1
    • HW1_Exam
      • w10
      • w11_ch
      • w11_hw
      • w12
      • w14
    • w7
      • 練習3
      • 練習4
      • 練習5
      • 練習6
      • 練習7
      • 練習8
    • Solvespace 操作
    • put .stl步驟
  • HW2
    • HW2_Exam
      • w16_exam1
  • HW3
    • HW3_Exam
      • w16_exam2
  • HW4
    • HW4_Exam
      • w16_exam3
  • Pinball
  • Final Report
w16_exam3 << Previous Next >> Final Report

Pinball

/downloads/pinball.ttt

# pip install pyzmq cbor keyboard
from coppeliasim_zmqremoteapi_client import RemoteAPIClient
import keyboard

# Connecting to the CoppeliaSim server
client = RemoteAPIClient('localhost', 23000)

print('Program started')
sim = client.getObject('sim')

# Get the handles for the sliders (prismatic joints)
cw = sim.getObject('/cw_joint')
ccw = sim.getObject('/ccw_joint')
slider = sim.getObject('/Prismatic_joint')

# Starting the simulation
sim.startSimulation()
print('Simulation started')

# Main control loop
def main():
    # Keep running until simulation is stopped
    while True:
        # Controls for cw and ccw joints
        if keyboard.is_pressed('l'):  # Move cw slider to -0.25 position
            print("l is pressed")
            sim.setJointTargetPosition(cw, -0.25)

        if keyboard.is_pressed('p'):  # Reset cw slider to the original position
            print("p is pressed")
            sim.setJointTargetPosition(cw, 0.0)

        if keyboard.is_pressed('w'):  # Move ccw slider to -0.28 position
            print("w is pressed")
            sim.setJointTargetPosition(ccw, -0.28)

        if keyboard.is_pressed('s'):  # Reset ccw slider to the original position
            print("s is pressed")
            sim.setJointTargetPosition(ccw, 0.0)

        # Controls for the Prismatic_joint
        if keyboard.is_pressed('E'):  # Move slider to -0.15 position
            print("E is pressed")
            sim.setJointTargetPosition(slider, 0.20)

        if keyboard.is_pressed('D'):  # Reset slider to the original position
            print("D is pressed")
            sim.setJointTargetPosition(slider, 0.0)

        # Stop the simulation
        if keyboard.is_pressed('t'):  # Stop the simulation
            print("t is pressed - stopping simulation")
            sim.stopSimulation()
            break

# Start the main control loop
main()

w16_exam3 << Previous Next >> Final Report

Copyright © All rights reserved | This template is made with by Colorlib