%% Climb stairs and shoot the target: A Student Robotics Project!
% For this week’s blog post, we invited an ABU Robocon team, BRACT’s Vishwakarma Institute of Technology, Pune to share their journey to winning 3rd place in the MathWorks Modelling Award at DD Robocon 2023. For the 2023 season, The theme and problem statement of the contest was "Casting Flowers over Angkor Wat," which involves the cooperation of a rabbit robot and an elephant robot. The objective of the game is to toss their team's colored rings into 11 poles located in the Angkor Wat Area. MathWorks is immensely proud of the team's achievements, and we hope you also find their insights useful!
%
%% Introduction
% This blog explores the realms of physical modelling and pole identification as required for the challenge. The mechanism verification for the required robots was accomplished using MATLAB and Simulink. Physical modelling allowed us to understand and anticipate the behavior of complex systems. Deployed YOLOv2, an algorithm that provides YOU ONLY LOOK ONCE functionality. On the other hand, computer vision technology was used to gain an acceptable amount of accuracy in object detection.
%
%% Methodology
%% Modelling of the ring
% The ring shape is modelled using a revolved solid block. Providing the block with ring dimensions makes it possible to accurately simulate the contact force between the ring shooting mechanism and the ring. The geometry section has two blocks:
% In the first one, the user is required to input the cross-section of the ring, envisioning it as a square, and providing the coordinates in an anticlockwise manner.
% In the second block, users are prompted to input the extent of the revolution, setting it to full. In the inertia section, users are required to set the calculated parameters derived from the original ring's physical model.
%
% Ring
%% Modelling of the Robots (Elephant Robot and Rabbit Robot)
% MATLAB provides a seamless way to import SolidWorks CAD models into Simulink by converting them to XML files and using the 'smimport' command. However, for complex robots, the import may not generate perfectly aligned parts. To address this, we created a simplified CAD model with only essential components for analysis. Additionally, to visualize Weldments accurately, converting them to STEP files or using simple sketches for import into MATLAB proves effective. This integration streamlines the design process and facilitates a more efficient examination of mechanisms.
%% Modelling of the ring shooting mechanism
% In the ring shooting mechanism, a hollow aluminium square section is mounted on a motor shaft at a specific distance from the ring. When we actuate the motor, the link shoots the ring, and it is thrown into the pole.
%
%
% Ring Shooting Mechanism
%% Challenge encountered
% One of the main challenges faced was determining the appropriate length and position of the link, as well as the position of the ring on the guideway (A plate, where the ring is placed for shooting). Ensuring consistent placement of the ring actively contributed to the effectiveness of guideway manufacturing. To find the optimal configuration, after conducting multiple simulations in MATLAB, varying the ring positions and link lengths, the best combination was manufactured. The figure illustrates the ideal link length, position, ring placement, and shooting height. This meticulous approach resulted in improved results and overall performance.
%% Calculate torque for the motor

     % Distance along x axis (s_x )= 4 m,
     % u=Velocity of ring
     % Distance along y axis (s_y )= 1.2 m,
     % ω=Angular velocity of link 
     % I=Moment of Inertia of link=0.0012 kg-m^2,
     % t=Time of flight
     % Angle of shooting ( θ) = 45°
     % s_x   = u cos⁡(45°)×t                   … (1)
     % s_y=u sin(45°)×t -1/2 gt^2       …(2) 
     % Using equation (1)  and (2), 
     % u=7.64 m/s⁡and t=0.74 s         
     % Using law of conservation of energy,

    %      (@  Rotational Energy)_((link))=〖Kinetic Energy〗_((ring))
    %      1/2×I×ω^2=1/2×M×u^2  
    %      ∴ω=74.13 rad/s  and RPM=698   
    %      Torque,τ=I×α                                                       α=ω/t    … (Assume,t=0.05)     
    %                   τ=0.0012×1462.8                             α=73.14/0.05  =1462.8     
    %                   τ=1.755     
    %      Final Torque =τ×FOS×10 (∴Factor of Safety=1.5) 
    %      Final Torque=27.5 kg-cm

%
%% Modelling of Bridge Climbing Mechanism
% The main challenge in modelling the slope climbing for the robot was its stability during slope climbing because the centre of mass of the robot was above the ground at a significant height and to address this concern, modeling of slope climbing proved effective to assess whether it climbs the slope or topples along the way.
%
% Robot climbing the bridge
%% Modelling of Step Climbing Mechanism
% Simulink models of step climbing are used to test the stability of the mechanism and to tackle the challenges encountered.
%
% Robot climbing the step
%
%% Pole Detection using Computer Vision and Deep Learning
% Computer Vision and Deep Learning techniques were used for the detection of the pole, which helped the Rabbit Robot align properly with the pole and increase the accuracy and efficiency of the operation of the Rabbit Robot. The YOLOv2 algorithm was used for the detection of poles and deployed on a Jetson Nano.
%%  Creating and training dataset
%  A custom and diverse dataset was made by clicking 800 images containing the actual pole from various angles, scales, backgrounds, and lighting conditions.
%
%
%
%% Annotation of Images and Splitting of Dataset
% the Image Labeler Application was used for the annotation or labelling of images, ground truth data of the dataset was created by labelling all the images manually. The goal was to detect only one object, the pole. Before labelling, the image size was bigger than the network input size so all the images were resized to [244 244 3], the minimum size to run the YOLOv2 Object Detection Network.
%% Creating YOLOv2 Object Detection Network
% This network consists of a feature extraction network and a detection network. ResNet-50 was used for feature extraction which is a pertained 50 layers convolutional neural network. The object detection network was made by specifying all the parameters, like input size, number of classes and anchor boxes.
%% Data Augmentation
% Randomly transforming the training dataset to create a new diverse variation of an already existing dataset. A few techniques used for data augmentation include brightness and contrast adjustment, and blurring.
%
%% Train YOLOv2 Object Detector and Evaluate
% Specify all the parameters like batch size, learning rate and epochs to train the object ‘detector’ model. The average precision metric of the Computer Vision Toolbox has been used to evaluate performance. The precision–recall curve was plotted to test how precise our detector model has been trained. The average precision was achieved at 0.91.
%% Results and Conclusion
% Team BRACT’S VIT Pune modelled robots and systems using MATLAB and Simulink. The team’s efforts were primarily driven by a desire to solve practical problems with effective engineering solutions. The lack of a direct ring form in SimScape prompted them to creatively use the extruded solid block to replicate the ring shooting mechanism. Furthermore, it addresses the stability issues that can arise when climbing a slope or meticulously refining the robot's design and shooting mechanism using thorough simulations. The team used its object detection model on the Nvidia Jetson Nano, further embracing cutting-edge technology like computer vision and deep learning to precisely detect and align with respect to the poles present in Robocon’23 Arena
%% Future Scope
% MATLAB's numerical computing and simulation features allow users to explore more intricate physical models, improving the performance and stability of their robot. Users can explore new configurations and improve old models using Simulink to construct and evaluate complex mechanisms and can navigate challenging areas and take on duties other than pole detection by incorporating cutting-edge sensors and perception algorithms into the robots. Participating in robotics contests can help team members develop their innovative, collaborative, and leadership skills. All things considered, it provides the ability to advance robotics and significantly advance automation and intelligence systems.