This paper focuses on the collective cognition of robotic swarms. The robotic swarms perform tasks that are beyond the capability of a single robot by collective behavior that emerge from local interactions. However, due to the lack of the capability of a single robot, it is necessary for robotic swarms to collectively perceive the environment. In this paper, we develop controllers for a robotic swarm to accomplish a complex cognitive task, namely the collective foraging task with poison. In this task, robots have to both collectively distinguish two objects, namely foods and poisons, and cooperatively transport foods to the nest. We applied an evolutionary robotics approach with covariance matrix adaptation evolution strategy to develop controllers for robotic swarms. The results of computer simulations show that collective cognition behavior was successfully generated, which allows the robots to transport only foods. In addition, we also perform experiments to examine the scalability of the developed controllers.