using S3 & S4 as home switches

Questions about using encoders with the Roboclaw product line
Post Reply
SouthernAtHeart
Posts: 32
Joined: Fri Jan 29, 2016 4:00 pm
using S3 & S4 as home switches

Post by SouthernAtHeart »

Can you explain a little more about how this works? If I have them tied to my home microswitches, what command would I issue (packet serial) to tell it to go home. Does it have accel/decel? Thanks.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: using S3 & S4 as home switches

Post by Basicmicro Support »

Im assuming you have the signals set to Home(user). This means you have to manually move the motors till they trigger the home switched after power up. To do this you just use any movement commands you want to. if you use a Distance command just make sure you give a distance that is gaurunteed to get the motor back to the home switch. If you use a position command remember that the encoder will start at 0 so give a it a positon(some negative value) that is far enough back to gauruntee it will trigger the home switch. You can use commands with acceleration settings or not.

When the switch triggers the motor will be stopped automatically and the encoder for that motor will be reset to 0.
SouthernAtHeart
Posts: 32
Joined: Fri Jan 29, 2016 4:00 pm
Re: using S3 & S4 as home switches

Post by SouthernAtHeart »

That sounds great. It should be easy to use that feature then.
So this arduino code would send the motor to the home position:

Code: Select all

boolean returnM1Home() { //returns true if successful
  roboclaw.SpeedAccelDeccelPositionM1(address, accel, maxSpeed, deccel, -3000000, 0); //2500000 pulses is the max table length
  uint8_t depth1; //buffer 1 reading
  uint8_t depth2; //buffer 2 reading
  while (1) { //wait for buffers to be empty
    roboclaw.ReadBuffers(address, depth1, depth2);
    if (depth1 == 0X80 && depth2 == 0X80) return true;
    delay(300);
  } //end of waiting for drillhead position
}
Am I correct that once the home switch is triggered, the buffer will empty? Also, will the roboclaw hold the 0 encoder position? Like if it overshoots home, from the time the switch triggers to the time the motor stops will it try to take the motor back to the 0 encoder mark?
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: using S3 & S4 as home switches

Post by Basicmicro Support »

Once the home switch triggers the movement command will be finished. However only that command will be removed from the buffer IIRC. So if you sent a home command(eg move -30000000) and a command to move forward 10000 it should move backwards until the home sensor triggers and then execute the 10000 move forwards.
SouthernAtHeart
Posts: 32
Joined: Fri Jan 29, 2016 4:00 pm
Re: using S3 & S4 as home switches

Post by SouthernAtHeart »

Thanks. It's going to be great having the roboclaw monitor the home microswitch, and I'll also set up the Out Of Bounds microswitches to, so my atmega chip would have to bother watching them.
Cheers.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: using S3 & S4 as home switches

Post by Basicmicro Support »

One correction. The S4 and S5 pins are available for home signals. Not S3. I just re-read the tital of the post and realised that.
Joe
Posts: 34
Joined: Fri Dec 23, 2016 1:00 am
Re: using S3 & S4 as home switches

Post by Joe »

SouthernAtHeart wrote: roboclaw.SpeedAccelDeccelPositionM1(address, accel, maxSpeed, deccel, -3000000, 0); //2500000 pulses is the max table length
Is for position a negative value allowed?
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: using S3 & S4 as home switches

Post by Basicmicro Support »

Yes. If you set the Min Position setting to a negative value you can set negative positions. Min and Max Position settings set the available range limits for the Position commands.

Post Reply