Example #1
0
 def initialize(self):
     print("Initialize")
     self.client = b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient',
                                               'b0RemoteApiAddOn')
     self.wall_camera = self.client.simxGetObjectHandle(
         self.cameraName, self.client.simxServiceCall())
     self.start = time.time()
Example #2
0
	def initialize(self):
		print("Initialize")
		self.client = b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient','b0RemoteApiAddOn')
		self.wall_camera = self.client.simxGetObjectHandle(self.cameraName,self.client.simxServiceCall())
#		res, self.bill = self.client.simxLoadModelFromFile('/home/rcintas/Software/CoppeliaSim_Edu_V4_0_0_Ubuntu18_04/models/people/Walking_Bill.ttm', self.client.simxServiceCall())
#		print(res, self.bill)
		self.start = time.time()
 def __init__(self, paths=[]):
     super(CoppeliaSimAPI, self).__init__()
     self.coppelia_paths = paths + [
         './', os.environ['COPPELIASIM_ROOT'] + '/'
     ]
     self.client = b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient',
                                               'b0RemoteApiAddOn')
     signal.signal(signal.SIGINT, please_exit)
Example #4
0
 def initialize(self):
     print("Initialize")
     self.client = b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient',
                                               'b0RemoteApiAddOn')
     #self.wall_camera = self.client.simxGetObjectHandle('camera_' + str(self.cameraid) + '_rgb',self.client.simxServiceCall())
     self.wall_camera = self.client.simxGetObjectHandle(
         'Camera_Arm', self.client.simxServiceCall())
     #self.bill = self.client.simxGetObjectHandle('Bill_base#1', self.client.simxServiceCall())
     self.start = time.time()
Example #5
0
    def initialize(self):
        # openpifpaf configuration
        class Args:
            source = 0
            checkpoint = None
            basenet = None
            dilation = None
            dilation_end = None
            headnets = ['pif', 'paf']
            dropout = 0.0
            quad = 1
            pretrained = False
            keypoint_threshold = None
            seed_threshold = 0.2
            force_complete_pose = False
            debug_pif_indices = []
            debug_paf_indices = []
            connection_method = 'max'
            fixed_b = None
            pif_fixed_scale = None
            profile_decoder = None
            instance_threshold = 0.05
            device = torch.device(type="cuda")
            disable_cuda = False
            scale = 1
            key_point_threshold = 0.05
            head_dropout = 0.0
            head_quad = 0
            default_kernel_size = 1
            default_padding = 0
            default_dilation = 1
            head_kernel_size = 1
            head_padding = 0
            head_dilation = 0
            cross_talk = 0.0
            two_scale = False
            multi_scale = False
            multi_scale_hflip = False
            paf_th = 0.1
            pif_th = 0.1
            decoder_workers = None
            experimental_decoder = False
            extra_coupling = 0.0

        self.args = Args()
        model, _ = nets.factory_from_args(self.args)
        model = model.to(self.args.device)
        self.processor = decoder.factory_from_args(self.args, model)

        self.client = b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient',
                                                  'b0RemoteApiAddOn')
        self.bill = self.client.simxGetObjectHandle(
            'Bill_base#1', self.client.simxServiceCall())

        self.start = time.time()
Example #6
0
    def start(self):
        while True:
            with b0RemoteApi.RemoteApiClient(self.python_client,
                                             self.remote_api) as self.client:
                self.__add_method()
                self.__add_objects()
                self.__start_simulation()

                self.__loop()

                self.__finish_simulation()
                self.__remake_neural_network()
            time.sleep(1)
	def initialize(self):
		args = Args()
		model, _ = nets.factory_from_args(args)
		model = model.to(args.device)
		self.processor = decoder.factory_from_args(args, model)

		if self.simulation:
			self.client = b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient', 'b0RemoteApiAddOn')
			ret, children = self.client.simxGetObjectsInTree('sim.handle_scene', None, 1+2, self.client.simxServiceCall())
			for child in children:
				ret, name = self.client.simxGetObjectName(child, '', self.client.simxServiceCall())
				if "Bill_base" in str(name):
					self.bill.append(child)

		self.start = time.time()
