Showing posts with label SPIK3R. Show all posts
Showing posts with label SPIK3R. Show all posts

Monday, 7 May 2018

Our Pet Spik3r

Below is a story of our pet Spik3r, which we have captured in the form of a small video clip. Our Spik3r was moving on as usual and we were about to give it some food (the bug). However, our Spik3r sensed some danger at that point of time and shot the bug. It started running backwards and stopped after some time. Enjoy the visual. (The Java program is also shared along with the visual).

Based on the mechanical assembly of the Spik3r, the large motor D is used to drive the robot forward. Another large motor A, is used to implement the sting. While the medium motor is used to implement the claw to catch the food (the bugs). The IR sensor is mounted on the front part of the robot in order to sense the existence of any danger. 

The program to drive the robot Spik3r consists of a single class, Spik3r2. It has a main method, which initializes all the three motors and the IR sensor in Distance mode. When the ESCAPE button is un-pressed and the IR Sensor does not find any object (danger) in front of it in a range of 20 cm, the robot keeps moving forward with the large motor D (which rotates with a speed of 400 degrees per seconds) and it also keeps moving its claw to catch the bug. The claw movement is done by rotating the medium motor through 220 to -220 degrees. The IR Sensor distance samples are fetched continuously while moving forward.  

If the robot locates a danger (our hand which is placing the bug in front of the robot) in less than 20 cm distance, it starts running backwards with a speed of 990 degrees per seconds. While running backwards, it stings the dangerous object (in the case of Spiker, it shoots a ball towards the dangerous object). The sting is caused by setting the large motor A at a speed of 640 degrees per second and rotating it through 600 degrees. The IR Sensor keeps fetching the Distance samples and as soon as the dangerous object goes out of sight, the robot starts moving forward again (unfortunately this forward movement at a later stage has not gotten captured in the video).





Wednesday, 12 March 2014

SPIK3R operates with IR Beacon

Here is a small LeJOS program to demonstrate the use of IR beacon to operate SPIK3R. I would suggest you to go through my previous article SPIK3R With IR Sensor before going through the current article. I am operating the same robot (SPIK3R) with the Beacon here.  I would also suggest you to go through the operation of the EV3 IR Beacon with the link EV3 IR Beacon Tutorial. This tutorial will make you familiar with the concepts of Beacon channels, Beacon buttons etc. 

Let me explain my code below. My code consists of two classes EV3IRBeacon and InfraredSignalCheckerThread. The EV3IRBeacon class initializes the IR Sensor at port S1. It also spawns a thread InfraredSignalCheckerThread and passes the IR Sensor Object to it. The thread then initializes the large motor at port B and also works with the IR Sensor object as follows. The thread keeps listening to the IR sensor commands until the ESCAPE button is pressed. The IR commands are sent over Beacon channel 0. The remote command is received in the form of an integer (1, 2, 3) which represent the top-left, bottom-left and top-right buttons respectively. Pressing button 1, rotates the large motor (connected to port B), forward. Pressing button 2, rotates the motor backwards and pressing button 3, stops the motor. 

Below is a small clip to show the performance of the program (under construction ..).  

Sunday, 9 March 2014

SPIK3R detects objects with IR sensor


Below is the LeJOS program for SPIK3R to detect objects with IR sensor provided with EV3 kit. This program makes SPIK3R crawl forward until it detects an object at a proximity of less than 35 cm. On detecting the object, SPIK3R crawls backwards until the object goes at a proximity of greater than 35 cm. Once the object goes out of its site, SPIK3R crawls forward again. There is a small video clip associated with this post to show the performance of the robot. 

NOTE: I have setup a Bluetooth connectivity from my PC to the robot to download the program wirelessly. However, it takes a long time (nearly 25 seconds) for the program to get downloaded onto EV3 brick. I did not understand the reason for this slowness yet. However, in essence, we will have to wait for 25 seconds to see how the program is doing!
 


I will explain my code to a certain extent below. My program consists of a single class EV3FirstProgram. This program starts with initializing the large regulated motor connected at port B. I have set the speed of the motor to be 90 degrees per second. It looks like the SPIK3R moves very slowly with this speed. However, you can always try increasing the speed to get a more thrilling experience! Let's move ahead with the program. I have initialized the port S1 where the infrared sensor is connected. Using LeJOS, the infrared sensor can be initialized in two modes Distance and Seek modes.  The Distance mode can be used to detect the presence of an object in the robot's proximity. The Seek mode is used along with the remote control (also called as beacon) to capture the infrared signals sent by the remote control. In this program I have used the Infrared Sensor's Distance mode.

The program runs in a continuous while loop which runs until the ESCAPE button is up. That means when we press the ESCAPE button, the robot will stop its execution. Next, I have provided a delay of 2 seconds. I have driven the motor forward in the continuous while loop. That means moving forward is the default behavior of the motor. What other things can be stated as default behavior of the robot? Let's see ... The robot collects 5 samples of distance from the infrared sensor and calculates the mean of them using the MeanFilter. This mean is stored in the variable dist. 

Now let's see how far this default behavior continues. It continues until an object is sighted in a proximity of 35 cm. When an object is sighted, the robot enters into the inner while loop and the robot's behavior changes. It starts going backwards. While going backwards, the robot keeps fetching the samples from the infrared sensor. It calculates the mean of 5 samples (similar to the case of moving forward). It checks whether the mean of 5 samples is greater than 35 cm. If the mean is greater than 35 cm (since the robot is moving backwards from the object), the robot will come out of the inner while loop and starts executing the outer while loop. Which essentially means the robot will starts moving forward again! We have considered the averaging of 5 samples in order to smoothen out any spikes from the Infrared sensor readings. 

That's how the robot will have an oscillating behavior of going forward and backward again! Please execute the code below and see the performance of the robot at your end! 
  
I hope you enjoyed this article!