Archive for Robotics

Adding a Camera

Now that the necessary buttons, sliders, and spinner boxes have been added to the interface, it is time to find a way to attach a camera to the robot. The camera will allow a user to control the robot without having to be in the same room as the robot (albeit within 30 feet of the robot). However, there is no default video component in C#. As such, some exploration needs to be done to see if such a component exists. If a video component is available, a wireless camera must be found that will work with it.

Comments

Gripper Buttons

The next buttons to add to the interface were those to control the opening and closing of the grippers. To do so, I once again used the turn command provided by Fokke. However, in using this command, I got unexpected results. I had programmed the motor controlling the grippers to open and close 90 degrees. To my surprise, this caused the grippers to open too wide. To resolve this issue, I used trial and error. As it turns out, the degrees the motor controlling the gripper must turn works best at 60 degrees. With the addition of the open and close gripper buttons, the interface now provides the user with all the options they need to use the robot to grab a ball off a stand and then place the ball back on the stand. In addition, the interface can be used to perform other tasks with the robot as well.

Comments (1)

Controlling Speed with a Slider

Now that the interface includes a precise way to turn the robot, it was time to devise a way for the user to precisely control the speed of the robot. After some thought, I came to the conclusion that a slider would be ideal. Again, having no prior background in C#, I had to investigate how to first add a slider to my interface and then correctly code it. Similar to the spinner box, the slider also needed a minimum and maximum value. Learning my lesson from the spinner box, I checked the properties box of the slider before proceeding to the code. As it turns out, I was able to set the minimum and maximum value from the properties panel. The next issue with the slider was determining the jump interval. Initially, I had the slider jump by values of 10. However, when I tried to use the slider to control the speed, I felt I was very limited in my choices. As such, I changed the increment property of the slider to 1. This gives the user very fined tuned control over the speed of the motor. Even though there were a few bumps in the road, and some problems to overcome, I feel my progression in creating the interface is going very well.

 

Comments

Turning and the Spinner Box

In looking at the interface, I was a little uncomfortable having the user type the amount of degrees they wished the robot to turn into a textbox. I decided that a spinner box, with a minimum value of 0 and a maximum value of 360, would be better. This meant it was time to learn how to use a spinner box. In my first attempt, I wrote the minimum and maximum values using code. However, I soon realized that you could apply a minimum and maximum value from the properties panel of the spinner box. When I figured this out, I erased the code I had written and used the properties panel to apply a minimum and maximum value. I also changed the interval amount to 1, so that when the user clicked on the up or down arrow in the spinner box, the displayed value would increase and decrease by 1 respectively. Next, I created a global variable to store the text string shown in the spinner box. I then wrote the code to convert the text string stored in the variable into a numeric number. The global variable was then placed in the command used to turn the robot. This procedure was added to both the left and right turn buttons.

Comments

The Turning Constant

In meeting with Chandima, he saw that a discrete pattern existed in the amount of degrees the robot must turn to coincide with the amount of degrees the user typed into the textbox. As such, he provided me with a method to determine the decimal number the degrees the user types in should be multiplied by. In figuring out this constant, I was able to completely eliminate the if/then statement I had written. Overall, this little suggestion made the code much cleaner, easier to follow, and more efficient.

Comments

Turning and Textboxes

Having the user select the amount of degrees to turn proved to be quite a challenging process. To control the degrees the robot turns, I thought it would be best to use a textbox in which the user typed in the degrees. In Fokke’s tutorial, he provided a command to turn the robot. However, when you type in the amount of degrees, for example 90 degrees, the robot does not turn that amount. Instead, the motor turns 90 degrees but the robot does not due to slipping. To overcome this issue, I had to determine the amount of degrees a motor must spin in order to turn the robot the correct amount of degrees. After much trial and error, I found that the amount of degrees the user types into the textbox has to be multiplied by about four. In addition, for each 90 degree interval, the amount of degrees the user types in the textbox has to not only be multiplied by four, but an additional amount of degrees has to be added to the number. Because of this, I had to create an if/then statement for each 90 degree interval, up to 360 degrees. During the process of figuring out how to get the robot to turn, I learned how to write an if/then statement, declare a global variable, and convert a string in to a number in C#.

