naoqi身体零件测试程序

零部件类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication2
{
    public class bj
    {
        public  bj(string n, float ma, float mi)
        {
            name = n;
            max = ma;
            min = mi;
        }
        public override string ToString()
        {
            return name;
        }
        public string name;
        public float max;
        public float min;

    }
}


窗口设计:

namespace WindowsFormsApplication2
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.textBoxIP = new System.Windows.Forms.TextBox();
            this.trackBarPitch = new System.Windows.Forms.TrackBar();
            this.lstbj = new System.Windows.Forms.ListBox();
            this.lbvalue = new System.Windows.Forms.Label();
            this.trackBar1 = new System.Windows.Forms.TrackBar();
            this.cb = new System.Windows.Forms.CheckBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.button4 = new System.Windows.Forms.Button();
            this.trackBar2 = new System.Windows.Forms.TrackBar();
            ((System.ComponentModel.ISupportInitialize)(this.trackBarPitch)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).BeginInit();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(221, 21);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "连接";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // textBoxIP
            // 
            this.textBoxIP.Location = new System.Drawing.Point(12, 23);
            this.textBoxIP.Name = "textBoxIP";
            this.textBoxIP.Size = new System.Drawing.Size(100, 21);
            this.textBoxIP.TabIndex = 1;
            this.textBoxIP.Text = "192.168.1.102";
            // 
            // trackBarPitch
            // 
            this.trackBarPitch.Location = new System.Drawing.Point(3, 174);
            this.trackBarPitch.Maximum = 100;
            this.trackBarPitch.Minimum = -100;
            this.trackBarPitch.Name = "trackBarPitch";
            this.trackBarPitch.Size = new System.Drawing.Size(330, 45);
            this.trackBarPitch.SmallChange = 2;
            this.trackBarPitch.TabIndex = 2;
            this.trackBarPitch.ValueChanged += new System.EventHandler(this.trackBar1_ValueChanged);
            // 
            // lstbj
            // 
            this.lstbj.FormattingEnabled = true;
            this.lstbj.ItemHeight = 12;
            this.lstbj.Location = new System.Drawing.Point(12, 63);
            this.lstbj.Name = "lstbj";
            this.lstbj.Size = new System.Drawing.Size(145, 88);
            this.lstbj.TabIndex = 3;
            // 
            // lbvalue
            // 
            this.lbvalue.AutoSize = true;
            this.lbvalue.Location = new System.Drawing.Point(278, 159);
            this.lbvalue.Name = "lbvalue";
            this.lbvalue.Size = new System.Drawing.Size(0, 12);
            this.lbvalue.TabIndex = 4;
            // 
            // trackBar1
            // 
            this.trackBar1.Location = new System.Drawing.Point(207, 63);
            this.trackBar1.Minimum = 1;
            this.trackBar1.Name = "trackBar1";
            this.trackBar1.Size = new System.Drawing.Size(104, 45);
            this.trackBar1.TabIndex = 5;
            this.trackBar1.Value = 1;
            // 
            // cb
            // 
            this.cb.AutoSize = true;
            this.cb.Location = new System.Drawing.Point(200, 114);
            this.cb.Name = "cb";
            this.cb.Size = new System.Drawing.Size(96, 16);
            this.cb.TabIndex = 6;
            this.cb.Text = "Bady准备就绪";
            this.cb.UseVisualStyleBackColor = true;
            this.cb.CheckedChanged += new System.EventHandler(this.cb_CheckedChanged);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(165, 159);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(107, 12);
            this.label1.TabIndex = 7;
            this.label1.Text = "当前角度(弧度):";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(165, 70);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(35, 12);
            this.label2.TabIndex = 8;
            this.label2.Text = "速度:";
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(12, 225);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 9;
            this.button2.Text = "sound";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(125, 21);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(75, 23);
            this.button3.TabIndex = 10;
            this.button3.Text = "hello";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // button4
            // 
            this.button4.Location = new System.Drawing.Point(106, 225);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(75, 23);
            this.button4.TabIndex = 11;
            this.button4.Text = "sound stop";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Click += new System.EventHandler(this.button4_Click);
            // 
            // trackBar2
            // 
            this.trackBar2.Location = new System.Drawing.Point(221, 214);
            this.trackBar2.Name = "trackBar2";
            this.trackBar2.Size = new System.Drawing.Size(86, 45);
            this.trackBar2.SmallChange = 2;
            this.trackBar2.TabIndex = 12;
            this.trackBar2.ValueChanged += new System.EventHandler(this.trackBar2_ValueChanged);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(333, 262);
            this.Controls.Add(this.trackBar2);
            this.Controls.Add(this.button4);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.cb);
            this.Controls.Add(this.trackBar1);
            this.Controls.Add(this.lbvalue);
            this.Controls.Add(this.lstbj);
            this.Controls.Add(this.trackBarPitch);
            this.Controls.Add(this.textBoxIP);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "NaoQi身体零件测试";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.trackBarPitch)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox textBoxIP;
        private System.Windows.Forms.TrackBar trackBarPitch;
        private System.Windows.Forms.ListBox lstbj;
        private System.Windows.Forms.Label lbvalue;
        private System.Windows.Forms.TrackBar trackBar1;
        private System.Windows.Forms.CheckBox cb;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.Button button4;
        private System.Windows.Forms.TrackBar trackBar2;
    }
}


主程序:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Aldebaran.Proxies;
using System.Collections;
using System.IO;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        MotionProxy _motion = null;
        List<bj> joint = new List<bj>();
        bool key = false;
        AudioPlayerProxy ad = null;
        int play = 0;
        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {



                Connect(textBoxIP.Text);
                if (_motion != null)
                {
                    ArrayList ar = (ArrayList)_motion.getLimits("Body");
                    List<string> ls = _motion.getJointNames("Body");
                    for (int i = 0; i < ls.Count; i++)
                    {
                        ArrayList arbj = (ArrayList)ar[i];

                        bj nbj = new bj(ls[i], (float)arbj[1], (float)arbj[0]);
                        lstbj.Items.Add(nbj.ToString());
                        joint.Add(nbj);
                    }
                    

                }


            
            
        }
        public void Connect(string ip)
        {

                _motion = new MotionProxy(ip, 9559);
                // --------------- prepare limits --------------------------
                // three floats as an ArrayList for each joint in the chain
                // min,max,maxNoLoadSpeedPerCycle


                // give the joints some stiffness这里非常重要 记住
                


        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {

        }

        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            if (lstbj.SelectedIndex >= 0)
            {
                
                UpdatePitch(trackBarPitch.Value);
            }

        }

        private void UpdatePitch(int p)
        {
            if (_motion != null)
            {

                    float re = ScaleToRange(p, joint[lstbj.SelectedIndex].min, joint[lstbj.SelectedIndex].max);
                    
                    _motion.setAngles(joint[lstbj.SelectedIndex].name, re, (float)trackBar1.Value/10.0f);
                    
                    lbvalue.Text = re.ToString();

            }
        }
        private static float ScaleToRange(int val, float min, float max)
        {
            float returnVal = (((val + 100.0f) / 200.0f) * (max - min)) + min;
            
            return returnVal;
            
        }

        private void cb_CheckedChanged(object sender, EventArgs e)
        {
            key = !key;
            if (key)
            {
                _motion.stiffnessInterpolation("Body", 1.0f, 2.0f);
            }
            else
            {
                _motion.stiffnessInterpolation("Body", 0.0f, 2.0f);
            }
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
             ad = new AudioPlayerProxy(textBoxIP.Text, 9559);
            
             play= ad.post.playWebStream("http://mp3.mwap8.com/destdir/Music/2009/20090601/ZuiXuanMinZuFeng20090601119.mp3", 1.0f, 1.0f);
             ad.setVolume(play, 0.1f);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            TextToSpeechProxy tts = new TextToSpeechProxy(textBoxIP.Text, 9559);
            tts.say("Hello World");

        }

        private void button4_Click(object sender, EventArgs e)
        {
            ad.stopAll();
        }

        private void trackBar2_ValueChanged(object sender, EventArgs e)
        {
            ad.setVolume(play, (float)(trackBar2.Value / 10.0));
        }


    }
}


程序窗口图:

程序运行图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值