Example #8
0
def coopelia_api_ini():
    # with b0RemoteApi.RemoteApiClient('b0RemoteApi_CoppeliaSim_Python', 'b0RemoteApi', 60) as client:
    global client
    global target
    global activeVisionSensor
    client = b0RemoteApi.RemoteApiClient('b0RemoteApi_CoppeliaSim_Python',
                                         'b0RemoteApi', 60)
    client.simxStartSimulation(client.simxServiceCall())
    client.simxAddStatusbarMessage('Hello from PyCharm Python',
                                   client.simxDefaultPublisher())
    res, activeVisionSensor = client.simxGetObjectHandle(
        'Vision_sensor', client.simxServiceCall())
    # res, resolution, image = client.simxGetVisionSensorImage(activeVisionSensor, False, client.simxServiceCall())
    res, target = client.simxGetObjectHandle('Quadricopter_target',
                                             client.simxServiceCall())
    def start(self):
        with b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient',
                                         'b0RemoteApi_manirs') as client:
            self.robot = ManRobot(client)

            client.simxSynchronous(True)
            client.simxGetSimulationStepStarted(
                client.simxDefaultSubscriber(self.simulation_step_started))
            client.simxGetSimulationStepDone(
                client.simxDefaultSubscriber(self.simulation_step_done))
            client.simxStartSimulation(client.simxDefaultPublisher())
            self.init()
            while not self.robot.disconnect and self.robot.simTime < 120:
                if self._do_next_step:
                    self._do_next_step = False
                    client.simxSynchronousTrigger()
                client.simxSpinOnce()
            self.cleanup()
            if not self.robot.disconnect:
                client.simxStopSimulation(client.simxDefaultPublisher())
            else:
                print('Simulation was stopped and client was disconnected!')
Example #10
0
from scipy import ndimage
import torch
from torch.autograd import Variable
import cv2
import os

import skimage.transform as trans
# from utils_warp import convert_image_np, normalize_transforms, rotatepoints, show_image
from utils import get_heightmap, get_input_tensors, get_prepared_img, \
    transform_position_cam_to_global, euler2rotm, isRotm, depth_img_from_bytes, \
    rgb_img_from_bytes

from model import reinforcement_net
import logger

with b0RemoteApi.RemoteApiClient('b0RemoteApi_V-REP', 'b0RemoteApi',
                                 timeout=5) as client:

    # Make sure simulation is not running
    client.simxStopSimulation(client.simxDefaultPublisher())

    # Global variables
    doNextStep = True
    rgb_vision_msg = None
    d_vision_msg = None

    ##########################
    # Callbacks

    # Callbacks
    def simulationStepStarted(msg):
        # simTime=msg[1][b'simulationTime'];
Example #11
0
# b0 (shared library), which depends on:
# boost_chrono (shared library)
# boost_system (shared library)
# boost_thread (shared library)
# libzmq (shared library)

# Built-in lib imports
import time, random

# Standard Library imports
import numpy as np

# Third-Party imports
import b0RemoteApi

with b0RemoteApi.RemoteApiClient('b0RemoteApi_V-REP', 'b0RemoteApi') as client:

    # Make sure simulation is not running
    client.simxStopSimulation(client.simxDefaultPublisher())

    # Global variables
    cube_position = 0
    doNextStep = True
    target_right_pose = []

    # Callbacks
    def simulationStepStarted(msg):
        simTime = msg[1][b'simulationTime']
        print('Simulation step started. Simulation time: ', simTime)

    def simulationStepDone(msg):
Example #12
0
 def jointAngleCallback(msg):
     b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient','b0RemoteApi').jointAngle=msg[1]
Example #13
0
 def create_client(a=None, b=None):
     # print(f'Creating self.client {threading.get_ident()}')
     c = b0RemoteApi.RemoteApiClient(a, b)
     # print('XX created')
     return c
Example #14
0
mat_x_ref = np.array([[orientation_roll], [orientation_pitch],
                      [orientation_yaw], [acceleration_roll],
                      [acceleration_pitch], [acceleration_yaw], [altitude],
                      [acceleration_altitude]])

