如何在pybullet中模拟平衡另一个对象的对象?

如何解决如何在pybullet中模拟平衡另一个对象的对象?

我正在尝试使用pybullet和openAI体育馆在板上模拟球的平衡,但是现在我正在处理任何形状的东西。我的体育馆已经停放了,但是我不确定如何用pybullet来解决这个问题。这是我为一个对象编写的代码示例,我想进行移动并平衡另一个对象。这是openAI env的代码,以及到目前为止我使用pybullet渲染它的工作:

import os import gym import numpy as np import pybullet as pb import pybullet_data import math import random


class BeamEnv(gym.Env):

    def __init__(self,obs_low_bounds  = np.array([ 0,"TBD",-45]),obs_high_bounds = np.array([12,12,45])):
        self.physicsClient = pb.connect(pb.GUI)     pb.setAdditionalSearchPath(pybullet_data.getDataPath())     self._seed()
        """Environment for a ball and beam system where agent has control of tilt.

        Args:
            obs_low_bounds (list,optional): [target location(in),ball location(in),ball velocity(in/s),beam angle(deg)]. Defaults to [ 0,-45].
            obs_high_bounds (list,optional): As above so below. Defaults to [12,45].
        """
        super(BeamEnv,self).__init__()

        # Hyperparameters
        self.ACC_GRAV    = 386.22  # [in/s]
        self.MOTOR_SPEED = 46.875  # 1.28[sec/60deg] converted to [deg/s]
        self.TIME_STEP   = 0.1     # [s]

        # Observation Space 
        #  _bounds = []
        self.obs_low_bounds  = obs_low_bounds
        self.obs_high_bounds = obs_high_bounds
        self._determine_max_velocity()
        self.observation_space = gym.spaces.Box(low = self.obs_low_bounds,high = self.obs_high_bounds,dtype = np.float32)

        # Action Space
        # increase,decrease or keep current angle
        self.action_space = gym.spaces.Descrete(3)

        # Reward Range
        self.reward_range = (-1,1)

    def _set_velocity_bounds(self):
        """Use Inclined Plane and Kinematics Formulas 
            to determine min/max velocities and set the obs_low/high_bounds
        """
        # Max Distance
        distance_max = self.obs_high_bounds[1]

        # Max Angle
        ang_max = self.obs_high_bounds[3]

        # Max acceletation (Inclined Plane Formula)
        a_max = self.ACC_GRAV * np.sin(np.deg2rad(ang_max))

        # Max Velocity (vf^2 = v0^2 + 2ad)
        vel_max = np.sqrt(2*a_max*distance_max)

        # Set Bounds
        self.obs_low_bounds[2]  = -vel_max
        self.obs_high_bounds[2] =  vel_max
        def _compute_observation(self):     cubePos,cube0rn = pb.getBasePositionAndOrientation(self.botId)     cubeEuler = pb.getEulerFromQuaternion(cubeOrn)  linear,angular = pb.getBaseVelocity(self.botId)    return[cubeEuler[0],angular[0],self.vt]
    
    def _compute_reward(self):  _,cubeOrn = pb.getBasePosition(self.botId)     cubeEuler = pb.getEulerFromQuaternion(cube0rn)  return(1 - abs(cubeEuler[0])) *