Comments

Starting to Design the Interface

Having learned how to use the motor commands provided in Fokke’s tutorial, it is time to start learning different aspects of C# and create an interface for running the robot.  To begin, I have placed four buttons on the interface that I plan to use to move the robot forward, backwards, left, and right.  In addition, I have included a brake button to stop the robot.  Working with the forwards and back commands, I have realized that the robot tends to move in a curved direction even though both motors are running at the same speed.  To overcome this issue, I have slowed the motor speed to about 50%.  Although not totally perfect, this seems to have greatly mitigated the problem.  My first attempt at turning the robot called for using the turn command and setting the motor speed to 50%.  In doing so, the user would have to hit a brake button to stop the robot after it turned the desired amount.  However, when trying this method out, I found it extremely difficult to precisely control the amount the robot turned.  Currently, I am trying to develop a way for the user to control the amount of degrees the robot must turn.  In order to accomplish this I will need to learn more about how to write a C# program.

Comments

Running Motors Simultaneously

Now that I am able to establish a Bluetooth connection with the NXT brick and I am able to get the robot to turn when I hit a button on the form, it is time to explore how to get the robot to move forward (i.e. have two motors run simultaneous while clicking only one button).  At first, I tried to use the “coast command” that Fokke included in his tutorial.  However, I was unable to get the robot to respond to this command.  Instead, I used the turn command and set the amount of degrees for the motor to turn to zero.  In the click event procedure for the forward button in my form, I included the turn command (degrees set to zero) for the two motors connected to ports B and C on the NXT.  When I ran the application and clicked the button, the robot moved forward.  I realized, however, that I had no way of stopping the robot.  I actually had to turn off the NXT brick to get it to stop.  I decided to use the “brake command” to stop the robot.  To do this, I added a new button to the form named “stop” and included the brake command for both motors in the button’s click event procedure.  Finally, following the same process I used to get the robot to move forward, I made a new button named “back” that moved the robot backwards. 

Comments

Triumphs and Tribulations

Here are some of the issues I ran into when following Bran Fokke’s tutorial and how I overcame them.

Problem 1: The “click event procedure”

As it turns out, I had not correctly written the click event procedure for the button I added to my form. Initially, I had nested two click event procedures within each other. Additionally, I had named my button something different than what Fokke had named his in his tutorial. As such, I started debugging my program. After some time, I was able to figure out how to add a click event procedure to a button in a form using C#. Again I ran the program. This time there was no errors when I executed it. Everything seemed to be perfect. Then I tried to click the button, expecting the robot to turn, on my form and nothing happened. This was a little frustrating for me because I did not know where to go to next.

Problem 2: The “AutoPoll property”

I started trying to find the error in my program by rereading Fokke’s tutorial. However, it appeared I had followed it correctly. In attempt to fix my problem, I decided to make sure each motor was assigned to the right port on the NXT brick and that I had chosen the correct COM port. Everything was set up right. I then looked at the program Fokke provided in the QuickStart.zip, which can be found in the download section on Fokke’s website, for inspiration. What I found out is that in his NXTBrick component he had set the AutoPoll property to true. So I went back to my program and set it to true also. To my excitement, I was able to click on the button in my form and the robot turned clockwise. Wow! Awesome! Great! Spectacular!

Comments

Working with C#

Knowing I was able to connect to the NXT brick using Bluetooth, I moved to the next tutorial provided on Bram Fokke’s website.

Working with the C# commands was quite an interesting experience for me, since this was the first time I have used C#. Although I never have used C#, I do have some experience with Visual Basic. Using this knowledge, I was able to get the basic idea of what Fokke was saying in his tutorial. Adhering closely to Fokke’s instructions, I began adding the motor commands to my program. Seemingly when everything seemed perfect, I ran my program. To my dismay, I got numerous errors when I tried to execute the program. I had hoped one of the motors on my robotic car would have moved forward (thus turning the robot), but it did not.

Comments