zoukankan      html  css  js  c++  java
  • V-REP Remote API(C++)实现简单的关节转动

    基础内容参考:https://www.cnblogs.com/eternalmoonbeam/p/10753149.html

    V-REP客户端设置:

    在V-REP场景文件中需要添加三个实体,包括两个形状和一个关节。

    关于实体的知识在User Manual - Entities - Scenes objects。

    关节用的是旋转型Revolute_joint,注意三个实体间的继承关系,直接用鼠标在左侧实体列表拖动就可以添加为子对象了。

    在添加之后要设置一下旋转关节的一些属性,双击它的图标:

    点击下方的“Show dynamic properties dialog”:

    这里重点是设置“Maximum torque”,这个属性决定了旋转加速度;

    最后不要忘记添加脚本并设置端口号。

    C++代码:

    #include<iostream>
    #include"extApi.h"
    
    void main()
    {
    	
    	using namespace std;
    
    	int Port = 20172;
    	int clientID = simxStart("127.0.0.1", Port, 1, 1, 1000, 5);
    	cout << "client ID: " << clientID << endl;
    
    	if (clientID != -1)
    	{
    		cout << "V-rep connected." << endl;
    		simxInt Revolute_joint;//设置一个变量存储关节句柄
    		if (simxGetObjectHandle(clientID, "Revolute_joint", &Revolute_joint, simx_opmode_blocking) == simx_return_ok)//获得关节句柄,若成功
    		{
    			// here we have the joint handle in variable jointHandle!    
    			cout << "Successfully got joint handle." << endl;
    
    			simxFloat tar_velo = 0.5;//设置一个变量存储关节目标转速
    			if (simxSetJointTargetVelocity(clientID, Revolute_joint, tar_velo, simx_opmode_blocking) == simx_return_ok)//设置关节目标转速
    				cout << "target velocity: " << tar_velo << endl;
    			else
    				cout << "angle set failed." << endl;
    		}
    		else
    			cout << "Geting object handle failed." << endl;
    	}
    	else 
    	{
    		cout << "V-rep can't be connected." << endl;
    	}
    
    	simxFinish(clientID);
    	cin.get();
    	return;
    }
    

    代码说明:

    这种判断语句的风格来自手册中的Writing code in and around V-REP - V-REP API framework - Remote API - Remote API modus operandi。

    首先需要获得关节的句柄,然后是设定关节转速,注意默认是弧度制。

    在Remote API function list (by category)中可以查找各种功能函数,找到Joint object functionality:

    所有关节控制的功能函数都在这里。这次只是实现了简单的加速转动,操作方法仍然是,先运行场景仿真然后启动C++控制台程序。

    效果:

     长方体开始匀加速转动,一段时间后匀速转动。即使退出C++程序,其也将继续转动。事实上,C++程序所起到的作用就是修改了实体参数。

  • 相关阅读:
    git 常用命令
    centos 7 mini 安装
    python打印杨辉三角
    python 求100内的素数/质数
    字符串与bytes
    format
    Python字符串格式化
    数据结构
    ARM工作模式
    C语言实现字符串逆序输出
  • 原文地址:https://www.cnblogs.com/eternalmoonbeam/p/10761106.html
Copyright © 2011-2022 走看看