0.1 - abs(self.vt - self.vd)

    def _compute_done(self):    cubePos,_ = pb.getBasePositionAndOrientation(self.botId)   return cubePos[2] < 0.15 or self._envStepCounter >= 1500

    def reset(self,target_location = None,ball_location = None):
        pb.resetSimulation()    pb.setGravity(0,-9.8)     """default timeStep is 1/240s"""    pb.setTimeStep(0.01)    planeId = pb.loadURDF('plane.urdf')     #loading bot    cubeStarPos=[0,0.001]     cubeStartOrientation = pb.getQuaternionFromEuler([0,0])   path = os.path.abspath(os.path.dirname(__file__))   self.botId = pb.loadURDF(os.path.join(path,"beam.xml"),cubeStartPos,cubeStartOrientation)   self._observation = self._compute_observation()     return np.array(self._observation)

    
        """Reset the environment so the ball is not moving,there is no angle,Args:
            target_location (float,optional): Desired location of ball. Defaults to random.
            ball_location (float,optional): Current location of ball. Defaults to random.

        Returns:
            list: observation of (target location,ball location,ball velocity,beam angle)
        """
        
        # Set target location
        if target_location is not None:
            self.target_location = target_location
        else:
            possible_targets = list(range(self.obs_low_bounds[0],self.obs_high_bounds[0]))
            self.target_location = random.choice(possible_targets)

        # Set ball location
        if ball_location is not None:
            self.ball_location = ball_location
        else:
            possible_ball_locations = list(range(self.obs_low_bounds[1],self.obs_high_bounds[1]))
            self.ball_location = random.choice(possible_ball_locations)

        # Set Intial Velocity and Angle to Zero
        self.ball_velocity = 0 # [in/s]
        self.beam_angle    = 0 # [deg]

        return self._next_observation()

    def _next_observation(self):
        """Determines what will happen in the next time step

        Returns:
            list: observation of (target location,beam angle)
        """
        # Calculate Acceleration (Inclined Plane Equation)
        ball_acceleration = self.ACC_GRAV * np.sin(np.deg2rad(self.beam_angle))

        # Calculate Next Position (x = x0 + v0t + 0.5at^2)
        self.ball_location = self.ball_location + self.ball_velocity * self.TIME_STEP + 0.5 * ball_acceleration * self.TIME_STEP**2

        # Calculate New Velocity (v = v0 + at)
        self.ball_velocity = self.ball_velocity + ball_acceleration * self.TIME_STEP

        # Clip Ball Location
        self.ball_location = max(min(self.ball_location,self.obs_high_bounds[1]),self.obs_low_bounds[1])

        # Clip Ball Velocity
        self.ball_velocity = max(min(self.ball_velocity,self.obs_high_bounds[2]),self.obs_low_bounds[2])

        # Return Observation
        return [self.target_location,self.ball_location,self.ball_velocity,self.beam_angle]    

    def _take_action(self,action):
        """Determines change in angle due to action

        Args:
            action (int): increase,decrease or keep current angle
        """
        # Change action to signs by subtracting by 1 ie (0,1,2) --> (-1,1)
        action -= 1

        # Change the angle by unit step
        self.beam_angle = self.beam_angle + action * self.MOTOR_SPEED * self.TIME_STEP

        # Clip
        self.beam_angle = max(min(self.beam_angle,self.obs_high_bounds[3]),self.obs_low_bounds[3])

    def step(self,action):
        """Take action,collect reward and get new observation

        Args:
            action (int): increase,decrease or keep current angle

        Returns:
            tuple: (observation,reward,done,info)
        """
        # Take the action
        self._take_action(action)

        # Determine Success
        if (round(abs((self.target_location - self.ball_location)),3) == 0) & (round(self.ball_velocity,3) == 0) & (round(self.beam_angle,3) == 0):
            done = True
        else:
            done = False

        # Find Reward
        reward = 1 if done else -1

        # Find Next Observation
        obs = self._next_observation()

        # Return what happened
        return obs,{}

        def _seed(self,seed=None):     self.np_random,seed = seeding.np_random(seed)  return[seed]

这是pybullet中的一个物体,我要在其上平衡物体的板上。我不确定如何通过可变力使其移动或根据我的openAI健身脚本进行渲染。

import numpy 
import pybullet as pb
physicsClient = pb.connect(pb.GUI)

> #creates plane import pybullet_data pb.setAdditionalSearchPath(pybullet_data.getDataPath()) planeId =
> pb.loadURDF('plane.urdf')
> 
> 
> visualShapeId = pb.createVisualShape(
>     shapeType=pb.GEOM_MESH,>     fileName='procedural_objects/126/126.obj',>     rgbaColor=None,>     meshScale=[0.1,0.1,0.1])
> 
> collisionShapeId = pb.createCollisionShape(
>     shapeType=pb.GEOM_MESH,0.1])
> 
> #connects visual shape and collider multiBodyId = pb.createMultiBody(
>     baseMass=1.0,>     baseCollisionShapeIndex=collisionShapeId,>     baseVisualShapeIndex=visualShapeId,>     basePosition=[0,1],>     baseOrientation=pb.getQuaternionFromEuler([0,0]))
> 
> pb.setGravity(0,-9.8) pb.setRealTimeSimulation(1)
> #use setTimeStep fn to override default time step (1/240s)

任何建议如何使pybullet生成在另一个随机形状上保持平衡的随机形状(忽略球)?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-