mat_K = np.array([[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
                  [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]])

mat_A = np.array([[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
                  [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
                  [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
                  [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]])

# Initialize Simulator
client = b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient', 'b0RemoteApi')
doNextStep = True

# Motor Thrust
client.simxSetFloatSignal('F450_particleVelocity1', 0,
                          client.simxDefaultPublisher())
client.simxSetFloatSignal('F450_particleVelocity2', 0,
                          client.simxDefaultPublisher())
client.simxSetFloatSignal('F450_particleVelocity3', 0,
                          client.simxDefaultPublisher())
client.simxSetFloatSignal('F450_particleVelocity4', 0,
                          client.simxDefaultPublisher())

# Gyroscope
client.simxGetFloatSignal('F450_gyroX',
                          client.simxDefaultSubscriber(gyroXCallback))
import os
os.add_dll_directory(r'C:\Program Files\CoppeliaRobotics\CoppeliaSimEdu')

import b0RemoteApi
from RoboFunctions import ManRobot
import time

with b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient',
                                 'b0RemoteApi_manirs') as client:
    doNextStep = True
    robot = ManRobot(client)
    step = 0  #переменная для подсчета шагов симуляции

    def init():
        #пример использования функций управления роботом:
        #подробнее о всех функицях, их параметрах и возвращаемых значения см ReadMe

        #энкодеры:
        #robot.link1_enc
        #robot.link2_enc
        #robot.link3_enc
        #robot.link4_enc
        #robot.grip_enc
        #robot.cam_enc

        #simTime=robot.simTime

        #pos1=90 #градусов
        #pos2=90 #градусов
        #pos3=100 #мм
        #pos4=90 #градусов
Example #16
0
'''  Файл синхронизации с тьюториала CoppeliaSim'''
''' Если хочешь синхронизации скопируй этот файл в новый и изменяй'''
import b0RemoteApi
import math
import time
global kp, kv
kp = 0.5
kv = 100 * math.pi / 180

with b0RemoteApi.RemoteApiClient(
        'b0RemoteApi_pythonClient',
        'b0RemoteApi1') as client:  # Имя клиента: PYTHON_CODE
    # Channel name: b0RemoteApi
    doNextStep = True  # doNextStep переменная которая определяет выполнился ли шаг или нет

    def simulationStepDone(
            msg):  # подпрограмма вызываемая после выполнения шага
        simTime = msg[1][b'simulationTime']
        #print('Simulation step done. Simulation time: ', simTime);
        global doNextStep
        doNextStep = True

    client.simxSynchronous(True)

    #########################################Определеям Handle объектов###########################################################
    errHandle_LeftMotor, objHandle_LeftMotor = client.simxGetObjectHandle(
        'LeftMotor', client.simxServiceCall())
    errHandle_RighttMotor, objHandle_RightMotor = client.simxGetObjectHandle(
        'RightMotor', client.simxServiceCall())

    client.simxGetSimulationStepDone(
Example #17
0
def diffWheelTurnRight():
    print("differential wheel turn right") 
    global leftMtrSpd, rightMtrSpd    
    leftMtrSpd = forwardSlowV 
    rightMtrSpd = reverseSlowV
    sendWheelData()
    
def diffWheelTurnLeft():
    print("differential wheel turn left") 
    global leftMtrSpd, rightMtrSpd    
    leftMtrSpd =  reverseSlowV
    rightMtrSpd = forwardSlowV
    sendWheelData() 
    

with b0RemoteApi.RemoteApiClient('b0RemoteApi_CoppeliaSim-addOn','b0RemoteApiAddOn',60) as client:
    
    """ display on coppelia """
    client.simxAddStatusbarMessage('Sensor Program Started',client.simxDefaultPublisher())
    
    visionHndl = [-1, -1, -1]
    retCode, visionHndl[0] = client.simxGetObjectHandle('Vision_sensor_L',client.simxServiceCall())
    retCode, visionHndl[1] = client.simxGetObjectHandle('Vision_sensor_M',client.simxServiceCall())
    retCode, visionHndl[2] = client.simxGetObjectHandle('Vision_sensor_R',client.simxServiceCall())

    proximityHndl = [-1, -1, -1, -1, -1, -1, -1]
    retCode, proximityHndl[pFrontBtm] = client.simxGetObjectHandle('Proximity_sensor_front_bottom',client.simxServiceCall())
    retCode, proximityHndl[pFrontLft] = client.simxGetObjectHandle('Proximity_sensor_front_left',client.simxServiceCall())
    retCode, proximityHndl[pFrontRht] = client.simxGetObjectHandle('Proximity_sensor_front_right',client.simxServiceCall())
    retCode, proximityHndl[pFrontTop] = client.simxGetObjectHandle('Proximity_sensor_front_top',client.simxServiceCall())
    retCode, proximityHndl[pLeft] = client.simxGetObjectHandle('Proximity_sensor_left',client.simxServiceCall())
Example #18
0
 def create_client(ident: str = None, channel: str = None):
     # print(f'Creating self.client {threading.get_ident()}')
     c = b0RemoteApi.RemoteApiClient(ident, channel)
     # print('XX created')
     return c
Example #19
0
import b0RemoteApi
import time
from math import *

with b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient',
                                 'b0RemoteApi_first') as client:
    doNextStep = True
    flag = True
    adder = 0
    legPos = None

    def simulationStepDone(msg):
        simTime = msg[1][b'simulationTime']
        global doNextStep
        global flag
        global objHand
        global adder
        global targetLegHand
        global legPos

        adder += 1

        errPose, objPose = client.simxGetObjectPosition(
            objHand, -1, client.simxServiceCall())
        __e = client.simxSetObjectPosition(
            objHand, -1,
            (objPose[0] + adder * 0.001, objPose[1] + adder * 0.001,
             objPose[2] + adder * 0.001), client.simxServiceCall())
        # print("hexa_base: ", objPose[2])

        if legPos == None:
global Left_sensor_py
global Right_sensor_py
global objHand_LeftMotor
global objHand_RightMotor
global P
global kp
kp = 0.5
global kv
kv = (300 * math.pi) / 180
print('kv =', kv)
global err
global leftspeed
global rightspeed

with b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient',
                                 'b0RemoteApi_test5') as client:
    doNextStep = True
    # получаем HANDLE левого мотора
    errHand_LeftMotor, objHand_LeftMotor = client.simxGetObjectHandle(
        'LeftMotor', client.simxServiceCall())
    # получаем HANDLE правого мотора
    errHand_RightMotor, objHand_RightMotor = client.simxGetObjectHandle(
        'RightMotor', client.simxServiceCall())

    # попадаем при старте


    def simulationStepStarted(msg):
        simTime = msg[1][b'simulationTime']
        # получаем сигнал с левого датчика
        errLS_py, Left_sensor_py = client.simxGetFloatSignal(
Example #21
0
import b0RemoteApi
import time

with b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient', 'b0RemoteApi',
                                 60) as client:

    def callb(msg):
        print(msg)

    client.simxAddStatusbarMessage('Hello', client.simxDefaultPublisher())
    s1 = client.simxGetObjectHandle('shape1', client.simxServiceCall())
    s2 = client.simxGetObjectHandle('shape2', client.simxServiceCall())
    prox = client.simxGetObjectHandle('prox', client.simxServiceCall())
    vis = client.simxGetObjectHandle('vis', client.simxServiceCall())
    fs = client.simxGetObjectHandle('fs', client.simxServiceCall())
    coll = client.simxGetCollisionHandle('coll', client.simxServiceCall())
    dist = client.simxGetDistanceHandle('dist', client.simxServiceCall())
    '''
    res=client.simxAuxiliaryConsoleOpen('theTitle',50,4,[10,400],[1024,100],[1,1,0],[0,0,0],client.simxServiceCall())
    client.simxAuxiliaryConsolePrint(res[1],'Hello World!!!\n',client.simxServiceCall())
    time.sleep(1)
    client.simxAuxiliaryConsoleShow(res[1],False,client.simxServiceCall())
    time.sleep(1)
    client.simxAuxiliaryConsoleShow(res[1],True,client.simxServiceCall())
    time.sleep(1)
    client.simxAuxiliaryConsoleClose(res[1],client.simxServiceCall())
    client.simxStartSimulation(client.simxServiceCall())
    client.simxStopSimulation(client.simxServiceCall())
    '''
    '''
    res=client.simxAddDrawingObject_points(8,[255,0,255],[0,0,0,1,0,0,0,0,1],client.simxServiceCall())
Example #22
0
import sys
sys.path.append('./remoteAPI')
import b0RemoteApi as bSim

import rospy

import time

import matplotlib.pyplot as plt
from PIL import Image
import array


theClient = bSim.RemoteApiClient('b0Api_VREP','b0Api',60)
tValue = 0
theClient.im = Image.new("RGB", (256, 256), "#000000")

def imageCallback(msg):
	#print('Received image.', msg[1])
	#plt.imshow(im)
	#plt.show()
	global tValue
	theClient.im = Image.frombuffer("RGB", (msg[1][0],msg[1][1]), 
		msg[2], "raw", "RGB", 0, 1)
	tValue += 1
	#plt.imshow(im)
	#plt.show()

if __name__ == '__main__':
	'''
	with bSim.RemoteApiClient('b0Api_VREP','b0Api',60) as theClient: