If visiting a castle is what you want to do, Himeji is an hour away by train. You can get there faster on a shinkansen, but assuming you won’t be using the shinkasnsen it’s an hour each way and 3,000yen return (or 2,400yen if you get the 1 day Kansai rail pass). Castle admission is an additional 1,000jpy.
Osaka and Himeji Castles are incomparable.