I am finding it difficult to control the speed of an SVR robot using a trackbar and having the speed displayed on a text box.
I have been able to write athe codes for the directiuonal control of robot, created the trackbar and the value of the track bar displays on the textbox but I don't know how to make this trackbar control the speed of the robot movement. Please some urgent help needed.
here is my code
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;
namespace Mobile_Robot
{
public partial class Mobile_Robot : Form
{
public Mobile_Robot()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Sp.Open(); //connect
}
private void button3_Click(object sender, EventArgs e)
{
Sp.Write("8"); //go forward
}
private void button2_Click(object sender, EventArgs e)
{
Sp.Write("5"); //stop
}
private void button4_Click(object sender, EventArgs e)
{
Sp.Write("2"); //reverse
}
private void button5_Click(object sender, EventArgs e)
{
Sp.Write("6"); //right
}
private void button6_Click(object sender, EventArgs e)
{
Sp.Write("4"); //left
}
private void button7_Click(object sender, EventArgs e)
{
Sp.Close(); //disconnect
}
private void button9_Click(object sender, EventArgs e)
{
Sp.Write("7"); //drift left
}
private void button8_Click(object sender, EventArgs e)
{
Sp.Write("9"); //drift right
}
private void button11_Click(object sender, EventArgs e)
{
Sp.Write("."); //rotate right by 20 degrees
}
private void button10_Click(object sender, EventArgs e)
{
Sp.Write("0"); //rotate left by 20 degrees
}
private void button12_Click(object sender, EventArgs e)
{
Sp.Write("1"); //back left
}
private void button13_Click(object sender, EventArgs e)
{
Sp.Write("3"); //back right
}
private void Slider_Scroll(object sender, EventArgs e)
{
Slider.Text = Convert.ToInt16(Slider.Value).ToString();
//converts the double (Slider.Value) into integer
//then to a string in other to display in the text box
Slider.Maximum = 10;
// The Maximum property sets the value of the track bar when
// the slider is all the way to the right.
Slider.Minimum = 0;
// The Minimum property sets the value of the track bar when
// the slider is all the way to the left.
Slider.TickFrequency = 2;
// The TickFrequency property establishes how many positions
// are between each tick-mark.
Slider.LargeChange = 1;
// The LargeChange property sets how many positions to move
// if the bar is clicked on either side of the slider.
Slider.SmallChange = 2;
// The SmallChange property sets how many positions to move
// if the keyboard arrows are used to move the slider.
Speed.Text = "" + Slider.Value;
// Display the trackbar value in the text box.
}
}
}
and here is the GUI
