Introduction: Increasing the production efficiency is an important goal in precision farming. The use of precision farming requires a lot of labor work. Also, due to the risk of agricultural operations, it is not recommended to do it directly by humans. Therefore, it is necessary for agricultural operations to be carried out automatically. For this reason, the application of robotics in agricultural environments, especially in the greenhouse, is increasing. The first step in automatic farming is autonomous navigation. For autonomous navigation, a robot must be the ability to understand its environment and recognize its position. In other words, a robot must be able to create a map of an unknown environment, locate itself on this map and finally plane for the path. This problem is solvable by Simultaneous LOCALIZATION and Mapping (SLAM). The SLAM problem is a recursive estimation process. In the other words, when a robot moves in an unknown environment, mapping and LOCALIZATION errors increase incrementally. To reduce these two errors, a recursive estimation process is used to solve the SLAM problem. Materials and Methods: In this research, two webcams, made by Microsoft Corporation with the resolution of 960×544, are connected to the computer via USB2 in order to produce a stereo parallel camera. For this study, we used a greenhouse that was located the Arak, Iran. Before taking stereo images, a camera path was designed in the greenhouse. This path may be either straight or curved. The designed path was implemented in the greenhouse. The entire path traversed by a stereo camera was 32. 7 m and 150 stereo images were taken. Graph-SLAM algorithm was used for Simultaneous LOCALIZATION and Mapping in the greenhouse. Using the ROS framework, the SLAM algorithm was designed with nodes and network for connecting the nodes. Results and Discussion: For evaluation, the stereo camera locations, every step was measured manually and compared with the stereo camera locations that were estimated in the graph-SLAM algorithm. The position error was calculated through the Euclidean distance (DE) between the estimated points and the actual points. The results of this study showed that, the proposed algorithm has an average of error 0. 0679412, standard deviation of 0. 0456431 and root mean square error (RMSE) of 0. 0075569 for camera LOCALIZATION. In this research, only a stereo camera was used to prepare a map of the environment, but other researches have used multiple sensor combinations. Another advantage of this research related to others was created a 3D map (point cloud) of the environment and loop closer detection. In the 3D map, in addition to determining the exact location of the plant, the height of the plant can also be estimated. Plant height estimate is important in some agricultural operations such as spot spray, harvesting and pruning. Conclusions: Due to the risk of agricultural activities, the use of robotics is essential. Autonomous navigation is one of the branches of the robotics. For autonomous navigation, a map of environment and LOCALIZATION in this map is need. The purpose of our research was to provide simultaneous LOCALIZATION and mapping (SLAM) in agricultural environments. ROS is a strong framework for solving the SLAM problem. So that, this problem can be solved by combining different nodes in ROS. The method depended only on the information from the stereo camera because stereo camera provided exact distance information. We believe that this study will contribute to the field of autonomous robot applications in agriculture. In future studies, it is possible to use an actual robot in the greenhouse with various sensors for SLAM and path planning.